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

Free Support Forum - aspose.com

Applying different Colors to DataPoint for BubbleChart

Hi! Aspose Team,
I have the requirement where I want to apply different colors for the DataPoint of the same series.
I tried with the snippet code it is changing the color for the dataPoints.
But Legends are coming three for only one Series, It should show only one Legends.
How to configure Legends according to the Series only.
Please let me know how I can achieve it.
I have attached the snippet code.
Workbook workbook = new Workbook();
Worksheet sheet = workbook.getWorksheets().get(0);
//Put data
sheet.getCells().get(0, 0).putValue(“Y Values”);
sheet.getCells().get(0, 1).putValue(2);
sheet.getCells().get(0, 2).putValue(4);
sheet.getCells().get(0, 3).putValue(6);

sheet.getCells().get(1, 0).putValue("Bubble Size");
sheet.getCells().get(1, 1).putValue(1);
sheet.getCells().get(1, 2).putValue(5);
sheet.getCells().get(1, 3).putValue(3);

sheet.getCells().get(2, 0).putValue("X Values");
sheet.getCells().get(2, 1).putValue(1);
sheet.getCells().get(2, 2).putValue(2);
sheet.getCells().get(2, 3).putValue(3);

ChartCollection charts = sheet.getCharts();
//Generate chart
int chartIndex = charts.add(com.aspose.cells.ChartType.BUBBLE, 5, 0, 32, 17);
Chart chart = charts.get(chartIndex);

//Insert series, set bubble size and x values
chart.getNSeries().add("B1:D1", false);
chart.getNSeries().get(0).setBubbleSizes("B2:D2");
chart.getNSeries().get(0).setXValues("B3:D3");

//getting SeriesCollection
SeriesCollection nSeries = chart.getNSeries();

Series series = nSeries.get(0);
series.setName("Test");
FillFormat seriesFillFormat = series.getArea().getFillFormat();
seriesFillFormat.setFillType(FillType.SOLID);
ChartPointCollection points = series.getPoints();
//getting 1st dataPoint from Series
ChartPoint chartPoint1 = points.get(0);
chartPoint1.getArea().getFillFormat().setFillType(com.aspose.cells.FillType.SOLID);
chartPoint1.getArea().setForegroundColor(com.aspose.cells.Color.getGreen());

//getting 1st dataPoint from Series
ChartPoint chartPoint2 = points.get(1);
chartPoint2.getArea().getFillFormat().setFillType(com.aspose.cells.FillType.SOLID);
chartPoint2.getArea().setForegroundColor(com.aspose.cells.Color.getBlue());

//getting 1st dataPoint from Series
ChartPoint chartPoint3 = points.get(2);
chartPoint3.getArea().getFillFormat().setFillType(com.aspose.cells.FillType.SOLID);
chartPoint3.getArea().setForegroundColor(com.aspose.cells.Color.getOrange());

workbook.save("D://AsposeCells//outBubbleChart1.xlsx");

thanks!
Rohan Wankar

@Rohan_Wankar,

Thanks for the sample code segment.

I tried to accomplish the task in MS Excel (create bubble chart having single series and with different color for each bubble/point to reflect single legend entry for the series name) but could not do that. Could you provide your desired chart for reference, you may create your desired chart in MS Excel manually. We will check on how to do it via Aspose.Cells APIs.