Curved Line Charts

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Curved Line Charts

Post by tox0tes » Thu Aug 07, 2008 8:28 am

Is it possible to use curved lines in a line chart instead of jaggedness like so:

Image

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Thu Aug 07, 2008 9:04 am

tox0tes wrote:Is it possible to use curved lines in a line chart instead of jaggedness
Yes, use XYSplineRenderer.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

asd
Posts: 19
Joined: Tue Sep 26, 2006 11:28 pm

Post by asd » Mon Aug 25, 2008 1:20 pm

Hi

I instance an JFreeChart object
JFreeChart chart = ChartFactory.createLineChar(..);

so
chart.getPlot(); returns a CategoryPlot
chart.getXYPlot(); crash with: java.lang.ClassCastException: org.jfree.chart.plot.CategoryPlot cannot be cast to org.jfree.chart.plot.XYPlot

CategoryPlot.setRenderer( new XYSplineRenderer() ); will not work, so how can I use Splinerenderer?

I use version 1.0.9.

Thanks in advance

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Mon Aug 25, 2008 5:19 pm

Try using ChartFactory.createXYLineChart(...) instead.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Post by tox0tes » Tue Aug 26, 2008 2:06 am

Code: Select all

import org.jfree.chart.renderer.xy.XYSplineRenderer;
I am getting
cannot find symbol
symbol : class XYSplineRenderer
location: package org.jfree.chart.renderer.xy

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Tue Aug 26, 2008 2:09 am

tox0tes wrote:

Code: Select all

import org.jfree.chart.renderer.xy.XYSplineRenderer;
I am getting
cannot find symbol
symbol : class XYSplineRenderer
location: package org.jfree.chart.renderer.xy
XYSplineRenderer has been available since v1.0.7 as stated in the JavaDoc, so you must be using v1.0.7 or later.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Post by tox0tes » Tue Aug 26, 2008 2:24 am

thanks, i upgraded to the correct version and now it works. How do I make the plot points smaller?

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Tue Aug 26, 2008 2:33 am

tox0tes wrote:thanks, i upgraded to the correct version and now it works. How do I make the plot points smaller?
Extend XYSplineRenderer and override the getItemShape method inherited from AbstractRenderer.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Post by tox0tes » Tue Aug 26, 2008 2:40 am

thanks a lot, works great 8)

tox0tes
Posts: 34
Joined: Tue Aug 05, 2008 7:05 pm

Post by tox0tes » Tue Aug 26, 2008 3:18 am

almost.... there is a problem where the curve extends beyond the auto-range:
Image

RichardWest
Posts: 844
Joined: Fri Oct 13, 2006 9:29 pm
Location: Sunnyvale, CA

Post by RichardWest » Tue Aug 26, 2008 3:22 am

tox0tes wrote:almost.... there is a problem where the curve extends beyond the auto-range:
The auto-range is best on the minimum and maximum values in the dataset plus some margin. The spline is not considered. The easiest solution would be to increase the lower margin, but feel free to contribute a patch if you figure out a more robust solution.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA

Locked