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 的使用从入门到精通的更多相关文章

  1. <程序员从入门到精通> -- How

    定位 自己才是职业生涯的管理者,想清楚自己的发展路径: 远期的理想是什么?近期的规划是什么?今日的任务和功课又是什么? 今日之任务或功课哪些有助于近期之规划的实现,而近期之规划是否有利于远期之理想? ...

  2. 【无私分享:从入门到精通ASP.NET MVC】从0开始,一起搭框架、做项目 目录索引

    索引 [无私分享:从入门到精通ASP.NET MVC]从0开始,一起搭框架.做项目(1)搭建MVC环境 注册区域 [无私分享:从入门到精通ASP.NET MVC]从0开始,一起搭框架.做项目(2)创建 ...

  3. ASP.NET MVC4入门到精通系列目录汇总

    序言 最近公司在招.NET程序员,我发现好多来公司面试的.NET程序员居然都没有 ASP.NET MVC项目经验,其中包括一些工作4.5年了,甚至8年10年的,许多人给我的感觉是:工作了4.5年,We ...

  4. Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引

    因为内容比较多,所以每篇讲解一些内容,最后会放出全部代码,可以参考.操作中总会遇到各式各样的问题,个人对部分问题的研究在最后一篇 问题研究 里.欢迎大家探讨学习. 代码都经过个人测试,但仍可能有各种未 ...

  5. 1、ASP.NET MVC入门到精通——新语法

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 在学习ASP.NET MVC之前,有必要先了解一下C#3.0所带来的新的语法特性,这一点尤为重要,因为在MVC项目中我们利用C#3.0的新特 ...

  6. 5、ASP.NET MVC入门到精通——NHibernate代码映射

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 上一篇NHibernate学习笔记—使用 NHibernate构建一个ASP.NET MVC应用程序 使用的是xml进行orm映射,那么这一 ...

  7. 6、ASP.NET MVC入门到精通——ASP.Net的两种开发方式

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 目前,ASP.NET中两种主流的开发方式是:ASP.NET Webform和ASP.NET MVC.从下图可以看到ASP.NET WebFo ...

  8. 7、ASP.NET MVC入门到精通——第一个ASP.NET MVC程序

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 开发流程 新建Controller 创建Action 根据Action创建View 在Action获取数据并生产ActionResult传递 ...

  9. 8、ASP.NET MVC入门到精通——View(视图)

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 View视图职责是向用户提供界面.负责根据提供的模型数据,生成准备提供给用户的格式界面. 支持多种视图引擎(Razor和ASPX视图引擎是官 ...

  10. 9、ASP.NET MVC入门到精通——Controller(控制器)

    本系列目录:ASP.NET MVC4入门到精通系列目录汇总 Controller主要负责响应用户的输入.主要关注的是应用程序流,输入数据的处理,以及对相关视图(View)输出数据的提供. 继承自:Sy ...

随机推荐

  1. Solution -「洛谷 P2000」拯救世界

    Description Link. 概括什么好麻烦哦 w. Solution 生成函数裸题. 把所有情况罗列出来: kkk: 金: \(1+x^6+x^{12}+\dots=\frac{1}{1-x^ ...

  2. Teamcenter RAC 开发之《新建Item》

    private TCComponentItem createOperation(String itemName,String itemType) { //obejct_name itemType tr ...

  3. c语言代码练习10

    //判断输入的数字是否为素数#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main() { int n = 0; int ...

  4. 文心一言 VS 讯飞星火 VS chatgpt (106)-- 算法导论10.1 4题

    四.用go语言,重写 ENQUEUE 和 DEQUEUE 的代码,使之能处理队列的下溢和上溢. 文心一言: 在 Go 语言中,我们可以使用切片来实现队列.下面是如何实现 ENQUEUE 和 DEQUE ...

  5. 快速启动Stable Diffusion WebUI

    快速启动Stable Diffusion WebUI详情    产品文档   输入文档关键字查找   机器学习PAI 产品概述 快速入门 操作指南 准备工作 开通PAI并创建默认工作空间 开通并授权依 ...

  6. css的认知与样式

      目录 1. 介绍css 2. CSS语法 3. CSS注释 4. CSS中的颜色值 5. CSS长度单位 6. html引入CSS的三种方法 6.1 行内样式(内联样式) 6.2   内嵌样式 6 ...

  7. C++在HotSpot VM中一种巧妙的内存管理方式

    在HotSpot VM中定义了一个Relocation类及相关的子类,可以通过这些类操作不同的重定位数据,如在CodeCache中读写这些数据.这些类需要的内存很小,但是不同的类需要的内存大小又不一样 ...

  8. Java-网络编程(TCP-UDP)

    Java-网络编程(TCP-UDP) 网络基础 网络编程最主要的工作就是在发送端把信息通过规定好的协议进行组装包,在接收端按照规定好的协议把包进行解析,从而提取出对应的信息,达到通信的目的.中间最主要 ...

  9. 一次考试的dp题

    很明显是dp 看题目的时候我们先进行初步的思考,发现一个性质 一个点时不可能被重复覆盖三次的很显然,如果一个点被覆盖了3次,这3个覆盖他的区间一定是有一个区间被完全包含的,因为有贡献的左右端点只有两个 ...

  10. dig 简明教程

    哈喽大家好,我是咸鱼 不知道大家在日常学习或者工作当中用 dig 命令多不多 dig 是 Domain Information Groper 的缩写,对于网络管理员和在域名系统(DNS)领域工作的小伙 ...