How to Mix ScatterPlot and Lines
How to Mix ScatterPlot and Lines
Hi,
I'm a french student, and I develop an application using JFreeChart.
I have to make a chart with plots and lines, how I can do that ?
Sorry for my english
Regards,
Gaël
I'm a french student, and I develop an application using JFreeChart.
I have to make a chart with plots and lines, how I can do that ?
Sorry for my english
Regards,
Gaël
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: How to Mix ScatterPlot and Lines
Your english is fine! In JFreeChart, you can overlay multiple datasets on the same plot. First, call setDataset(int, dataset), then call setRenderer(int, renderer) to add an appropriate renderer for the dataset. You'll find these methods in the CategoryPlot and XYPlot classes (with slightly different parameter types reflecting the type of data that each plot supports).
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: How to Mix ScatterPlot and Lines
Ok I understand that, but I use which plot ?
But a chart could have many plots ??
I use which plot ?
But a chart could have many plots ??
I use which plot ?
-
- Posts: 47
- Joined: Thu Dec 11, 2008 7:59 pm
Re: How to Mix ScatterPlot and Lines
Here's my test code I used to figure this out myself. This example will create two separate charts that are overlaid on top of each other. It's like making two separate JFreeCharts then stacking them together.
From here you can tweak the plot.mapDatasetToXXX methods to your liking. If you want both the scatter and line graphs to share the same Domain (example: share the same time axis) then just change this:
Now both the scatter and line graphs share the same Domain axis. You can also share the same Range, or share both. Just mix and match until you have what you want.
Code: Select all
// Create a single plot containing both the scatter and line
XYPlot plot = new XYPlot();
/* SETUP SCATTER */
// Create the scatter data, renderer, and axis
XYDataset collection1 = getScatterPlotData();
XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true); // Shapes only
ValueAxis domain1 = new NumberAxis("Domain1");
ValueAxis range1 = new NumberAxis("Range1");
// Set the scatter data, renderer, and axis into plot
plot.setDataset(0, collection1);
plot.setRenderer(0, renderer1);
plot.setDomainAxis(0, domain1);
plot.setRangeAxis(0, range1);
// Map the scatter to the first Domain and first Range
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
/* SETUP LINE */
// Create the line data, renderer, and axis
XYDataset collection2 = getLinePlotData();
XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); // Lines only
ValueAxis domain2 = new NumberAxis("Domain2");
ValueAxis range2 = new NumberAxis("Range2");
// Set the line data, renderer, and axis into plot
plot.setDataset(1, collection2);
plot.setRenderer(1, renderer2);
plot.setDomainAxis(1, domain2);
plot.setRangeAxis(1, range2);
// Map the line to the second Domain and second Range
plot.mapDatasetToDomainAxis(1, 1);
plot.mapDatasetToRangeAxis(1, 1);
// Create the chart with the plot and a legend
JFreeChart chart = new JFreeChart("Multi Dataset Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
Code: Select all
// Map the line to the FIRST Domain and second Range
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);
Re: How to Mix ScatterPlot and Lines
Thanks a lot,
I'm using XYDotsRenderer and XYSpline and it works.
Perfect
I'm using XYDotsRenderer and XYSpline and it works.
Perfect
Re: How to Mix ScatterPlot and Lines
there is some error if i use your source code, there is no getScatterPlotData() and getLineChart in my netbeans..
i using jfreechart-1.0.14 and jcommon-1.0.16
can you explain to me?
is it possible if i want to mix polar chart and lines using jfreechart?
thank you very much..
*i'm an indonesian, sorry maybe i can't write english well...
i using jfreechart-1.0.14 and jcommon-1.0.16
can you explain to me?
is it possible if i want to mix polar chart and lines using jfreechart?
thank you very much..
*i'm an indonesian, sorry maybe i can't write english well...
Re: How to Mix ScatterPlot and Lines
Hello everyone: I have a question related to the topic.
I intend to draw X bar charts overlayed.
I can plot them bto video but the colors of the bars in each chart component are not displayed correctly. Simply they aren't the colors i've selected.
Before posting the code I would be grateful to those who suggest vaguely what can go wrong even according to their own experiences.
Thank you very much
Gib.
I intend to draw X bar charts overlayed.
I can plot them bto video but the colors of the bars in each chart component are not displayed correctly. Simply they aren't the colors i've selected.
Before posting the code I would be grateful to those who suggest vaguely what can go wrong even according to their own experiences.
Thank you very much
Gib.
Re: How to Mix ScatterPlot and Lines
Hi, Gibbster.
Is this thread at all relevant? (started by myself)
viewtopic.php?f=3&t=115807
I found that setting the "base" methods on the bar renderers does NOT work as I would expect.
For instance, these methods don't work as I would expect:
Instead, you have to call methods like renderer.setSeriesPaint(0, Color.blue) for each of your series in your collection. Then your colors should be correct.
Does that help?
I'm not sure your reply belongs on this thread but just thought I'd try to help.
Is this thread at all relevant? (started by myself)
viewtopic.php?f=3&t=115807
I found that setting the "base" methods on the bar renderers does NOT work as I would expect.
For instance, these methods don't work as I would expect:
Code: Select all
renderer.setBasePaint(Color.blue);
renderer.setBaseFillPaint(Color.blue);
Does that help?
I'm not sure your reply belongs on this thread but just thought I'd try to help.
Re: How to Mix ScatterPlot and Lines
Hello All,
I am doing a project in which I have to build a Jfreechart application.
I want a combo box with two types of chart selection: x-y plot and scatter plot.
Both will have same dataset but will not overlay each other.
Any help would be really helpful.
Regards
Sanchit
I am doing a project in which I have to build a Jfreechart application.
I want a combo box with two types of chart selection: x-y plot and scatter plot.
Both will have same dataset but will not overlay each other.
Any help would be really helpful.
Regards
Sanchit
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: How to Mix ScatterPlot and Lines
Do you want to switch from one chart to the next, or do you want to display the two charts simultaneously?
Technically, a scatter plot is an XYPlot. The only "special feature" of a scatter plot is that an XYItemRenderer is used that only draws shapes at the coordinates of the x/y data values.
Technically, a scatter plot is an XYPlot. The only "special feature" of a scatter plot is that an XYItemRenderer is used that only draws shapes at the coordinates of the x/y data values.