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 10, 2014 9:45 pm

Hi, I am attempting to set two different colors for the bars in my clustered bar chart. I am specifying two different colors for positive and negative values and setting the color per data point.

Here is my code:

Code: Select all
for (int r = 0; r < rowCount; r++)
{
    // Set color
    ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]);
    cdp.Index = r;
    cdp.Fill.FillType = FillFormatType.Solid;
    cdp.InvertIfNegative = false;

    if ((double)chartDataTable.Rows[r]["Change"] > 0)
    {
          cdp.Fill.SolidColor.R = 141;
          cdp.Fill.SolidColor.G = 198;
          cdp.Fill.SolidColor.B = 63;
    }
    else
    {
          cdp.Fill.SolidColor.R = 215;
          cdp.Fill.SolidColor.G = 0;
          cdp.Fill.SolidColor.B = 54;
    }
}


However, the InvertIfNegative on the ChartDataPoint is not working. It does not appear to be written to the XML behind the chart.

I have also tried to use a template where the Invert color is specified, but that is getting overwritten and I cannot find where in the Series object to specify it.

Thanks in advance.

dkmallott
 
Posts: 3
Joined: Wed Dec 10, 2014 9:18 pm

Thu Dec 11, 2014 8:39 am

Hello,

Thanks for your inquiry.
I tried the following code and InvertIfNegative property was working.
Code: Select all
  Presentation presentation = new Presentation();
            RectangleF rect = new RectangleF(presentation.SlideSize.Size.Width / 2 - 200, 100, 400, 400);
            IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.BarClustered, rect, false);
            InitChartData(chart);

            chart.Categories.CategoryLabels = chart.ChartData["A2", "A9"];
            chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];

            chart.Series[0].Values = chart.ChartData["B2", "B9"];
            chart.Series[0].Fill.FillType = FillFormatType.Solid;
            chart.Series[0].InvertIfNegative = true;

            for (int r = 0; r < 8; r++)
            {
                ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]);
                cdp.Index = r;
                cdp.Fill.FillType = FillFormatType.Solid;
                cdp.InvertIfNegative = false;
                chart.Series[0].DataPoints.Add(cdp);
                if (chart.Series[0].Values[r].NumberValue > 0)
                {
                    cdp.Fill.SolidColor.R = 141;
                    cdp.Fill.SolidColor.G = 198;
                    cdp.Fill.SolidColor.B = 63;
                }
                else
                {
                    cdp.Fill.SolidColor.R = 255;
                    cdp.Fill.SolidColor.G = 255;
                    cdp.Fill.SolidColor.B = 255;
                }
            }         
            presentation.SaveToFile("chart.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("chart.pptx");
        }
        static void InitChartData(IChart chart)
        {
            chart.ChartData[0, 1].Text = "Series1";
            string[] text = new string[] { "A","B","C","D","E","F","G","H"};
            double[] data = new double[] { -0.3, 1, 0.5, -0.8, -0.5, 1.4, 0.8, -0.7 };
            for (int r = 0; r < text.Length; ++r)
            {
                chart.ChartData[r+1, 0].Value = text[r];
                chart.ChartData[r+1, 1].NumberValue = data[r];
            }
        }


If you still have the issue, please share all your code here. Thanks.

Best wishes,
Amy
E-iceblue support team
User avatar

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

Fri Dec 12, 2014 2:56 pm

Amy,

Thank you for your prompt response. Your code does indeed work, however, I am not seeing anywhere to specify the color to use for the inversion. My requirement is such that we cannot simply display white, but rather green when positive and red when negative.

Thanks,

Daniel

dkmallott
 
Posts: 3
Joined: Wed Dec 10, 2014 9:18 pm

Mon Dec 15, 2014 3:57 am

Dear Daniel,

The next version can implement your requirement. We will inform you when it is released.

Best wishes,
Amy
E-iceblue support team
User avatar

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

Mon Dec 15, 2014 2:48 pm

Amy,

Thanks so much. I look forward to that.

In the meantime, we are working around the problem by using two separate series.

Thanks,

Daniel

dkmallott
 
Posts: 3
Joined: Wed Dec 10, 2014 9:18 pm

Fri Mar 20, 2015 2:47 am

Hello,

Sorry for long silence, the issue that the inversion color has been resolved, you can download the newest hotfix(Spire.Presentation2.2.17) from the following link and try.
http://www.e-iceblue.com/Download/downl ... t-now.html
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

Tue Mar 24, 2015 8:27 am

Hello,

Did Spire.Presentation2.2.17 resolve your issue?
Thanks for your feedback.

Best wishes,
Amy
E-iceblue support team
User avatar

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

Return to Spire.Presentation