Hello,
I want to plot points on the X and Y axis in a line chart.
e.g p1(20,0) or p2(0,20)
Currently I can plot the points only if the X and the Y co-ordinates are not zero.
If any one has any idea, let me know of how it can be done.
Thanks,
Scarlett
Plotting points on domain and range axis in Line chart
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: Plotting points on domain and range axis in Line chart
Can you explain the problem? It shouldn't matter if one or the other coordinate is zero.Scarlett wrote:Currently I can plot the points only if the X and the Y co-ordinates are not zero.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader


Creation of Line chart
//First step is creation of Dataset.
DefaultCategoryDataset dataset = new DefaultCategoryDataset()
dataset.addValue(10, " Classes", "0");
dataset.addValue(15, " Classes", "10");
//Second step is creating the Line chart with the above dataset.
I am using
ChartFactory.createLineChart(....);
When I see the above chart, I see the origin as (0,0) and one more point on X Axis as "0" above which the the Yvaue for the first point "10" gets plotted.
Where as what I want is that the first point should appear on the YAxis.
Let me know of how it can be done.
Thanks,
Scarlett
DefaultCategoryDataset dataset = new DefaultCategoryDataset()
dataset.addValue(10, " Classes", "0");
dataset.addValue(15, " Classes", "10");
//Second step is creating the Line chart with the above dataset.
I am using
ChartFactory.createLineChart(....);
When I see the above chart, I see the origin as (0,0) and one more point on X Axis as "0" above which the the Yvaue for the first point "10" gets plotted.
Where as what I want is that the first point should appear on the YAxis.
Let me know of how it can be done.
Thanks,
Scarlett
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Don't use a CategoryPlot for this, use an XYPlot:
Code: Select all
/*
* (C)opyright 2006, by Object Refinery Limited
*/
import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RefineryUtilities;
/**
* A very simple line chart.
*/
public class XYLineChartDemo extends JFrame {
/**
* A demonstration application showing how to create a simple time series
* chart. This example uses monthly data.
*
* @param title the frame title.
*/
public XYLineChartDemo(String title) {
super(title);
JFreeChart chart = createChart(createDataset());
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
chartPanel.setMouseZoomable(true, false);
setContentPane(chartPanel);
}
/**
* Creates a chart.
*
* @param dataset a dataset.
*
* @return A chart.
*/
private static JFreeChart createChart(XYDataset dataset) {
JFreeChart chart = ChartFactory.createXYLineChart(
"Line Chart", // title
"X", // x-axis label
"Y", // y-axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
return chart;
}
/**
* Creates a dataset.
*
* @return The dataset.
*/
private static XYDataset createDataset() {
XYSeries s1 = new XYSeries("Series 1");
s1.add(0.0, 10.0);
s1.add(10.0, 15.0);
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(s1);
return dataset;
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
XYLineChartDemo demo = new XYLineChartDemo("Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader

