How to change the color of an individual point? see "Program fails here!" in code.
And how can i access the other properties of the data points?
- Code: Select all
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
//set background Image
string ImageFile = "bg.png";
RectangleF rect2 = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect2);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
//insert chart
RectangleF rect = new RectangleF(50, 100, 400, 400);
IChart chart = presentation.Slides[0].Shapes.AppendChart(Spire.Presentation.Charts.ChartType.ColumnClustered, rect);
//add chart Title
chart.ChartTitle.TextProperties.Text = "Report";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
//load data from XML file to datatable
DataTable dataTable = LoadData();
//load data from datatable to chart
InitChartData(chart, dataTable);
chart.Series[0].Type = ChartType.ColumnStacked;
chart.Series[1].Type = ChartType.ColumnStacked;
chart.Series[2].Type = ChartType.Line;
[b]// Program fails here!
chart.Series[0].DataPoints[0].Fill.SolidColor.KnownColor = KnownColors.Aqua; [/b]
//save the document
presentation.SaveToFile("chart.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("chart.pptx");
}
//function to load data from XML file to DataTable
private static DataTable LoadData()
{
DataSet ds = new DataSet();
ds.ReadXmlSchema("data-schema.xml");
ds.ReadXml("data.xml");
return ds.Tables[0];
}
//function to load data from DataTable to IChart
private static void InitChartData(IChart chart, DataTable dataTable)
{
for (int c = 0; c < dataTable.Columns.Count; c++)
{
chart.ChartData[0, c].Text = dataTable.Columns[c].Caption;
}
for (int r = 0; r < dataTable.Rows.Count; r++)
{
object[] data = dataTable.Rows[r].ItemArray;
for (int c = 0; c < data.Length; c++)
{
chart.ChartData[r + 1, c].Value = 3;// data[c];
}
}
}
}