PolarLine Chart not showing series item labels

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
thegame90
Posts: 5
Joined: Mon Aug 26, 2019 8:04 pm
antibot: No, of course not.

PolarLine Chart not showing series item labels

Post by thegame90 » Mon Sep 09, 2019 8:14 pm

I am using JFreeChart v1.5.0 to create a PolarLine Chart. I added the following code to display the series item labels but I could not see any labels in the chart output.

Code: Select all

public class PolarLineDemo extends ApplicationFrame {
public PolarLineDemo(String title) {
    super(title);
    final XYDataset dataset = getXYDataset();
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 500));
    setContentPane(chartPanel);
}

private XYDataset getXYDataset() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(20, 45);
    series1.add(145, 120);
    series1.add(90, 150);
    dataset.addSeries(series1);
    return dataset;
}

private JFreeChart createChart(final XYDataset dataset) {
    JFreeChart chart = ChartFactory.createPolarChart("Polar Line Chart",dataset,true,true,false);
    PolarPlot plot = (PolarPlot)chart.getPlot();
    DefaultPolarItemRenderer renderer = (DefaultPolarItemRenderer) plot.getRenderer();
    NumberAxis rangeAxis = (NumberAxis) plot.getAxis();

    //set gridlines for category
    plot.setAngleGridlinesVisible(true);
    plot.setAngleLabelsVisible(true);
    //set gridlines for series
    plot.setRadiusGridlinesVisible(true);
    plot.setRadiusMinorGridlinesVisible(false);

    //series range setter
    rangeAxis.setRange(0, 240.0);
    //series label visible
    rangeAxis.setTickLabelsVisible(true);
    rangeAxis.setTickUnit(new NumberTickUnit(40.0));

    //Marker shape visible
    renderer.setShapesVisible(true);
    //set marker shape, line color and width
    Shape triangle = ShapeUtilities.createDownTriangle(5);
    renderer.setSeriesShape(0, triangle, true);
    renderer.setSeriesStroke(0, new BasicStroke(2));
    [b]//show series item labels -- This is not working.[/b]
    renderer.setSeriesItemLabelsVisible(0, true);
    return chart;
}

public static void main(String[] args) {
    PolarLineDemo polarLineDemo = new PolarLineDemo("Polar Line Chart");
    polarLineDemo.setSize(500, 500);
    RefineryUtilities.centerFrameOnScreen(polarLineDemo);
    polarLineDemo.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    polarLineDemo.setVisible(true);
}
Not sure if I am invoking the correct API to show the series item labels. Any guidance would be of great help.

John Matthews
Posts: 482
Joined: Wed Sep 12, 2007 3:18 pm

Re: PolarLine Chart not showing series item labels

Post by John Matthews » Tue Sep 10, 2019 4:30 am

Cross-posted here.

thegame90
Posts: 5
Joined: Mon Aug 26, 2019 8:04 pm
antibot: No, of course not.

Re: PolarLine Chart not showing series item labels

Post by thegame90 » Mon Sep 16, 2019 4:21 pm

How can I achieve the item labels? Will there be any support for it in the future? Currently, I do notice there is no API support for it in the current version 1.5.0.

Post Reply