1

I am using ChartFactory.createStackedXYAreaChart() in my application using JFreeChart. This chart needs TableXYDataset in it's argument at the time of creation. My problem is that I am using different series to add in charts, but it does not allow me to add differant series to the XYDataset. I am using the following code:

XYSeries series1 = new XYSeries("First");

series1.add(0.1,25);
series1.add(0.2,43);
series1.add(0.5,70);
series1.add(0.64,94);
series1.add(0.9,112);

XYSeries series2 = new XYSeries("Second");

series2.add(0.9,112);
series2.add(1.1,150);
series2.add(1.3,175);
series2.add(1.5,200);
series2.add(1.7,225);
series2.add(1.9,250);

XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
dataset.addSeries(series2);

return dataset;

Please help me.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045

1 Answers1

2

DefaultTableXYDataset is a TableXYDataset that has an addSeries(XYSeries series) method.

Addendum: Note that duplicates are not allowed. For example,

enter image description here

XYSeries series1 = new XYSeries("First", true, false);
series1.add(0.1, 25);
series1.add(0.2, 43);
series1.add(0.5, 70);
series1.add(0.64, 94);
series1.add(0.9, 112);

XYSeries series2 = new XYSeries("Second", true, false);
series2.add(0.9, 112);
series2.add(1.1, 150);
series2.add(1.3, 175);
series2.add(1.5, 200);
series2.add(1.7, 225);
series2.add(1.9, 250);

DefaultTableXYDataset dataset = new DefaultTableXYDataset();
dataset.addSeries(series1);
dataset.addSeries(series2);
return dataset;
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • trashgod:: Thanks buddy..! In the same graph I am using value marker to show domain axis value.. the cade I am using for it is Marker myDateMarker = new ValueMarker(new Double(0.31)); myDateMarker.setPaint(Color.BLACK); plot.addDomainMarker(myDateMarker); plot.addDomainMarker(myDateMarker, Layer.FOREGROUND); myDateMarker.setStroke(new BasicStroke(0.6f)); I want to set the marker as dotted.. how should I do ?? – Shreyas Deshpande Aug 17 '12 at 05:01
  • Thanks for help.. in the same application i want to add the the errorlines (range error lines).. I am using XYDataset.. can anyone post me the code specifying hw to add these error lines? I am using the scatter chart gor it – Shreyas Deshpande Aug 20 '12 at 05:57
  • I'm not sure what you mean, but this sounds like a new question. You might browse the [API, samples or guide](http://www.jfree.org/jfreechart/) for related examples, e.g. `CandlestickRenderer`. – trashgod Aug 20 '12 at 06:44
  • trashgod: I mean to say i want to add error bars at points in scatter plot..can u post related code for it? – Shreyas Deshpande Aug 21 '12 at 04:02
  • [`XYErrorRenderer`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/xy/XYErrorRenderer.html) looks promising, although I've not used it. – trashgod Aug 21 '12 at 09:30
  • trashgod: HI.. yea, actually this XYRenderer provides such facility for adding error bars.. but i am getting only error bars for x values i.e. domain fluctuations but i want for the Range(y values) also. i have setted setDrawXError(true); and setDrawYError(true); for the renderer.. also i want to control the error bar length.any idea how should i achieve it? – Shreyas Deshpande Aug 22 '12 at 05:11
  • This is definitely a new question. You might want to check the demo and put together an [sscce](http://sscce.org/) in preparation. – trashgod Aug 22 '12 at 10:36