Hi Aspose Team,
I want to write a program to change the border color from format chart series.
Could you please help me for writing the program for this.
I am attaching here image for reference.
image.png (157.4 KB)
Thanks for the screenshot.
See the sample code for your reference. The code snippet creates a Bubble chart and sets the border color of data points using format chart series.
e.g.,
Sample code:
Presentation presentation = new Presentation();
//Create a slide to add the chart
ISlide slide = presentation.getSlides().get_Item(0);
//Add a Bubble chart to the slide
IChart chart = slide.getShapes().addChart(ChartType.Bubble, 100, 100, 600, 400);
//Get the chart's data sheet
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
//Set data for the bubble chart
double[] xValues = {1, 2, 3, 4, 5}; // X axis values
double[] yValues = {10, 20, 30, 40, 50}; // Y axis values
double[] zValues = {5, 10, 15, 20, 25}; // Z values (size of the bubbles)
//Create the first (and only) series for the chart
IChartSeries series = chart.getChartData().getSeries().add(workbook.getCell(0, 1, 0, "red series"), ChartType.Bubble);
//Add data points to the series
for (int i = 0; i < 5; i++) {
IChartDataPoint dp = series.getDataPoints().addDataPointForBubbleSeries(
workbook.getCell(0, 1, i + 1, xValues[i]),
workbook.getCell(0, 2, i + 1, yValues[i]),
workbook.getCell(0, 3, i + 1, zValues[i])
);
}
//Set border color for the first series data points
for (IChartDataPoint dataPoint : series.getDataPoints()) {
dataPoint.getFormat().getLine().getFillFormat().setFillType( FillType.Solid);
dataPoint.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GREEN);
}
//Save the presentation to a file
try {
presentation.save("d:\\files\\BubbleChart.pptx", com.aspose.slides.SaveFormat.Pptx);
System.out.println("Presentation created successfully!");
} catch (Exception e) {
System.out.println("Error saving presentation: " + e.getMessage());
}
Hope, this helps a bit.
@amjad.sahi … Thanks for sharing the code but the issue did not resolve it.
I don’t see border applied in the series. The above code you applied for each data points.
Actual PPT which I generated above code:
image.png (74.2 KB)
Expected PPT:
image.png (92.5 KB)
I am attaching here for expected PPT file
BubbleChart.zip (33.1 KB)
Thank you for sharing the screenshots and the sample PowerPoint presentation file with the chart you want.
I have looked into your requirements, and it appears that when you set the border color for a data series in the chart, it does not automatically apply to the corresponding legend entries, even though the border color is correctly applied to the data points of the series. I searched for relevant APIs to manually set borders for the legend entries but couldn’t find any. I will continue to investigate this issue and will create a ticket in our database to address your concerns. We apologize for any inconvenience this may have caused.
@manikandan1234,
To change the border color and width of all data points of a Bubble chart, you should access the ILineFormat interface from a series and set the properties.
Please try using the following code example:
Presentation presentation = new Presentation();
ISlide slide = presentation.getSlides().get_Item(0);
IChart chart = slide.getShapes().addChart(ChartType.Bubble, 100, 100, 600, 400);
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();
double[] xValues = {1, 2, 3, 4, 5};
double[] yValues = {10, 20, 30, 40, 50};
double[] zValues = {5, 10, 15, 20, 25};
IChartDataCell dataCell = workbook.getCell(0, 1, 0, "red series");
IChartSeries series = chart.getChartData().getSeries().add(dataCell, ChartType.Bubble);
for (int i = 0; i < xValues.length; i++) {
IChartDataPoint dp = series.getDataPoints().addDataPointForBubbleSeries(
workbook.getCell(0, 1, i + 1, xValues[i]),
workbook.getCell(0, 2, i + 1, yValues[i]),
workbook.getCell(0, 3, i + 1, zValues[i])
);
}
ILineFormat bubbleBorderFormat = series.getFormat().getLine();
bubbleBorderFormat.getFillFormat().setFillType( FillType.Solid);
bubbleBorderFormat.getFillFormat().getSolidFillColor().setColor(Color.GREEN);
bubbleBorderFormat.setWidth(3);
presentation.save("output.pptx", com.aspose.slides.SaveFormat.Pptx);
presentation.dispose();
The result:
output.zip (31.8 KB)
More examples:
Create or Update PowerPoint Presentation Charts in Java|Aspose.Slides Documentation
Chart Formatting|Aspose.Slides Documentation