Click here to Skip to main content
15,861,168 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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);

}
Posted

1 solution

chart.SaveImage(@"C:\Matlab\" + (g).ToString() + ".png", ChartImageFormat.Png);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900