求助!把数据库中的数据用chart画成折线图,用c#来做,求代码!!

qq_37804445 2017-04-13 09:14:29
把SQL SEVER数据库中的数据用chart控件画成曲线图,用c#来做,求代码!!

比如数据库一列是温度,一列是时间,画出折线图显示时间是x轴,温度是y轴;
...全文
1010 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
komla168 2017-11-09
  • 打赏
  • 举报
回复
引用 12 楼 wenhuizhen0289 的回复:
[quote=引用 10 楼 qq_34997704 的回复:] [quote=引用 8 楼 wenhuizhen0289 的回复:] ChartArea area = this.chart1.ChartAreas[0];为什么这行报错啊,超出索引范围,但是我并没有超出啊
是不是没有添加集合[/quote] 添加了呀,就是不行。[/quote] 你整出来了吗,我也是报错这里,你怎么办的
Squall001 2017-11-09
  • 打赏
  • 举报
回复
楼上各位大神,有那么麻烦? 楼主搜索http://echarts.baidu.com/,各种图表都有,美观简洁~~~只需要传数据就行了,什么画图都不用考虑了~~~ 当然你自己要学习研究也可以,哈哈, 兄弟给两分吧,没分了
komla168 2017-11-08
  • 打赏
  • 举报
回复
这个是不是要在窗体上加chart控件啊
wenhuizhen0289 2017-09-18
  • 打赏
  • 举报
回复
引用 10 楼 qq_34997704 的回复:
[quote=引用 8 楼 wenhuizhen0289 的回复:] ChartArea area = this.chart1.ChartAreas[0];为什么这行报错啊,超出索引范围,但是我并没有超出啊
是不是没有添加集合[/quote] 添加了呀,就是不行。
taoye_11 2017-09-17
  • 打赏
  • 举报
回复
网上很多这样的例子
拇指男孩 2017-09-16
  • 打赏
  • 举报
回复
引用 8 楼 wenhuizhen0289 的回复:
ChartArea area = this.chart1.ChartAreas[0];为什么这行报错啊,超出索引范围,但是我并没有超出啊

是不是没有添加集合
拇指男孩 2017-09-16
  • 打赏
  • 举报
回复
private void ChartForm_Load(object sender, EventArgs e) { //设置图表标题 System.Windows.Forms.DataVisualization.Charting.Title tit = new System.Windows.Forms.DataVisualization.Charting.Title(); tit.Text = "人员业绩"; chart1.Titles.Add(tit); chart1.Series[0].XValueMember = "Name"; // 设置X轴数据表的列名 chart1.Series[0].YValueMembers = "Score"; //设置Y轴 //柱状/折线显示 chart1.Series[0].LegendText = "业绩"; chart1.Series[0].Label = "#VAL"; // 设置图形颜色 chart1.Series[0].Color = Color.Aqua; //饼图显示 //chart1.Series[0].LegendText = "#VAL"; //chart1.Series[0].Label = "#VALX (#PERCENT)"; //设置图表的图形 chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;//折线 chart1.DataSource = GetData();//数据源 //把图形保存成图片 chart1.SaveImage("abc.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); }
wenhuizhen0289 2017-09-16
  • 打赏
  • 举报
回复
ChartArea area = this.chart1.ChartAreas[0];为什么这行报错啊,超出索引范围,但是我并没有超出啊
wang_peng_yl 2017-04-18
  • 打赏
  • 举报
回复
用VS2010及以上版本开发,我这个设计的是背景是黑的,线是白的,你可以改,自带Chart代码如下: private System.Windows.Forms.DataVisualization.Charting.Chart chart1; private void Form1_Load(object sender, EventArgs e) { this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.chart1.Series.Clear(); this.chart1.BackColor = Color.Black; Series series = new Series();    series.XValueType = ChartValueType.Time; series.LabelForeColor = Color.White; series.ChartType = SeriesChartType.Line; series.IsValueShownAsLabel = true; this.chart1.Series.Add(series); ChartArea area = this.chart1.ChartAreas[0]; area.BackColor = Color.Black; Axis axisX = this.chart1.ChartAreas[0].AxisX; axisX.IsStartedFromZero = true; axisX.LineWidth = 2; axisX.Maximum = 400; //可不写,它会自动技算,但效果不好 //axisX.Minimum = 0; //如果写这个,会不从0开始 axisX.IntervalAutoMode = IntervalAutoMode.FixedCount; axisX.Interval = 1; axisX.LabelStyle = new LabelStyle() { ForeColor=Color.White }; axisX.LineColor = Color.White; axisX.IsMarginVisible = false; Axis axisY = this.chart1.ChartAreas[0].AxisY; axisY.LabelStyle = new LabelStyle() { ForeColor = Color.White }; axisY.LineColor = Color.White;       this.CreateChart(series); } private void CreateChart(Series series) { try { string connectionString = "Server = myServerAddress;Database = myDataBase;User ID = myUsername;Password = myPassword"; SqlConnection conection = new SqlConnection(connectionString); conection.Open(); string selectCommandText = "select 温度,时间 from 表名"; SqlDataAdapter da = new SqlDataAdapter(selectCommandText, conection); DataTable dt = new DataTable(); da.Fill(dt); conection.Close(); foreach (DataRow row in dt.Rows) { float temperature = float.Parse(row["温度"].ToString()); DateTime time = DateTime.Parse(row["时间"].ToString()); series.Points.AddXY(time, temperature); } } catch (Exception ex) { throw ex; } }
大鱼> 2017-04-17
  • 打赏
  • 举报
回复
引用 4 楼 xuggzu 的回复:
2k给2楼打包了!
你们好客气啊。3楼只需要500
xuggzu 2017-04-14
  • 打赏
  • 举报
回复
2k给2楼打包了!
夏天的枫 2017-04-14
  • 打赏
  • 举报
回复
引用 2 楼 duanzi_peng 的回复:
给一楼 1K 他给你做了。
。。。。。。
exception92 2017-04-14
  • 打赏
  • 举报
回复
给一楼 1K 他给你做了。
xuggzu 2017-04-13
  • 打赏
  • 举报
回复
从数据库取数据,以及简单的Chart画折线图网上都有现成的,搜搜吧。

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧