Farhan Shariff

Farhan Shariff

  • NA
  • 933
  • 241.6k

Renaming and saving file each time code executes

Mar 31 2014 10:11 AM
I have a DataTable

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++)
{
 
          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);

}

Answers (4)