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.

Thu Jan 11, 2018 11:54 am

Hi guys,

Basically I want to change color and width of PrimaryValueAxis though couldn't found any relevant properties there.
Can you help me with that? Please see attachment to see what I want to achieve

Thanks.

Stecya
 
Posts: 27
Joined: Wed Jan 10, 2018 2:36 pm

Fri Jan 12, 2018 3:09 am

Hello,

Thanks for your inquiry.
Sorry that our Spire.Presentation doesn't support the setting of line color and width for PrimaryValueAxis at present. We will consider adding it in our future upgrade. Once there's an update, I will let you know.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Jan 29, 2018 9:43 am

Hello Stecya,

Glad to inform that your issue has been resolved. Please download the Spire.Presentation Pack Version:2.9 and use the below code to set the axis color and width.

Code: Select all
IChart chart = presentation.Slides[0].Shapes[0] as IChart;
//SecondaryValueAxis is for Y axis and  PrimaryValueAxis is for X axixs.
chart.SecondaryValueAxis.ChartEffectFormat.Line.FillType = FillFormatType.Solid;
chart.SecondaryValueAxis.ChartEffectFormat.Line.Width = 2;
chart.SecondaryValueAxis.ChartEffectFormat.Line.FillFormat.SolidFillColor.Color = Color.Red;


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Feb 01, 2018 9:29 am

Hello Stecya,

Good day!
Has your issue been resolved by the hotfix?
Your feedback would be greatly appreciated.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Sun Sep 26, 2021 7:03 am

Hello,
When i get a chart in a slide it doesn't get the color and labels.
- Chart line color turns green to red
- Chart labels turns to string empty.

I'm giving the sample code and sample presentation file below.

Chart on template slide
18f44514-ccfb-4579-84f6-533aaa383b6e.png


Chart on output slide
817efdf2-99fb-49f7-9bd6-fc127eac0693.png


Sample Code:

Code: Select all
IChart chart = templatePresentation.Slides[0].Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;
//SecondaryValueAxis is for Y axis and  PrimaryValueAxis is for X axixs.
var chartFillType = chart.PrimaryCategoryAxis.ChartEffectFormat.Line.FillType;
var chartWidth = chart.PrimaryCategoryAxis.ChartEffectFormat.Line.Width;
var chartLineColor = chart.PrimaryCategoryAxis.ChartEffectFormat.Line.FillFormat.SolidFillColor.Color;

Debug.WriteLine("chartFillType-PrimaryCategoryAxis:" + chartFillType);
Debug.WriteLine("chartWidth-PrimaryCategoryAxis:" + chartWidth);
Debug.WriteLine("chartLineColor-PrimaryCategoryAxis:" + chartLineColor);


Output:
chartFillType:UnDefined
chartWidth:NaN
chartLineColor:Color [A=255, R=0, G=0, B=0]

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Sun Sep 26, 2021 9:06 am

Hello Omur,

Thanks for your feedback.
After I tried to load your source .pptx file(example_template2.pptx) and saved it to a new .pptx file, the chart color still is green that is same as the original.
Code: Select all
 Presentation templatePresentation = new Presentation();
 templatePresentation.LoadFromFile("example_template2.pptx");
 templatePresentation.SaveToFile("result.pptx",FileFormat.Pptx2013);

The above is my test code. If you tested differently than I do, please share your full code to help me reproduce your color issue. Thank you!

For the issue about the data read from the axis lines, the result you got is correct. In your template file, the attributes of the axis lines are not defined(as shown below).
original.png

After defining the axis lines like the below, you can retrieve these values.
modified.png


If you have any questions, please contact us.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Sep 27, 2021 7:51 am

Thank you for your reply. At my code i'm changing the template slide chart data and append that slide into new presentation file.

Template file :
example_template2.rar

Result File :
result.rar


My FullCode is:

Code: Select all
using Newtonsoft.Json.Linq;
using Spire.Presentation;
using Spire.Presentation.Charts;
using System;
using System.Linq;

namespace PptxTester
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load template presentation
            Presentation templatePresentation = new Presentation();
            templatePresentation.LoadFromFile("example_template2.pptx");
           

            //Create new presentation
            Spire.Presentation.Presentation newPresentation = new Spire.Presentation.Presentation();
            newPresentation.Slides.RemoveAt(0);

            //Get first slide from template presentation
            var slide = templatePresentation.Slides[0];

            //Change Chart Data                       
            IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;
            chart.ChartData[0, 1].Value = "Series 1";
            chart.ChartData[1, 0].Value = "Male";
            chart.ChartData[2, 0].Value = "Female";
            chart.ChartData[1, 1].Value = 0.1;
            chart.ChartData[2, 1].Value = 0.9;

            int categoryCount = 2;
            int seriesCount = 1;
            chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];

            for (int i = 0; i < seriesCount; i++)
            {
                string letter = GetColumnName(i + 1);
                chart.Series[i].Values = chart.ChartData[letter + "2", letter + (categoryCount + 1)];
            }
            //------------------------------------------------------------------------------------------

            //Append first slide to new presentation
            newPresentation.Slides.Append(slide);

            //Save presentation
            newPresentation.SaveToFile("result.pptx", FileFormat.Pptx2013);
        }

        static string GetColumnName(int index)
        {
            const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var value = "";

            if (index >= letters.Length)
                value += letters[index / letters.Length - 1];

            value += letters[index % letters.Length];

            return value;
        }
    }
}

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Mon Sep 27, 2021 9:49 am

Hello Omur,

Thanks for providing your code and files. I have reproduced the color issue and logged it into our issue tracking system with the ticket SPIREPPT-1694.
We will notify you once it is resolved.

Feel free to contact us if any questions.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Sep 28, 2021 8:43 am

Hello Omur,

I have got news about the color issue from our Dev team. When resetting this property chart.Series.SeriesLabel like chart.Series.SeriesLabel=chart.ChartData["B1", GetColumnName(seriesCount) + "1"]; in your code, the format of the series is initialized, so please reset the fill format for series after this line "chart.Series.SeriesLabel=chart.ChartData["B1", GetColumnName(seriesCount) + "1"];"

Sample code for reference:
Code: Select all
       
            IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;
              //Get original fill format of series
            List<FillFormat> fillFormat = new List<FillFormat>();
            for (int j = 0; j < chart.Series.Count; j++)
            {
                fillFormat.Add(chart.Series[j].Fill);
            }
           .....
           


Code: Select all
          chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];
            //Set the fill format for Series
            for (int j = 0; j < chart.Series.Count; j++)
            {
                chart.Series[j].Fill.FillType = fillFormat[j].FillType;
                chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
            }

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Sep 28, 2021 1:58 pm

Thank you very much. It works great. Line color preserved.

One another thing i recognize is data labels lost too. I think i have to re assign data labels too.

Before
1.png

After
2.png


But how can i do that ?

Template File:
example_template2.rar

Result File :
example_template2.rar



Code: Select all
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PptxTester
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load template presentation
            Presentation templatePresentation = new Presentation();
            templatePresentation.LoadFromFile("example_template2.pptx");
           

            //Create new presentation
            Spire.Presentation.Presentation newPresentation = new Spire.Presentation.Presentation();
            newPresentation.Slides.RemoveAt(0);

            //Get first slide from template presentation
            var slide = templatePresentation.Slides[0];

            //Change Chart Data                       
            IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;

            //Get original fill format of series
            List<FillFormat> fillFormat = new List<FillFormat>();
            for (int j = 0; j < chart.Series.Count; j++)
            {
                fillFormat.Add(chart.Series[j].Fill);
            }

            chart.ChartData[0, 1].Value = "Series 1";
            chart.ChartData[1, 0].Value = "Male";
            chart.ChartData[2, 0].Value = "Female";
            chart.ChartData[1, 1].Value = 0.1;
            chart.ChartData[2, 1].Value = 0.5;

            int categoryCount = 2;
            int seriesCount = 1;
            chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];

            //Set the fill format for Series
            for (int j = 0; j < chart.Series.Count; j++)
            {
                chart.Series[j].Fill.FillType = fillFormat[j].FillType;
                chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
            }

            for (int i = 0; i < seriesCount; i++)
            {
                string letter = GetColumnName(i + 1);
                chart.Series[i].Values = chart.ChartData[letter + "2", letter + (categoryCount + 1)];
            }
            //------------------------------------------------------------------------------------------

            //Append first slide to new presentation
            newPresentation.Slides.Append(slide);

            //Save presentation
            newPresentation.SaveToFile("result.pptx", FileFormat.Pptx2013);
        }

        static string GetColumnName(int index)
        {
            const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var value = "";

            if (index >= letters.Length)
                value += letters[index / letters.Length - 1];

            value += letters[index % letters.Length];

            return value;
        }
    }
}

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Wed Sep 29, 2021 2:15 am

Hello Omur,

You're welcome. Thanks for your feedback.
For the new issue about data labels, please refer to the following code snippet to add data labels for series and set their formats.
Code: Select all
        //Set the fill format for Series
            for (int j = 0; j < chart.Series.Count; j++)
            {
                chart.Series[j].Fill.FillType = fillFormat[j].FillType;
                chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
               
                //Add and set data labels
                for (int i = 0; i < 2; i++)
                {
                    ChartDataLabel dataLabel = chart.Series[j].DataLabels.Add();
                    dataLabel.HasDataSource = false;
                    dataLabel.LabelValueVisible = true;
                    dataLabel.NumberFormat = "0%";                 
                }

            }


Feel free to contact us if any issues.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Sep 30, 2021 9:39 am

Hello Omur,

Has your issue about data labels been solved? Any feedback will be appreciated.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Sun Oct 10, 2021 2:20 pm

Thank you very much Amy,
For data labels it works like a charm.

But for an another slide, again i lost chart bar colors. It's the Chart 33 at the 6th slide.

Template File Name: example_template2.pptx
Result File Name: result.pptx

Template and Result File :
template_result.rar


Template Presentation Chart
01.PNG


Result Presentation Chart
02.PNG


Source Code:

Code: Select all
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PptxTester
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load template presentation
            Presentation templatePresentation = new Presentation();
            templatePresentation.LoadFromFile("example_template2.pptx");
           

            //Create new presentation
            Spire.Presentation.Presentation newPresentation = new Spire.Presentation.Presentation();
            newPresentation.Slides.RemoveAt(0);

            //Get first slide from template presentation
            var slide = templatePresentation.Slides[5];

            //Change Chart Data                       
            IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 33") as IChart;

            //Get original fill format of series
            List<FillFormat> fillFormat = new List<FillFormat>();
            for (int j = 0; j < chart.Series.Count; j++)
            {
                fillFormat.Add(chart.Series[j].Fill);
            }

            chart.ChartData[0, 1].Value = "Break 1";
            chart.ChartData[0, 2].Value = "Break 2";
            chart.ChartData[0, 3].Value = "Break 3";

            chart.ChartData[1, 0].Value = "I would look at what other concerts are available from NETWORK through streaming or their app";
            chart.ChartData[2, 0].Value = "I would look for what other content NETWORK has available through streaming or their app";
            chart.ChartData[3, 0].Value = "I would visit NETWORK.org";
            chart.ChartData[4, 0].Value = "I would visit my local NETWORK station’s website";
           

            chart.ChartData[1, 1].Value = 0.2;
            chart.ChartData[1, 2].Value = 0.6;
            chart.ChartData[1, 3].Value = 0.2;

            chart.ChartData[2, 1].Value = 0.7;
            chart.ChartData[2, 2].Value = 0.2;
            chart.ChartData[2, 3].Value = 0.1;

            chart.ChartData[3, 1].Value = 0.7;
            chart.ChartData[3, 2].Value = 0.2;
            chart.ChartData[3, 3].Value = 0.1;

            chart.ChartData[4, 1].Value = 0.5;
            chart.ChartData[4, 2].Value = 0.2;
            chart.ChartData[4, 3].Value = 0.3;

            int categoryCount = 4;
            int seriesCount = 3;
            chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];

            //Set the fill format for Series
            for (int j = 0; j < chart.Series.Count; j++)
            {
                chart.Series[j].Fill.FillType = fillFormat[j].FillType;
                chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
            }


            for (int j = 0; j < chart.Series.Count; j++)
            {
                chart.Series[j].Fill.FillType = fillFormat[j].FillType;
                chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;

                //Add and set data labels
                for (int i = 0; i < 4; i++)
                {
                    ChartDataLabel dataLabel = chart.Series[j].DataLabels.Add();
                    dataLabel.HasDataSource = false;
                    dataLabel.LabelValueVisible = true;
                    dataLabel.NumberFormat = "0%";
                }
            }


            for (int i = 0; i < seriesCount; i++)
            {
                string letter = GetColumnName(i + 1);
                chart.Series[i].Values = chart.ChartData[letter + "2", letter + (categoryCount + 1)];
            }
            //------------------------------------------------------------------------------------------

            //Append first slide to new presentation
            newPresentation.Slides.Append(slide);

            //Save presentation
            newPresentation.SaveToFile("result.pptx", FileFormat.Pptx2013);
        }

        static string GetColumnName(int index)
        {
            const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var value = "";

            if (index >= letters.Length)
                value += letters[index / letters.Length - 1];

            value += letters[index % letters.Length];

            return value;
        }
    }
}

omurertanis
 
Posts: 22
Joined: Tue Mar 30, 2021 7:56 pm

Mon Oct 11, 2021 3:20 am

Hello Omur,

Thanks for your further feedback.
I have duplicated your issue and logged it in our issue tracking system. Sorry for the inconvenience caused. We will inform you once it is solved.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Oct 26, 2021 7:50 am

Dear Omur,

Thanks for patient waiting.
Glad to tell you that SPIREPPT-1704(The color of chart bar lost) has been solved. I will inform you when new version is released.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Presentation