incompatible type when createScatterPlot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
droop
Posts: 7
Joined: Fri Feb 01, 2008 11:01 am

incompatible type when createScatterPlot

Post by droop » Thu Feb 07, 2008 4:08 am

I got incompatible type when I try to write this, wy?

JFreeChart chart = ChartFactory.createScatterPlot(
"Line Chart Demo 2", // chart title
"X", // x axis label
"Y", // y axis label
subplot1, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);


I just whant to create a simple scatterplot without lines between the points. The entire code follow:

import org.jfree.chart.JFreeChart;
import java.awt.*;
import javax.swing.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class Main {
public static void main(String[] args) {
final XYDataset data1 = createDataset();
final XYItemRenderer renderer1 = new StandardXYItemRenderer();
final NumberAxis rangeAxis1 = new NumberAxis("Range 1");

final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);



JFreeChart chart = ChartFactory.createScatterPlot(
"Line Chart Demo 2", // chart title
"X", // x axis label
"Y", // y axis label
subplot1, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);


ChartFrame frame = new ChartFrame("First", chart);
frame.pack();
frame.setVisible(true);

}



static XYDataset createDataset() {

final XYSeries series2 = new XYSeries("series 2");

series2.add(10.0, 16853.2);
series2.add(20.0, 19642.3);
series2.add(30.0, 18253.5);
series2.add(40.0, 15352.3);
series2.add(50.0, 13532.0);
series2.add(100.0, 12635.3);
series2.add(110.0, 13998.2);
series2.add(120.0, 11943.2);
series2.add(130.0, 16943.9);
series2.add(140.0, 17843.2);
series2.add(150.0, 16495.3);
series2.add(160.0, 17943.6);
series2.add(170.0, 18500.7);
series2.add(180.0, 19595.9);

return new XYSeriesCollection(series2);
}
}




/Mike

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

Post by paradoxoff » Thu Feb 07, 2008 8:59 am

The fourth parameter in ChartFactory.createScatterPlot is an XYDataset. You are submitting an XYPlot instead. Just replace "subplot1" with "data1" and it should work. Note that there is no need to specify a renderer or a range axis when using the factory functions, so the respective lines in your code are superfluous.

droop
Posts: 7
Joined: Fri Feb 01, 2008 11:01 am

Post by droop » Thu Feb 07, 2008 11:50 am

Thanks!

kuroi_shinigami
Posts: 1
Joined: Tue Apr 29, 2008 1:23 pm

Post by kuroi_shinigami » Tue Apr 29, 2008 1:35 pm

I also have the same problem.

Here is my code,
JFreeChart chart = ChartFactory.createScatterPlot("Wireless Security Protocol",
"X", "Y",
XYDataset.class,
PlotOrientation.VERTICAL,
true,
true,
false
);
chart.getPlot();
Legend legend = chart.getLegend();
if (legend instanceof StandardLegend) {
StandardLegend sl = (StandardLegend) legend;
sl.setDisplaySeriesShapes(true);
}
NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
domainAxis.setAutoRangeIncludesZero(false);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 500));
chartPanel.setVerticalAxisTrace(true);
chartPanel.setHorizontalAxisTrace(true);
chartPanel.setVerticalZoom(true);
chartPanel.setHorizontalZoom(true);
setContentPane(chartPanel);

}

Don't mind the XYDataset.class, since I only use it to avoid error of not using XYDataset class.

It still return incompatible type error, expected orf.jfree.chart.JFreeChart, found org.jfree.chart.ChartFactory.createScatterPlot.

Can somebody help me? Thx in advance.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Apr 29, 2008 4:38 pm

kuroi_shinigami wrote:Don't mind the XYDataset.class, since I only use it to avoid error of not using XYDataset class.
Get out your Java text book and read it some more. XYDataset.class is of type Class, not XYDataset.

If you don't have a dataset to pass to the ChartFactory.createChartXYZ() method, just pass null.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked