How to create Radar chart (Java)

Hi Team,

could you please post a simple radar chart example using aspose slide in java.

Many thanks in advance.

Thanks,
Thilak Babu

@Thilakbabu,

I have observed your requirements and have created an issue with ID SLIDESJAVA-38060 in our issue tracking system as support request to provide and add example for Radar chart in documentation. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

Thanks Fayyaz for quick reply.

Could you please let me know when can I get an example ?

Thanks

@Thilakbabu,

Is it possible, if you may please share the desired chart in the form of PowerPoint presentation that you want to generate using Aspose.Slides. We will try to provide respective example to you in this regard.

Hi @mudassir.fayyaz,

Please find below the sample ppt screenshot.

image.png (35.9 KB)

hope this helps.

Many thanks!

-Thilak

@Thilakbabu,

I suggest you to please try using following sample code on your end. You may alter the series data points value as per your requirements.

public static void TestRadarChart()
{
    
    String path="C:\\Aspose Data\\";

    Presentation pres = new Presentation();
    // Access first slide
    ISlide sld = pres.getSlides().get_Item(0);
    IChart ichart = sld.getShapes().addChart(ChartType.Radar, 0, 0, 500, 500);
    // Setting the index of chart data sheet
int defaultWorksheetIndex = 0;

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

    
    float x=ichart.getPlotArea().getX();
    float y=ichart.getPlotArea().getY();
    float width=ichart.getPlotArea().getWidth();
    float height=ichart.getPlotArea().getHeight();
    
    ichart.getChartData().getCategories().clear();
    ichart.getChartData().getSeries().clear();
    
    ichart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
    ichart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 3"));
    ichart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 5"));
  	ichart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 4, 0, "Caetegoty 7"));
    ichart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 5, 0, "Caetegoty 11"));
 
    // Adding new series
    ichart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"),ichart.getType());
    ichart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"),ichart.getType());

    // Now populating series data
    IChartSeries series = ichart.getChartData().getSeries().get_Item(0);

    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 4, 1, 15));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 5, 1, 25));

    // Now populating series data
    series = ichart.getChartData().getSeries().get_Item(1);

    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 10));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 20));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 13));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 4, 2, 20));
    series.getDataPoints().addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 5, 2, 27));
  
    ichart.getPlotArea().setX(0);
    ichart.getPlotArea().setY(0);
    
    ichart.getPlotArea().setHeight(2);
    ichart.getPlotArea().setHeight(2);
 
    pres.save(path+"RadarChart.Pptx", SaveFormat.Pptx);

}

Hi @mudassir.fayyaz,

Thanks that snippet helped me.

Could you please provide some snippet on showing how to set the series color for simple RADAR chart in java ?

Thanks.

@Thilakbabu,

I suggest you to please try using following sample code.

    series.getFormat().getFill().setFillType(FillType.Solid);
    series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.YELLOW);

Thanks @mudassir.fayyaz for your reply!

But I am using the same code but the color is not getting applied.

PFB the code which I am using.

public class RadarChartExample {
public static void main(String[] args) {
Presentation pres = new Presentation();
ISlide sld = pres.getSlides().get_Item(0);
IChart chart = sld.getShapes().addChart(com.aspose.slides.ChartType.Radar, 50, 100, 550, 300);
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat()
.setShowValue(true);
int defaultWorksheetIndex = 0;

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

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

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

int s = chart.getChartData().getSeries().size();
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());

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"));
chart.getChartData().getCategories()
    .add(fact.getCell(defaultWorksheetIndex, 4, 0, "Caetegoty 4"));
chart.getChartData().getCategories()
    .add(fact.getCell(defaultWorksheetIndex, 5, 0, "Caetegoty 5"));
chart.getChartData().getCategories()
    .add(fact.getCell(defaultWorksheetIndex, 6, 0, "Caetegoty 6"));

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

series.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20));

series.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50));

series.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30));

series.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 4, 1, 25));

series.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 5, 1, 35));

series.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 6, 1, 40));


// Setting fill color for series

series.getFormat().getFill().setFillType(FillType.Solid);

**series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.YELLOW);**

IChartSeries series1 = chart.getChartData().getSeries().get_Item(1);

series1.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30));

series1.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10));

series1.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60));

series1.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 4, 2, 25));

series1.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 5, 2, 45));

series1.getDataPoints()
    .addDataPointForRadarSeries(fact.getCell(defaultWorksheetIndex, 6, 2, 15));
	
series1.getFormat().getFill().setFillType(FillType.Solid);

**series1.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.magenta);**

pres.save("radar_chart_6.pptx", com.aspose.slides.SaveFormat.Pptx);

}
}

output ppt -

image.png (40.8 KB)

Could you please tell me what’s causing to get the default colors instead of the colors which I have set for the series ?

Thanks.

@Thilakbabu,

I am sorry for your inconvenience. I have observed the image shared by you. The radar chart has lines in it. Can you please try using following on your end.

    series.getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
    series.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(java.awt.Color.YELLOW);

It worked. Thanks a lot @mudassir.fayyaz

@Thilakbabu,

It’s good to hear that things are working on your end.