Setting Pie Chart Sector Colors (URGENT!)

Hi Admin,

We are going to purchase a license of Aspose.Slides for Java. But before we will do that, I nee you to help me on something.

I have a code that will modify the data of a pie chart. But I cant set colors to pie chart sector. Please give me the full code in java to do this. I have 7 sectors in a pie chart each is in different color.

Please reply asap because this is urgent.

Thanks,
Jonah

Hi Jonah,


Thanks for your interest in Aspose.Slides.

I like to share that Aspose.Slides for Java does allow you to set the pie chart sector color. Please visit this documentation link for your kind reference. Please share with us, if any further help is needed in this regard.

Many Thanks,

Hi,

No, I already browse the documentation but I count find a full code of what I need. Please give me a full code as it will really solve my problem.

Thanks!

Hi Jonah,


I am sorry for your inconvenience. I have added the sample code for your convenience over this documentation link. Please share, if I may help you further in this regard.

Many Thanks,

Thanks so much… I will use that and see how it works.

Hi,

I got it working now.

Another issue is that how can I format the piechart label to currency in $X,XXX… Please help.

Thanks,
Jonah

Hi Jonah,

I have tried to understand the requirement shared by you. Can you please share the requirement in the form of sample presentation or snapshot so that I may help you further. Please visit this documentation link whereby I have shared the sample application to format chart. I have also shared the example to set the number format as well. I am hopeful that the shared link will be helpful to you.

Many Thanks,

Hi,



The documentation doesnt solve my problem. I need to formal a pie chart label in currency. Please give me the full code to do that.



Thanks,

Jonah

Hi Jonah,


Please use the following sample code to serve the purpose. Please share, if I may help you any further in this regard.

public static void addPieChart()
{
//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx();

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

// Add chart with default data
ChartEx chart = sld.getShapes().addChart(ChartTypeEx.Pie, 100, 100, 400, 400);

//Setting chart Title
chart.getChartTitle().getText().setText( “Sample Title”);
chart.getChartTitle().getText().setCenterText(true);
chart.getChartTitle().setHeight(20);
chart.hasTitle(true);
//Set first series to Show Values
chart.getChartData().getSeries().get_Item(0).getLabels().setShowValue(true);

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

//Getting the chart data worksheet
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory();

//Delete default generated series and categories

chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();

//Adding new categories
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, “First Qtr”));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, “2nd Qtr”));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, “3rd Qtr”));

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

//Accessing added series
ChartSeriesEx series = chart.getChartData().getSeries().get_Item(Id);

//Now populating series data
series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

//Adding new points and setting sector color
series.isColorVaried(true);
ChartPointEx point = new ChartPointEx(series);
point.setIndex(0);
point.getFormat().getFill().setFillType(FillTypeEx.Solid);
point.getFormat().getFill().getSolidFillColor().setPresetColor(com.aspose.slides.PresetColorEx.Cyan);
//Setting Sector border
point.getFormat().getLine().getFillFormat().setFillType(FillTypeEx.Solid);
point.getFormat().getLine().getFillFormat().getSolidFillColor().setPresetColor(com.aspose.slides.PresetColorEx.Gray);
point.getFormat().getLine().setWidth(3.0);
point.getFormat().getLine().setStyle(LineStyleEx.ThinThick);
point.getFormat().getLine().setDashStyle(LineDashStyleEx.DashDot);

ChartPointEx point1 = new ChartPointEx(series);
point1.setIndex(1);
point1.getFormat().getFill().setFillType(FillTypeEx.Solid);
point1.getFormat().getFill().getSolidFillColor().setPresetColor(com.aspose.slides.PresetColorEx.Brown);

//Setting Sector border
point1.getFormat().getLine().getFillFormat().getSolidFillColor().setPresetColor(com.aspose.slides.PresetColorEx.Blue);
point1.getFormat().getLine().setWidth( 3.0);
point1.getFormat().getLine().setStyle (LineStyleEx.Single);
point1.getFormat().getLine().setDashStyle(LineDashStyleEx.LargeDashDot);

ChartPointEx point2 = new ChartPointEx(series);
point2.setIndex(2);
point2.getFormat().getFill().setFillType(FillTypeEx.Solid);
point2.getFormat().getFill().getSolidFillColor().setPresetColor(com.aspose.slides.PresetColorEx.Coral);

//Setting Sector border
point2.getFormat().getLine().getFillFormat().setFillType(FillTypeEx.Solid);
point2.getFormat().getLine().getFillFormat().getSolidFillColor().setPresetColor(com.aspose.slides.PresetColorEx.Red);
point2.getFormat().getLine().setWidth(2.0);
point2.getFormat().getLine().setStyle(LineStyleEx.ThinThin);
point2.getFormat().getLine().setDashStyle(LineDashStyleEx.LargeDashDotDot);

//Adding Series Points
series.getPoints().add(point);
series.getPoints().add(point1);
series.getPoints().add(point2);

series.getLabels().setLinkedSource(false);
series.getLabels().setShowCategoryName(false);
series.getLabels().setShowSeriesName(false);
series.getLabels().setShowPercentage(false);
series.getLabels().setShowValue(true);

series.getLabels().setNumberFormat("$#,##0.00");
series.getLabels().setLinkedSource(false);


//Showing Leader Lines for Chart
series.getLabels().setShowLeaderLines(true);

//Setting Rotation Angle for Pie Chart Sectors
chart.getChartData().getSeries().get_Item(0).setFirstSliceAngle(180);

// Save presentation with chart
pres.write(“D:\Aspose Data\AsposeChart.pptx”);
}

Many Thanks,

Hi,

Please help me on how to change the color of piechart label to white.

Thanks!

Hi Jonah,


Please add the following code snippet in your sample code where you are addressing labels.

series.getLabels().getFormat().getFill().setFillType(FillTypeEx.Solid);
series.getLabels().getFormat().getFill().getSolidFillColor().setColor(Color.WHITE);


Many Thanks,

Hi,

This doesnt solve the problem. It change the background color of the text not the font color. All I need is a code to change the font color.

Thanks!

Hi Jonah,


Please try using following sample code to set the text color on your end for series labels.

series.getLabels().getTextProperties().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().getFillFormat().setFillType(FillTypeEx.Solid);
series.getLabels().getTextProperties().getParagraphs().get_Item(0).getParagraphFormat().getDefaultPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.WHITE);


Many Thanks,