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.

Wed Dec 15, 2021 8:23 am

Dears ,

am trying to create chart by c# code and i want to change chart line color
i am using the below code but color didn't change


Code: Select all
  RectangleF rect1 = new RectangleF(40, 100, 900, 320);
  IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Line, rect1, false);
  chart.Line.SolidFillColor.Color = Color.Black;


also i am adding Trendline and want to change color but same issue
Code: Select all
    ITrendlines it = chart.Series[0].AddTrendLine(TrendlinesType.Linear);
            it.displayEquation = false;
            it.displayRSquaredValue = false;
            it.type = TrendlinesType.Polynomial;
            it.polynomialTrendlineOrder = 6;
            it.Line.SolidFillColor.KnownColor = KnownColors.Green;



i am using version FreeSpire.Presentation 6.8.5

neverisnothing
 
Posts: 5
Joined: Wed Dec 15, 2021 7:42 am

Wed Dec 15, 2021 9:04 am

Hello,

Thanks for your inquiry!

Before you set the color of SolidFillColor, you need to set the fill type of the line to the SoildFill first. Please refer to the following code to set this property. If there are any questions, please feel free to write back.

Code: Select all
            chart.Line.FillType = FillFormatType.Solid;
            chart.Line.SolidFillColor.Color = Color.Black;
... ....
            it.Line.FillType = FillFormatType.Solid;
            it.Line.SolidFillColor.KnownColor = KnownColors.Green;


Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Dec 15, 2021 9:40 am

Still nothing changed

neverisnothing
 
Posts: 5
Joined: Wed Dec 15, 2021 7:42 am

Wed Dec 15, 2021 10:28 am

Hello,

Thanks for your feedback!

Here I attached the code I tested, and the file generated. In the screenshot, you can see that the color of the chart line and the trend line have changed.
Code: Select all
            Presentation ppt = new Presentation();
            RectangleF rect1 = new RectangleF(40, 100, 900, 320);
            IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Line, rect1, false);

            chart.Line.FillType = FillFormatType.Solid;
            chart.Line.SolidFillColor.Color = Color.Black;



            //Data for series
            Double[] Series1 = new Double[] { 7.7, 8.9, 1.0, 2.4 };
            Double[] Series2 = new Double[] { 15.2, 5.3, 6.7, 8 };

            //Set series text
            chart.ChartData[0, 1].Text = "Series1";
            chart.ChartData[0, 2].Text = "Series2";

            //Set category text
            chart.ChartData[1, 0].Text = "Category 1";
            chart.ChartData[2, 0].Text = "Category 2";
            chart.ChartData[3, 0].Text = "Category 3";
            chart.ChartData[4, 0].Text = "Category 4";

            //Fill data for chart
            for (Int32 i = 0; i < Series1.Length; ++i)
            {
                chart.ChartData[i + 1, 1].Value = Series1[i];
                chart.ChartData[i + 1, 2].Value = Series2[i];

            }

            //Set series label
            chart.Series.SeriesLabel = chart.ChartData["B1", "C1"];
            //Set category label
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];

            //Set values for series
            chart.Series[0].Values = chart.ChartData["B2", "B5"];
            chart.Series[1].Values = chart.ChartData["C2", "C5"];



            ITrendlines it = chart.Series[0].AddTrendLine(TrendlinesType.Linear);
            it.displayEquation = false;
            it.displayRSquaredValue = false;
            it.type = TrendlinesType.Polynomial;
            it.polynomialTrendlineOrder = 6;
            it.Line.FillType = FillFormatType.Solid;
            it.Line.SolidFillColor.KnownColor = KnownColors.Green;

            String result = "CreateLineMarkersChart_result.pptx";
            //Save the document
            ppt.SaveToFile(result, FileFormat.Pptx2010);

color.png


Could you please provide us with your whole testing code, your target framework(E.g. .Net framework 4.8.0), your system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese) for reference? Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Wed Dec 15, 2021 10:51 am

i need to change the main chart line color (or hide it and keep the trendline only)

Code: Select all
 Presentation ppt = new Presentation();
            ppt.SlideSize.Type = SlideSizeType.A3;

            //Insert a chart and set the chart type. 
            RectangleF rect1 = new RectangleF(40, 100, 900, 320);
            IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Line, rect1, false);

            //Add a title for the chart and format it. 

            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;
            chart.HasTitle = true;
            chart.HasLegend = false;
            chart.PrimaryValueAxis.MajorGridTextLines.FillType = FillFormatType.Gradient;
            chart.PrimaryValueAxis.NumberFormat = "###,0";
            chart.Line.FillType = FillFormatType.Solid;
            chart.Line.SolidFillColor.KnownColor = KnownColors.Red;
            int[] quarters =  new string[] { "1st Qtr", "2nd Qtr", "3rd Qtr", "4th Qtr" };
            double[] sales = new double[] { 1000, 2000, 4000 ,5000};
            chart.ChartData[0, 1].Text = "Sales";
            chart.ChartTitle.TextProperties.Text = "ADS Report  Stores";
             chart.ChartData[0, 0].Text = "Quarters";
            for (int i = 0; i < quarters.Length; ++i)
            {
                chart.ChartData[i + 1, 0].Value = Convert.ToString("W" + (quarters[i] - minweek));
                chart.ChartData[i + 1, 1].Value = (sales[i].ToString("F"));
            }
  chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A13"];
            chart.Series[0].Values = chart.ChartData["B2", "B13"];
            //Add data points to series and fill each data point with different KnownColors. 
            for (int i = 0; i < chart.Series[0].Values.Count; i++)
            {
                ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]);
                cdp.Index = i;
                chart.Series[0].DataPoints.Add(cdp);
                cdp.Fill.FillType = FillFormatType.Solid;
                cdp.Fill.SolidColor.KnownColor = KnownColors.Green;
            }
            ITrendlines it = chart.Series[0].AddTrendLine(TrendlinesType.Linear);

            //Set the trend line properties to determine what should be displayed. 
            it.displayEquation = false;
            it.displayRSquaredValue = false;
            it.type = TrendlinesType.Polynomial;
            it.polynomialTrendlineOrder = 6;
            it.Line.CapStyle = LineCapStyle.Round;
            it.Line.JoinStyle = LineJoinType.Round;
            it.Line.Width = 2;
            it.Line.DashStyle = LineDashStyleType.Solid;
            it.Line.FillType = FillFormatType.Solid;
            it.Line.SolidFillColor.KnownColor = KnownColors.Green;
           ppt.SaveToFile(Application.StartupPath + "\\PDFS\\sales\\ADS Report " + title + ".pdf", Spire.Presentation.FileFormat.PDF

neverisnothing
 
Posts: 5
Joined: Wed Dec 15, 2021 7:42 am

Thu Dec 16, 2021 1:33 am

Hello,

Thanks for your reply!

Please use "chart.Series[0].Line.FillType = FillFormatType.None;" to hide the line of the first series and keep the trend line only.

Besides, I did notice that the color of the trend line did not change after saving the presentation to PDF format, and I have logged it in our issue tracking system with the ticket SPIREPPT-1801 for further investigation.

We will let you know if there is any update. Sorry for the inconvenience caused.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Fri Dec 24, 2021 7:55 am

Hello,

Thanks for your patience!

Glad to inform you that we just released Spire.Presentation Pack Hotfix Version:6.12.4 which fixes the issue of SPIREPPT-1801.

Please download the fix version from the following links to test.

Website link: https://www.e-iceblue.com/Download/download-presentation-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.Presentation/6.12.4

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue Jan 04, 2022 6:26 am

Hello,

Hope you are doing well!

Has the issue been solved now? Could you please give us some feedback at your convenience?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.Presentation