Hi All,
Is there a way to plot a line using a line equation?
y = mx+c.
where 'm' is the slope
and 'c' is the Y intercept.
In the above case I know the values of 'm' and 'c'
Thanks,
Scarlett
Plotting a line by using an euqation
If you have a range of y or x values then generate a double[][] data. For a straight line just use the four coordinates at the extremes. Then use ChartFactory.createXYLineChart as follows:
DefaultXYDataset aDefaultXYDataset = new DefaultXYDataset();
aDefaultXYDataset.addSeries( "a", data );
JFreeChart aJFreeChart = ChartFactory.createXYLineChart(
null, null, null, aDefaultXYDataset,
PlotOrientation.HORIZONTAL, false, false, false );
Play around with the parameters until you get what your after.
I've only just started with JFreeChart, but that is how I did it.
Best wishes,
Andy
DefaultXYDataset aDefaultXYDataset = new DefaultXYDataset();
aDefaultXYDataset.addSeries( "a", data );
JFreeChart aJFreeChart = ChartFactory.createXYLineChart(
null, null, null, aDefaultXYDataset,
PlotOrientation.HORIZONTAL, false, false, false );
Play around with the parameters until you get what your after.
I've only just started with JFreeChart, but that is how I did it.
Best wishes,
Andy
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
JFreeChart doesn't know how to plot equations, just data, so you need to get sample points from your equation. The way Andy suggests is probably the easiest.
Another alternative is to write a class that represents your function and implements the Function2D interface (this assumes that your function can be expressed as y = f(x))...having done that, you can use the DatasetUtilities.sampleFunction2D() method to create a dataset containing sample values from your function.
Another alternative is to write a class that represents your function and implements the Function2D interface (this assumes that your function can be expressed as y = f(x))...having done that, you can use the DatasetUtilities.sampleFunction2D() method to create a dataset containing sample values from your function.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

