We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Wrong colors of chart series

Hi!

I am trying to add chart into PowerPoint slide, see code in attachment. As you can see on attached screenshot, all series have the same color (orange). But I have specified 6 color accents, so it doesn’t work. What I am doing wrong (if I am)? Does there is any workaround?

(I am using Aspose.Slides for Java, version 7.5.0.0)


Hi Nikolay,


Thanks for inquiring Aspose.Slides.

I have observed the sample code shared. Actually, you need to set the individual series color to sere the purpose. However, you are not setting any color for series and therefore getting single color for all of them. Please try using the sample code shared over this link for your kind reference and share with us if the issue is still incurring on your end.

Many Thanks,

Hi Mudassir!

As you can see in my code, I am using color scheme to set chart colors:

ColorSchemeEx colorScheme = item.getTheme().getColorScheme();
colorScheme.getAccent1().setColor( new Color( 255, 98, 9 ) );
colorScheme.getAccent2().setColor( new Color( 255, 5, 0 ) );
colorScheme.getAccent3().setColor( new Color( 255, 10, 100 ) );
colorScheme.getAccent4().setColor( new Color( 0, 40, 186 ) );
colorScheme.getAccent5().setColor( new Color( 0, 247, 255 ) );
colorScheme.getAccent6().setColor( new Color( 0, 115, 255 ) );


I cannot use direct color setting by two reasons:

1) When I use color accents, I need to set only 6 colors, and when series more that 6, PowerPoint will generate all rest colors automatically (see screen-1.png)

2) I need to use chart styles for charts. But, when colors are set manually, some styles doesn’t work (for example, style 18, see screen-2.png). Also, user cannot change chart style without breaking coloring.

Hi Nikolay,


I have observed the requirement shared by you and agree with you that Aspose.Slides supports setting six Accent colors in ColorSchemeEx. However, your requirement has turned out to be having more than six series. At present, the available option in this regard is to set the manual color for series as shared by me in my very first post of this thread. Secondly, I have created an issue with ID SLIDESJAVA-34000 as enhancement to further investigate the requirements shared by you. This thread has been linked with the issue so that you may be automatically notified once the issue will be addressed and resolved.

We are sorry for your inconvenience,

Hi Nikolay,

Our development team has investigated the issue on their end. Actually, the ColorScheme supports 6 Accents and other colors are generated by PowerPoint.Please try using the following sample code on your end by using Aspose.Slides for Java 14.9.0…


final int worksheetNum = 0;

Presentation pres = new Presentation();
ISlide slide = pres.getSlides().get_Item(0);

IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500);
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();

chart.setStyle(1);
chart.setWidth((float) pres.getSlideSize().getSize().getWidth());
chart.setHeight((float) pres.getSlideSize().getSize().getHeight());

IColorScheme colorScheme = pres.getMasterTheme().getColorScheme();
colorScheme.getAccent1().setColor( new Color( 255, 98, 9 ) );
colorScheme.getAccent2().setColor( new Color( 255, 5, 0 ) );
colorScheme.getAccent3().setColor( new Color( 255, 10, 100 ) );
colorScheme.getAccent4().setColor( new Color( 0, 40, 186 ) );
colorScheme.getAccent5().setColor( new Color( 0, 247, 255 ) );
colorScheme.getAccent6().setColor( new Color( 0, 115, 255 ) );

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

String[] categoriesArr = {“Cat 1”};
String[] seriesArr = {“Series 1”, “Series 2”, “Series 3”, “Series 4”, “Series 5”, “Series 6”,
“Series 7”, “Series 8”, “Series 9”, “Series 10”, “Series 11”, “Series 12”};

fact.getCell( 0,0,0 ).setValue( 0 );

// Add series
for( int i = 0; i < seriesArr.length; i++ )
{
String series = seriesArr[i];
chart.getChartData().getSeries().add(fact.getCell( worksheetNum, 0, i+1, series), chart.getType());
}

// Add categories
for( int i = 0; i < categoriesArr.length; i++ )
{
String cat = categoriesArr[i];
chart.getChartData().getCategories().add(fact.getCell(worksheetNum, i+1, 0, cat));
}


// Fill values
for( int i = 0; i < seriesArr.length; i++ )
{
IChartSeries series = chart.getChartData().getSeries().get_Item( i );
for( int j = 0; j < categoriesArr.length; j++ )
{
series.getDataPoints().addDataPointForBarSeries(fact.getCell(worksheetNum, j+1, i+1, 1 + 100 * Math.random()));
}
}

pres.save( “out.pptx”, SaveFormat.Pptx );

Many Thanks,

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


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