DataTable列到图表(图表) [英] DataTable column to chart (graph)
问题描述
我有一个DataTable如下:
new |老| New_1 |情节
2.1 | 1.1 | 4.3 | 0.60
0.4 | 1.2 | 2.1 | 0.12
3.1 | 2.3 | 3.2 | 0.29
我想绘制图表:1new vs plot,Old vs plot,new_1 vs plot1并将每个图保存为图像,从而为每列创建多个图表图像。
我想使用列索引,绘图列的索引是固定的。
我想如果我能够保存图像每次使用不同的名称并循环列索引,我将能够为每列生成图表。
I have a DataTable as the following:
new | Old | New_1| plot
2.1 | 1.1 | 4.3 | 0.60
0.4 | 1.2 | 2.1 | 0.12
3.1 | 2.3 | 3.2 | 0.29
I want to plot chart's with: 1new vs plot , Old vs plot, new_1 vs plot1 and save each of plots as images thus creating multiple chart images one for each column.
I want to use column index, the index of plot column is fixed.
I think if I am able to save image with different names each time and loop the column index ,I will be able to generate charts for each column.
for (int g = 0; g < resultDt.Columns.Count-1; g++)
// (resultDt.Columns.Count-1) last column is plot
{
Chart chart = new Chart(); chart.DataSource = resultDt;
chart.Width = 800;
chart.Height = 550;
//create serie...
Series serie1 = new Series();
serie1.Name = "Serie1";
serie1.Color = Color.FromArgb(112, 255, 200);
serie1.BorderColor = Color.FromArgb(164, 164, 164);
serie1.ChartType = SeriesChartType.Line;
serie1.XValueMember = resultDt.Columns[0].ColumnName;
serie1.YValueMembers = "plot";
chart.Series.Add(serie1);
//create chartareas...
ChartArea ca = new ChartArea();
ca.Name = "ChartArea1";
ca.BackColor = Color.White;
ca.BorderColor = Color.FromArgb(26, 59, 105);
ca.BorderWidth = 0;
ca.BorderDashStyle = ChartDashStyle.Solid;
ca.AxisX = new Axis();
ca.AxisY = new Axis();
//ChartArea
ca = new ChartArea("main");
ca.BackColor = System.Drawing.Color.FromArgb(64, System.Drawing.Color.White);
chart.ChartAreas.Add(ca);
//databind...
chart.DataBind();
//save result...
chart.SaveImage(@"C:\myChart.png", ChartImageFormat.Png);
}
推荐答案
chart.SaveImage(@"C:\Matlab\" + (g).ToString() + ".png", ChartImageFormat.Png);
这篇关于DataTable列到图表(图表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!