Hey folks, I have code that is supposed to generate a PowerPoint chart automatically. However, whenever I implement this code, it breaks the slide. No idea why it does this but whatever. So, here is the code to call the slide builder helper:
That InitChartData(c hart1, dt1) call goes into this routine:
Code:
SqlCommand sqlcmdLOC = new SqlCommand(sqlQueryLOC, sqlconn);
using (SqlDataAdapter da1 = new SqlDataAdapter(sqlcmdLOC))
{
DataTable dt1 = new DataTable();
da1.Fill(dt1);
InitChartData(chart1, dt1);
sqlconn.Close();
}
Code:
private static void InitChartData(IChart chart1, DataTable dt1)
{
//set series name
ChartSeriesFormatCollection ctf = chart1.Series;
for (int c = 0; c < dt1.Columns.Count; c++)
{
chart1.ChartData[0, c].Text = dt1.Columns[c].Caption;
if (c > 0)
{
ctf.Append(chart1.ChartData[0, c]);
}
}
ChartCategoryCollection catg = chart1.Categories;
for (int r = 0; r < dt1.Rows.Count; r++)
{
//set category
catg.Append(chart1.ChartData[r + 1, 0]);
//set chartData value
object[] data = dt1.Rows[r].ItemArray;
for (int c = 0; c < data.Length; c++)
{
chart1.ChartData[r + 1, c].Value = data[c];
}
//set series value
for (int i = 0; i < ctf.Count; i++)
{
chart1.Series[i].Values.Add(chart1.ChartData[r + 1, i + 1]);
}
}
}
Comment