How to customize XYLineChart with JFreeChart - java

I have an XYLineChart generated from an XYSeriesCollection.
The chart looks like that:
I would like to customize it in order to put into evidence the domain axis entry of the dataset, using some dots (or circles, or squares). It should look like:
Has JFreeChart some feature do achieve that result?
Any suggestion?

Yep: see the image in http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/category/LineAndShapeRenderer.html, and unless I'm wrong you can do it using this.

Just use this constructor for the renderer:
LineAndShapeRenderer(boolean lines, boolean shapes)
and set both values to true.

Related

Is there a way to set individual label link colors in JFreeChart's PiePlot?

I see that I can use setLabelLinkPaint() to universally apply a color to all label links, but I'm looking to set each individual label link to a different color. Is there a way to do this?
It looks like for now the most straightforward way to approach this problem is to subclass the PiePlot class and override the drawRightLabel and drawLeftLabel methods. In my case, I needed to have the label link color match the corresponding pie chart section, so in my overridden methods I set g2.setPaint(getSectionPaint(record.getKey())).
My advice to anyone trying to do something similar is to watch out for casting errors if casting from a JFreeChart chart object. You will likely have to additionally subclass ChartFactory and modify it so that it uses your subclassed PiePlot and not the original one.

How can I give two different styles for the same series of a line chart?

I would like to use JavaFX to assemble a line chart such that when there is no data to plot in a series, the space is empty. Something like that:
Chart
Notice that I would like to keep myself in the same series, just by changing your style in one part. But any help is welcome. Thank you.

JFreeChart grid base axis

I'm using JFreeChart 1.0.14 in Swing application.
I have chart with multiple Y-Axis and I want to change source Axis for chart grid lines. Now them always base on one axis, even if I hide it.
I know there are few similar questions but they are old and I wonder if solution exists now.
If it doesn't what is the best workaround in this task?
For example:
http://www.jfree.org/phpBB2/viewtopic.php?f=3&t=27885&sid=c4c609f3809d29a46e3e2bbccfac361e
There is still no way to do it natively unfortunately.
I was suggested to override XYPlot's drawRangeGridLines method, but I decided to go another way: to make it works you only need to change axis order because grid lines always depend on 0th axis (and its dataset). Make sure your axis has 0th index in plot axis collection.
NumberAxis axis = new NumberAxis(name);
plot.setRangeAxis(0, axis);
I think it's easiest way at this moment.

JFreechart, Line Chart with filled Areas

I am trying to create chart like below:
While I've almost achieved everything by simply creating a line chart and customizing shape/paint for Renderer, I can't seem to find a way to fill the areas under the series line.
Any clues, how can I do this?
You could create your chart with a StackedXYAreaRenderer. Specify AREA_AND_SHAPES in the constructor and enable outlines. See the ChartFactory code for createStackedXYAreaChart() as an example.
StackedXYAreaRenderer r = new StackedXYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);
r.setOutline(true);
Given a renderer, you can set the outline paint and stroke as desired.

How to display values within pie chart sector

I am using JFreeChart to create pie charts. Values are displayed outside pie chart sectors as labels. I want to display the values within the pie sectors. How can I achieve this. Please can any one help me?
Use setSimpleLabels(), as shown below; org.jfree.chart.demo.PieChartDemo1 is a good starting point.
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSimpleLabels(true);
If you are using createPieChart3D to create Pie chart, following URL will be helpful to you.
http://www.java2s.com/Code/Java/Chart/JFreeChartPieChart3DDemo1.htm
What I know is, showing values inside is default feature of the chart. If you're unable to do so it seems that you have changed the default way.

Categories

Resources