TeeChart 的使用从入门到精通
1.首先nutGet 进行使用
2.如果需要使用管方的Key 进行激活
3.直接上写的Demo代码
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using Steema.TeeChart;
11 using Steema.TeeChart.Styles;
12
13 namespace TeechartForm
14 {
15 public partial class FormTeeChart : Form
16 {
17 private TChart tChart;
18 private Label labelValue = new Label();
19 public FormTeeChart()
20 {
21 InitializeComponent();
22 // 在构造函数中初始化TChart
23 tChart = new TChart();
24 //tChart.Parent = this.panelCharts;
25 tChart.Dock = DockStyle.Fill;
26 this.panelCharts.Controls.Add(tChart);
27
28 // 初始化 labelValue
29 //labelValue.AutoSize = true;
30 //labelValue.BackColor = Color.Transparent;
31 //labelValue.Visible = false; // 默认情况下不可见
32 //this.Controls.Add(labelValue);
33
34 //tChart.MouseMove += TChart_MouseMove;
35 }
36
37 private void FormTeeChart_Load(object sender, EventArgs e)
38 {
39
40 }
41
42 // 添加一个标志来跟踪鼠标是否被按下
43 private bool isMouseDown = false;
44
45
46
47 private bool mOnBoxing = false;
48 Point mPoint1 = new Point();
49 Point mPoint2 = new Point();
50 private void TChart_MouseHover(object sender, MouseEventArgs e)
51 {
52 MessageBox.Show("1");
53 //labelValue.Text = "111";
54 //labelValue.Visible = true;
55
56 TChart chart = (TChart)sender;
57 if (Control.ModifierKeys == Keys.None)
58 {
59 mPoint2 = e.Location;
60
61 chart.Invalidate();
62 }
63 }
64
65
66 private void buttonLine_Click(object sender, EventArgs e)
67 {
68 //条形图
69 BarChart();
70
71 }
72
73 private void buttonBoxPlot_Click(object sender, EventArgs e)
74 {
75 BoxPlot();
76 //tChart.MouseMove += TChart_MouseMove;
77 }
78
79
80 /// <summary>
81 /// 进行获取Tcharts 鼠标移动的位置
82 /// </summary>
83 /// <param name="sender"></param>
84 /// <param name="e"></param>
85 private void TChart_MouseMove(object sender, MouseEventArgs e)
86 {
87 // 获取鼠标在图表上的位置
88 int x = e.X;
89 int y = e.Y;
90
91 Series s = tChart.Series[0];
92 int pointIndex = s.Clicked(e.X, e.Y);
93 if (pointIndex != -1)
94 {
95 // 获取数据点的值
96 double value = s.YValues[pointIndex];
97
98 // 设置标签文本
99 labelValue.Text = "Value: " + value.ToString();
100
101 // 移动标签位置并显示
102 labelValue.Left = x + 10; // 鼠标位置的偏移量
103 labelValue.Top = y;
104 labelValue.Visible = true;
105 }
106 else
107 {
108 // 如果不在任何数据点上,则不显示标签
109 //labelValue.Visible = false;
110 }
111 }
112
113 private void GantMap_Click(object sender, EventArgs e)
114 {
115 Gant();
116 }
117
118 private void LineMap_Click(object sender, EventArgs e)
119 {
120 LineChart();
121 }
122
123
124 /// <summary>
125 /// 折线图
126 /// </summary>
127 public void LineChart()
128 {
129 // 清除现有的系列
130 tChart.Series.Clear();
131
132 // 创建一个折线图系列
133 Line lineSeries = new Line(tChart.Chart);
134
135 // 添加数据到图表
136 lineSeries.Add(0, "Apples");
137 lineSeries.Add(5, "Pears");
138 lineSeries.Add(2, "Oranges");
139 lineSeries.Add(7, "Bananas");
140 lineSeries.Add(4, "Pineapples");
141
142 // 将系列添加到TChart
143 tChart.Series.Add(lineSeries);
144
145 // 鼠标移动事件
146 tChart.MouseMove += (s, e) =>
147 {
148 int pointIndex = -1;
149 // 遍历所有系列
150 foreach (Series series in tChart.Series)
151 {
152 // 尝试找到鼠标下的数据点
153 pointIndex = series.Clicked(e.X, e.Y);
154 if (pointIndex != -1)
155 {
156 // 如果找到数据点,执行所需的操作
157 string pointLabel = series.Labels[pointIndex];
158 double pointValue = series.YValues[pointIndex];
159 tChart.ClickTitle += TChart_ClickTitle;
160 //tChart.ClickTitle + = "Value: " + pointValue.ToString() + " for " + pointLabel;
161
162 break; // 跳出循环,因为我们已经找到了数据点
163 }
164 else
165 {
166 tChart.Header.Text = "";
167 }
168 }
169 };
170
171 // 其他代码保持不变...
172
173 // 设置图表标题
174 tChart.Header.Text = "Fruit Consumption";
175 tChart.Header.Visible = true;
176 tChart.Refresh();
177 tChart.Invalidate(); // 可能不需要手动调用
178 }
179
180 private void TChart_ClickTitle(object sender, MouseEventArgs e)
181 {
182 MessageBox.Show("1111");
183 }
184
185
186 /// <summary>
187 /// 条形图
188 /// </summary>
189 public void BarChart()
190 {
191 // 清除现有的系列
192 tChart.Series.Clear();
193 // 创建一个条形图系列
194 Bar barSeries = new Bar();
195 // 添加数据到图表
196 barSeries.Add(0, "Apples");
197 barSeries.Add(5, "Pears");
198 barSeries.Add(2, "Oranges");
199 barSeries.Add(7, "Bananas");
200 barSeries.Add(4, "Pineapples");
201
202 // 将系列添加到TChart
203 tChart.Series.Add(barSeries);
204
205
206 // 鼠标按下事件
207 //tChart.MouseMove += (s, e) =>
208 //{
209 // if (e.Button == MouseButtons.Left)
210 // {
211 // isMouseDown = true; // 设置标志为true
212 // MessageBox.Show("11");
213 // }
214 //};
215
216 // 在类的成员区域初始化一个工具提示
217 System.Windows.Forms.ToolTip tooltip = new System.Windows.Forms.ToolTip();
218
219 // 鼠标释放事件
220 tChart.MouseMove += (s, e) =>
221 {
222 if (e.Button == MouseButtons.Left)
223 {
224 int pointIndex = -1;
225 // 遍历所有系列
226 foreach (Series series in tChart.Series)
227 {
228 // 尝试找到点击的数据点
229 pointIndex = series.Clicked(e.X, e.Y);
230
231 if (pointIndex != -1)
232 {
233 // 如果找到数据点,执行所需的操作
234 string pointLabel = series.Labels[pointIndex];
235 double pointValue = series.YValues[pointIndex];
236 //MessageBox.Show("Clicked on: " + pointLabel + " Value: " + pointValue.ToString());
237
238 // 显示工具提示
239 tooltip.Show("Value: " + pointValue.ToString() + " for " + pointLabel, tChart, e.Location.X + 15, e.Location.Y - 15, 2000); // 显示2秒
240
241 break; // 跳出循环,因为我们已经找到了数据点
242 }
243 }
244 }
245 };
246
247
248 // 绑定鼠标点击事件处理程序到 tChart 控件
249 //tChart.MouseClick += (s, e) =>
250 //{
251 // if (e.Button == MouseButtons.Left)
252 // {
253 // int pointIndex = -1;
254 // // 遍历所有系列
255 // foreach (Series series in tChart.Series)
256 // {
257 // // 尝试找到点击的数据点
258 // pointIndex = series.Clicked(e.X, e.Y);
259
260 // if (pointIndex != -1)
261 // {
262 // // 如果找到数据点,执行所需的操作
263 // string pointLabel = series.Labels[pointIndex];
264 // double pointValue = series.YValues[pointIndex];
265 // MessageBox.Show("Clicked on: " + pointLabel + " Value: " + pointValue.ToString());
266 // break; // 跳出循环,因为我们已经找到了数据点
267 // }
268 // }
269 // }
270 //};
271
272 // 其他代码保持不变...
273 // 其他代码保持不变...
274 // 在类的成员区域初始化一个工具提示
275 /*System.Windows.Forms.ToolTip tooltip = new System.Windows.Forms.ToolTip();
276 // 鼠标移动事件
277 chart.MouseMove += (s, e) =>
278 {
279 int pointIndex = -1;
280 // 遍历所有系列
281 foreach (Series series in chart.Series)
282 {
283 Point mPointss = new Point();
284 // 尝试找到鼠标下的数据点
285 pointIndex = series.Clicked(e.X, e.Y);
286
287 if (pointIndex != -1)
288 {
289 // 如果找到数据点,执行所需的操作
290 string pointLabel = series.Labels[pointIndex];
291 double pointValue = series.YValues[pointIndex];
292 // 显示工具提示
293 tooltip.Show("Value: " + pointValue.ToString() + " for " + pointLabel, chart, e.Location.X + 15, e.Location.Y - 15, 2000); // 显示2秒
294 // chart.Invalidate();
295 break; // 跳出循环,因为我们已经找到了数据点
296 }
297
298 }
299 };
300 */
301
302 // 设置图表标题
303 tChart.Header.Text = "Fruit Consumption";
304 tChart.Header.Visible = true;
305 tChart.Refresh();
306 tChart.Invalidate();
307
308
309 }
310
311 /// <summary>
312 /// BoxPlot
313 /// </summary>
314 public void BoxPlot()
315 {
316
317 // 清除现有的系列
318 tChart.Series.Clear();
319
320 // 创建一个 BoxPlot 系列
321 Box boxSeries = new Box(tChart.Chart);
322
323 // 填充 BoxPlot 数据
324 boxSeries.Add(new double[] { 3, 5, 7, 2, 6 });
325 boxSeries.Add(new double[] { 4, 6, 8, 3, 7 });
326 boxSeries.Add(new double[] { 5, 7, 9, 4, 8 });
327 boxSeries.Add(new double[] { 5, 7, 9, 4, 8 });
328 //boxSeries.Add(new double[] { 15, 17, 19, 14, 18 });
329 // ... 添加更多的数据点 ...
330
331 // 设置标题
332 tChart.Header.Text = "Sample BoxPlot";
333 tChart.Header.Visible = true;
334
335 // 将 BoxPlot 系列添加到 TChart
336 tChart.Series.Add(boxSeries);
337 tChart.Refresh();
338 tChart.Invalidate();
339 }
340
341
342 /// <summary>
343 /// Gant
344 /// </summary>
345 public void Gant()
346 {
347 // 清除现有的系列
348 tChart.Series.Clear();
349
350 // 创建一个甘特图系列
351 Gantt ganttSeries = new Gantt();
352
353 // 添加数据到图表,每个点的格式为 Add(DateTime start, DateTime end, string text, Color color)
354 ganttSeries.Add(DateTime.Today.AddDays(1), DateTime.Today.AddDays(12), 100, "Project B", Color.Green);
355 ganttSeries.Add(DateTime.Today.AddDays(3), DateTime.Today.AddDays(15), 200, "Project C", Color.Red);
356 // ... 添加更多的数据 ...
357
358 // 将系列添加到TChart
359 tChart.Series.Add(ganttSeries);
360
361 // 设置X轴为日期时间类型
362 tChart.Axes.Bottom.Labels.Angle = 90;
363 tChart.Axes.Bottom.Labels.DateTimeFormat = "dd-MMM";
364 tChart.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
365
366 // 设置Y轴为分类类型,便于显示任务名称
367 tChart.Axes.Left.Labels.Angle = 0;
368 tChart.Axes.Left.Labels.Style = AxisLabelStyle.Text;
369
370 // 设置图表标题
371 tChart.Header.Text = "Project Timeline";
372 tChart.Header.Visible = true;
373
374 // 刷新图表显示
375 tChart.Refresh();
376 tChart.Invalidate();
377
378 }
379
380 }
381 }
TeeChart 的使用从入门到精通的更多相关文章
- <程序员从入门到精通> -- How
定位 自己才是职业生涯的管理者,想清楚自己的发展路径: 远期的理想是什么?近期的规划是什么?今日的任务和功课又是什么? 今日之任务或功课哪些有助于近期之规划的实现,而近期之规划是否有利于远期之理想? ...
- 【无私分享:从入门到精通ASP.NET MVC】从0开始,一起搭框架、做项目 目录索引
索引 [无私分享:从入门到精通ASP.NET MVC]从0开始,一起搭框架.做项目(1)搭建MVC环境 注册区域 [无私分享:从入门到精通ASP.NET MVC]从0开始,一起搭框架.做项目(2)创建 ...
- ASP.NET MVC4入门到精通系列目录汇总
序言 最近公司在招.NET程序员,我发现好多来公司面试的.NET程序员居然都没有 ASP.NET MVC项目经验,其中包括一些工作4.5年了,甚至8年10年的,许多人给我的感觉是:工作了4.5年,We ...
- Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引
因为内容比较多,所以每篇讲解一些内容,最后会放出全部代码,可以参考.操作中总会遇到各式各样的问题,个人对部分问题的研究在最后一篇 问题研究 里.欢迎大家探讨学习. 代码都经过个人测试,但仍可能有各种未 ...
- 1、ASP.NET MVC入门到精通——新语法
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 在学习ASP.NET MVC之前,有必要先了解一下C#3.0所带来的新的语法特性,这一点尤为重要,因为在MVC项目中我们利用C#3.0的新特 ...
- 5、ASP.NET MVC入门到精通——NHibernate代码映射
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 上一篇NHibernate学习笔记—使用 NHibernate构建一个ASP.NET MVC应用程序 使用的是xml进行orm映射,那么这一 ...
- 6、ASP.NET MVC入门到精通——ASP.Net的两种开发方式
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 目前,ASP.NET中两种主流的开发方式是:ASP.NET Webform和ASP.NET MVC.从下图可以看到ASP.NET WebFo ...
- 7、ASP.NET MVC入门到精通——第一个ASP.NET MVC程序
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 开发流程 新建Controller 创建Action 根据Action创建View 在Action获取数据并生产ActionResult传递 ...
- 8、ASP.NET MVC入门到精通——View(视图)
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 View视图职责是向用户提供界面.负责根据提供的模型数据,生成准备提供给用户的格式界面. 支持多种视图引擎(Razor和ASPX视图引擎是官 ...
- 9、ASP.NET MVC入门到精通——Controller(控制器)
本系列目录:ASP.NET MVC4入门到精通系列目录汇总 Controller主要负责响应用户的输入.主要关注的是应用程序流,输入数据的处理,以及对相关视图(View)输出数据的提供. 继承自:Sy ...
随机推荐
- 原创基于Scrum框架产研团队运作20问
学习完了 Scrum,实际使用中,是否遇到/思考过下面的问题? Product Owner的老板是谁.谁来给 Product Owner打绩效.考核的标准是啥? Scrum Master 的老板是谁. ...
- Markdown 包含其他文件静态渲染工具
1. 前言 在 GitHub 上写文档,很多时候要插入 uml,像 mermaid 这种可以直接在 GitHub/GitLab 中渲染的一般直接写个 code block 进去,但是这样造成一个问题就 ...
- tunm, 一种对标JSON的二进制数据协议
Tunm simple binary proto 一种对标JSON的二进制数据协议 支持的数据类型 基本支持的类型 "u8", "i8", "u16& ...
- 2022-10-22 CSP赛前隔离时的模拟赛 2:3
T1 简单红题,不懈于写. 锐评:镜子反射出来的竟然没有镜像一下. T2 坑人东西调了 2h. 类似于 round1 的 T4. 线性 \(\Theta(n)\) 过. T3 T4 其实简单,负边权要 ...
- Python 用户输入和字符串格式化指南
Python 允许用户输入数据.这意味着我们可以向用户询问输入.在 Python 3.6 中,使用 input() 方法来获取用户输入.在 Python 2.7 中,使用 raw_input() 方法 ...
- 3款免费又好用的 Docker 可视化管理工具
前言 Docker提供了命令行工具(Docker CLI)来管理Docker容器.镜像.网络和数据卷等Docker组件.我们也可以使用可视化管理工具来更方便地查看和管理Docker容器.镜像.网络和数 ...
- mysql常用函数详解
1. Mysql内置函数分类及使用范围 数学函数: 这类函数只要用于处理数字.这类函数包括绝对值函数.正弦函数.余弦函数.获取随机数函数等. 字符串函数:这类函数主要用于处理字符串.其中包括字符串连接 ...
- git 添加/删除子模块
背景 在很多项目中经常会重复使用一些代码块, 例如按键处理, LED提示, modbus等等 在传统开发中, 我们经常是将一些代码写成独立的.c/.h模块. 但随着时间的推移我们经常需要根据一 些项目 ...
- ReverseMe-120
一道好题,没解出来但是收获很多 贴两位大牛的题解 [精选]攻防世界逆向高手题之ReverseMe-120-CSDN博客 攻防世界ReverseMe-120详解_攻防世界reverseme基本思路-CS ...
- 小程序video去除上下黑边
方法很简单 ,只需要在video上增加属性 <video objectFit="cover" /> 或者 可通过 wxss 设置宽高 <view class=&q ...