Setting line chart to start with Zero

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Paul1309
Posts: 4
Joined: Mon Aug 08, 2016 8:06 am
antibot: No, of course not.

Setting line chart to start with Zero

Post by Paul1309 » Mon Aug 08, 2016 8:11 am

Hello

i have created an JFreeChart object with

JFreeChart LineChartObjectDistSum=ChartFactory.createLineChart

and everythign works fine - but just one smaller thing.
The final chart doesnt start on (0,0) but on (x,0) so the line
is moved to right .

Soo is there a way to move it to the left?

thx

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Setting line chart to start with Zero

Post by paradoxoff » Mon Aug 08, 2016 12:23 pm

The signature of the ChartFactory methoda that you are using indicates that you are using a CategoryPlot. With the default line renderer for a CategoryPlot, the line that is connecting the data points will start in the "center" of the category. I do not know a simple way to change that.

Paul1309
Posts: 4
Joined: Mon Aug 08, 2016 8:06 am
antibot: No, of course not.

Re: Setting line chart to start with Zero

Post by Paul1309 » Mon Aug 08, 2016 2:01 pm

Hello

yes you are right. I am using the following

CategoryPlot plotDistSum= (CategoryPlot) LineChartObjectDistSum.getPlot();
plotDistSum.setBackgroundPaint(Color.white);
plotDistSum.setRangeGridlinePaint(Color.black);
plotDistSum.getRenderer().setSeriesPaint(0, Color.BLACK);


i would like to add a picture but doesnt know how to do here

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Setting line chart to start with Zero

Post by paradoxoff » Mon Aug 08, 2016 3:35 pm

Paul1309 wrote:i would like to add a picture but doesnt know how to do here
An image is not needed. As explained above, the line renderer of a CategoryPlot will never start at the left edge of the plot. It will always connect the centers of the categories. Eventually (if you have multiple series and the useSeriesOffset falg is set to true), the line segments are slightly shifted away from the center, but never completely to the start or end of a category.

Paul1309
Posts: 4
Joined: Mon Aug 08, 2016 8:06 am
antibot: No, of course not.

Re: Setting line chart to start with Zero

Post by Paul1309 » Mon Aug 08, 2016 4:56 pm

many thanks for you reply.
is there another way how to code it to get what i want?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Setting line chart to start with Zero

Post by paradoxoff » Tue Aug 09, 2016 12:10 pm

Only by creating a new renderer.
You could extend org.jfree.chart.renderer.category.LineAndShapeRenderer and override the drawItem method. In your overriden method, replace the occurences of domainAxis.getCategoryMiddle with domainAxis.getCategoryStart.
But your requirement sounds a bit strange to me. I have the impression that you might be better off with an XYPlot. Maybe you can upload an image of your and post a link here.

Paul1309
Posts: 4
Joined: Mon Aug 08, 2016 8:06 am
antibot: No, of course not.

Re: Setting line chart to start with Zero

Post by Paul1309 » Tue Aug 09, 2016 12:34 pm

ok thanks,
i will try a XYPlot and maybe it will fit my needs

Thanks for your help

trollini
Posts: 1
Joined: Sat Aug 13, 2016 5:50 am
antibot: No, of course not.

Re: Setting line chart to start with Zero

Post by trollini » Sat Aug 13, 2016 5:52 am

If i remember well it might be a way but i cant remember, i am pretty sure i saw it like 3 months ago or so.. i will look up for it
peliculas por mega

Greetings

Locked