I'm trying to use JFreeChart's Polar Chart inside a JavaFX application. So far I've been able to create the chart and get it to plot the data.
I'm now trying to set the angular tick labels to show -90 degrees to +90 rather than 0 to 360.
Firstly, I've created an XYDataSet of the Angles and Values I need. Then I create a JFreeChart, get the plot from this, set various properties, and then use a ChartViewer to display it. As you can see below.
XYDataSet data = createDataSet();
final JFreeChart chart = ChartFactory.createPolarChart("myTitle",dataSet,false,false,false);
final PolarPlot plot = (PolarPlot) chart.getPlot();
plot.setAngleOffset(0);
plot.setCounterClockwise(true);
final DefaultPolarItemRenderer renderer = (DefaultPolarItemRenderer) plot.getRenderer();
renderer.setShapesVisible(false);
renderer.setConnectFirstAndLastPoint(false);
ChartViewer viewer = new ChartViewer(chart);
I can then add this viewer as a child to a JavaFX pane to be displayed.
After some research online I found a method to override the tick labels of a polar plot using something like below;
final PolarPlot plot = new PolarPlot() {
@Override
protected List refreshAngleTicks(){
List ticks = new ArrayList();
ticks.add(new NumberTick(-90, "-90", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
ticks.add(new NumberTick(-60, "-60", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
ticks.add(new NumberTick(-30, "-30", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
ticks.add(new NumberTick(ZERO, "0", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
ticks.add(new NumberTick(30, "30", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
ticks.add(new NumberTick(60, "60", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
ticks.add(new NumberTick(90, "90", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
return ticks;
}
};
Is there a way I can use this when I am not creating a new PolarPlot, and instead, am getting it from a chart.getPlot() method?
If you need any further information please just ask.
As a side note, if there is an easy way to remove the entire left side of the polar plot (ie have a D shape rather than a full circle, please let me know. Not critical, but while we're on the subject I thought I'd throw it in!)
Thanks in Advance.
Darren.