'Invert if negative' being set on ChartDataPoint by call to setFillType

I’m setting the colour of data points on a stacked bar chart. In the template PPTX, ‘Invert if negative’ is not set on the series or any of the data points. After clearing the series in code, and adding new points using ChartSeries.addPointForBarSeries, I’m calling:


ChartDataPoint.getFormat().getFill().getSolidFillColor().setColor(newJavaAwtColor)
ChartDataPoint.getFormat().getFill().setFillType(FillType.Solid)

After a process of elimination, it’s the call to setFillType that’s causing the invert if negative flag to be set on the chart data point in the resulting PPTX. If I omit the call, the flag isn’t set but the new colour isn’t used.

‘Vary color by point’ is checked in the template PPTX and the resulting one because I’m setting the colour of each point based on certain value criteria.

/* Sample code */

Presentation pres = new Presentation("testing.pptx");

//Access first slide

ISlide sld = pres.getSlides().get_Item(0);

IChart chart = null;

for (int i = 0; i < sld.getShapes().size(); i++)

{

if (sld.getShapes().get_Item(i).getAlternativeText().compareTo("testchart") == 0)

chart = (IChart) sld.getShapes().get_Item(i);

}

IChartSeries series = chart.getChartData().getSeries().get_Item(0);

series.getDataPoints().clear();

int defaultWorksheetIndex = 0;

IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

IChartDataPoint p1 = series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, -15));

IChartDataPoint p2 = series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));

// Comment out these two lines and the 'Invert if negative' checkbox will get set by Aspose.Slides

IFillFormat fill = p1.getFormat().getFill();

fill.getSolidFillColor().setColor(Color.RED);

fill.setFillType(FillType.Solid);

//Save presentation with chart

pres.save("output.pptx", SaveFormat.Pptx);

Hi George,

I have observed the requirements shared by you and have worked over it using Aspose.Slides for Java 14.5.0 on my end. I have not been able to observe any issue on my end while setting fill type for chart series data point and getInvertIfNegative() method returns False as a default. I have used the sample code shared over this documentation link. Can you please try using the code shared over specified link. Also, in your code I have observed that you are first setting the color then setting the fill type. You need to first set the fill type and then Color. For your kind reference, I have attached the generated presentation as well.

//Instantiate Presentation class that represents PPTX file//Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();

//Access first slide
ISlide sld = pres.getSlides().get_Item(0);

// Add chart with default data
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);

//Setting chart Title
// chart.ChartTitle.TextFrameForOverriding.Text = “Sample Title”;
chart.getChartTitle().addTextFrameForOverriding(“Sample Title”);
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True);
chart.getChartTitle().setHeight (20);
chart.hasTitle(true);

//Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue( true);

//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

//Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();

//Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
int s = chart.getChartData().getSeries().size();
s = chart.getChartData().getCategories().size();

//Adding new series
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, “Series 1”), chart.getType());
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, “Series 2”), chart.getType());

//Adding new categories
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, “Caetegoty 1”));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, “Caetegoty 2”));
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, “Caetegoty 3”));

//Take first chart series
IChartSeries series = chart.getChartData().getSeries().get_Item(0);

//Now populating series data

series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, -50));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

//Setting fill color for series
series.getFormat().getFill().setFillType(FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor (Color.RED);
boolean invertifNeg=series.getInvertIfNegative();


//Take second chart series
series = chart.getChartData().getSeries().get_Item(1);

//Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, -60));

//Setting fill color for series
series.getFormat().getFill().setFillType (FillType.Solid);
series.getFormat().getFill().getSolidFillColor().setColor(Color.GREEN);

//create custom labels for each of categories for new series
//first label will be show Category name
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel();
lbl.getDataLabelFormat().setShowCategoryName(true);

lbl = series.getDataPoints().get_Item(1).getLabel();
lbl.getDataLabelFormat().setShowSeriesName(true);

//Show value for third label
lbl = series.getDataPoints().get_Item(2).getLabel();
lbl.getDataLabelFormat().setShowValue(true);
lbl.getDataLabelFormat().setShowSeriesName(true);
lbl.getDataLabelFormat().setSeparator (“/”);

//Save presentation with chart
pres.save(“D:\Aspose Data\AsposeChart.pptx”, SaveFormat.Pptx);

Many Thanks,

I’m setting the fill properties of the chart data point - NOT the series. I’ve got some code and a template PPTX that shows the problem. I have edited my original post with the code and template. After running the example, look at the properties of the red chart data POINT (NOT the series) and you’ll see that the ‘Invert if negative’ checkbox is checked. It doesn’t get if you comment out the two lines of code that set the fill properties.


Hope this better shows the problem.

Hi George,

I have observed the requirement shared by you and request you to please share the sample java application, source template, generated presentation and desired output presentation. I will investigate the issue further on my end in light of shared information to help you out.

Many Thanks,

I have added all the information to the original post.


The template is testing.pptx
The output of the code is output.pptx
The desired output is desiredoutput.pptx

In output.pptx, notice that the bar that should be red is actually white. This is because the ‘Invert if negative’ checkbox gets set on the data point after the code calls setFillType. It should not get changed and should be the same as it is in the template file. The desiredoutput.pptx file shows this.

Hi George,

I have observed the presentation files shared by you and have been able to observe the issue specified. It seems to be an issue in Aspose.Slides. An issue with ID SLIDESJAVA-34488 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

We are sorry for your inconvenience,

Thanks for confirming the bug. Do you have an idea of when a fix will be available? It’s causing me problems because once the presentation is built, if I remove the ‘Invert if negative’ flag by hand in Powerpoint, it can’t be saved and Powerpoint says there is a major problem and may become unstable.

Hi George,

I have verified from our issue tracking system and regret to share that the issue is still pending for investigation in queue. I will really appreciate your patience till the time our development team schedule and investigate the issue and some feedback is shared by them.

Many Thanks,

Any update on this? We’re still waiting for a fix and are still having to update the ‘Invert if negative’ flag after generating reports before sending them to customers.

Hi George,

I have verified from our issue tracking system and regret to share that the issue is still unresolved. I have discussed the issue with our development tam and they have scheduled the issue for investigation and resolution during Week 06/2015. We will share the feedback with you as soon as the investigation will be completed by our development team.

We are sorry for your inconvenience,

Any update on this? I am facing the same issue where InvertifNegative option inverts the color of the data points. Although I set it to false negative values are shown in white color. Is there a way to set the inverted fill color also to the required color?


Please help this is really urgent.

There was a fix for this in aspose.slides for .Net 7.1.0.


Refer the below link
Bar chart format lost when saved

Coul;d you please check if the patch is applied to apose.slides 14.x versions also?

Tthanks,
Priya

Hi Priya,

I like to share that the issue is unresolved and has some internal blocking issue as source. The blocking issue has been scheduled for investigation and resolution during Week 06/2015. Once the issue concerned blocking issue will be fixed then the ticket associated with this thread will get resolved. Unfortunately, there is no workaround that I can offer you at this time.We will share the feedback with you as soon as the issue will be resolved.

Many Thanks,

Any update on this?

Hi Priya,

I am afraid, there is no update regarding your reported issue at the moment. I have requested the development team to share the ETA once they are done with their investigation. As soon as the information is shared, we will update you via this forum thread.

Thanks & Regards,

The issues you have found earlier (filed as SLIDESJAVA-34488) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Team,
If I set InvertIfNegative to false, the font properties that I had set for the datapoint earlier is all lost. Could you please let me know if this can be avoided?

Ex: DataPoint Label color was set to white whereas after setting Series.InvertIfNegative = false, the font color becomes black again.

FYI : I tried adding this Series.InvertIfNegative = false line before setting the data point color. It still does not work. Please find the exported file.

QVExport (5).zip (39.6 KB)

Below is the code FYR

chartSerie.InvertIfNegative = false;
for (int dataSliceIndex = 0; dataSliceIndex < dataSlice.Count(); dataSliceIndex++)
{
var serieData = dataSlice.ElementAt(dataSliceIndex);
var dataPoint = chartSerie.DataPoints.AddDataPointForBarSeries(dataWorkbook.GetCell(0, dataSliceIndex + 1, serieIndex + 1, serieData));

                chartSerie.Format.Fill.FillType = FillType.Solid;

                chartSerie.Format.Fill.SolidFillColor.Color = SeriesColor[colorIndex];
                if (chartSerie.Chart.Type == ChartType.PercentsStackedBar || chartSerie.Chart.Type == ChartType.PercentsStackedColumn)
                {
                    if (dataSlice.ElementAt(dataSliceIndex) == Setup.NaNValue || dataSlice.ElementAt(dataSliceIndex) == Setup.ZeroValue)
                    {
                        dataPoint.Format.Fill.FillType = FillType.NoFill;
                        //WCC 3769 - In Editable Exports, For Scoreless Categories in Charts, Display Blank Soln. Providing Empty spaces when it is a scoreless category
                        addNATextFrame(dataPoint, (dataSlice.ElementAt(dataSliceIndex) == Setup.NaNValue) ? ResxDataProvider.Get("NAText") : " ");// if it is a stacked graph fill NA only for the first column
                        //else { do nothing - so that the rest of the columns are filled with empty text for stacked graph}
                    }
                }
                else
                {

                    if (dataSlice.ElementAt(dataSliceIndex) == Setup.NaNValue || dataSlice.ElementAt(dataSliceIndex) == Setup.ZeroValue)
                    {
                        
                        addNATextFrame(dataPoint, (dataSlice.ElementAt(dataSliceIndex) == Setup.NaNValue) ? ResxDataProvider.Get("NAText") : " ");// if it is not a stacked graph fill it with NA for each column
                    }

                }
                // font color set to white when the series font color is null
                SetDataLabelDisplay(dataPoint);
                
                if (SeriesFontColor != null)
                {
                    dataPoint.Label.DataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color = SeriesFontColor[colorIndex];
                }
                else
                {
                    var color =  string.Format("#{0}{1}{2}",chartSerie.Format.Fill.SolidFillColor.Color.R.ToString("X2"),chartSerie.Format.Fill.SolidFillColor.Color.G.ToString("X2"),chartSerie.Format.Fill.SolidFillColor.Color.B.ToString("X2"));
                    if (dataPoint.Value.ToDouble() > 0.0)
                        dataPoint.Label.DataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color =
                            ColorHelper.ShouldBeFontBlack(ColorHelper.Parse(color)) ? Color.Black : Color.White;
                    else
                        dataPoint.Label.DataLabelFormat.TextFormat.PortionFormat.FillFormat.SolidFillColor.Color =
                            Color.Black;
                }
                //  });
            }

Hello!!! Can some one please help me on this?

@Priyarav87,

I have observed your comments. Can you please share generated result along with complete sample project. Also please share environment details. We have investigated your issue, please share requested information for further investigation.

This is resolved. Not an issue with aspose. I had to set the data label color for data points. Please close the ticket.