Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Mon Nov 10, 2014 11:27 am

Given the following example code:

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];
                }
            }
        }

    }

tuijlPL
 
Posts: 11
Joined: Fri Nov 07, 2014 4:14 pm

Tue Nov 11, 2014 8:15 am

Hello,

Thanks for your feedback. I have noticed the issue you mentioned, which has been transferred to our Dev team, once there are any update, we will let you know.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Nov 14, 2014 2:49 am

Hello,

By investigating, there is a method to set the color of datapoint of series. Here are the codes for your reference.
Code: Select all
ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]);
cdp.Index = 1;
cdp.Fill.FillType = FillFormatType.Solid;
cdp.Fill.SolidColor.KnownColor = KnownColors.Green;
chart.Series[0].DataPoints.Add(cdp);

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Nov 17, 2014 9:49 am

Thanks for the example that solved our problem!

tuijlPL
 
Posts: 11
Joined: Fri Nov 07, 2014 4:14 pm

Tue Dec 16, 2014 7:12 am

Hello,

Thanks for your feedback, if there are any questions, welcome to get it back to us.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Presentation