Hi,
I am using JFREE graphs, displaying in the browser. For this I am converting to Applets. Now I need to combine Scatter Plot and Line Graph into one. I have gone through OverlaidPlotLines.java program and tried to do the same with this. But it looks something different.
Please help me in this regard.
Thanking you,
Regards,
Mallesh
How combine Scatter and Line graphs into one
Re: How combine Scatter and Line graphs into one
If you post a little more information about what you have tried, it will be easier to point you in the right direction. You should also have a look at OverlaidXYPlotDemo for some ideas.
Regards,
DG.
Regards,
DG.
Re: How combine Scatter and Line graphs into one
Hi David,
Thanks for your reply. Here I am sending my source. In this JFParamUtil class is written by me. This class is used basically for parsing and saving into respective datatype fields. Class ScatterPlotDataSet is same as SampleXYDataset2, passing values to the constructor and getting XYDataset.
================================
package com.jrefinery.chart.demo;
import com.jrefinery.data.*;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.XYPlot;
import com.jrefinery.chart.ValueAxis;
import com.jrefinery.chart.NumberAxis;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.JFParamUtil;
import com.jrefinery.chart.demo.ScatterPlotDataSet;
import java.awt.Color;
import java.awt.GradientPaint;
import javax.swing.JApplet;
import java.awt.BorderLayout;
public class ScatterPlotApplet extends JApplet{
ChartPanel panel = null;
String strY_Label;
String strX_Label;
String strAGradient[];
String strABgColor[];
String strASeries[];
String strASeriesBg[];
Double objDblXValues[][] = null;
Double objDblYValues[][] = null;
public void init(){
String strTitle = getParameter("Header");
strY_Label = getParameter("Y_Label");
strX_Label = getParameter("X_Label");
String strXValues = getParameter("xValues");
String strYValues = getParameter("yValues");
String strSeries = getParameter("Series");
String strSeriesBg = getParameter("SeriesBg");
String strBgColor = getParameter("BgColor");
String strGradient = getParameter("GtColor");
strABgColor = (String[]) JFParamUtil.getStrArray(strBgColor,"}");
strAGradient = (String[]) JFParamUtil.getStrArray(strGradient,"}");
strASeries = (String[]) JFParamUtil.getStrArray(strSeries,",");
strASeriesBg = (String[]) JFParamUtil.getStrArray(strSeriesBg,"}");
objDblXValues = (Double[][])JFParamUtil.getDblDataVal(strXValues,"}");
objDblYValues = (Double[][])JFParamUtil.getDblDataVal(strYValues,"}");
JFreeChart chart = createScatterPlot(strTitle);
//Setting BackGround Color
chart.getPlot().setBackgroundPaint(new GradientPaint(0, 0,
JFParamUtil.getColor( strABgColor[0] ),
1000,0,
JFParamUtil.getColor(strABgColor[1])));
// set the color for each series...
chart.getPlot().setSeriesPaint(JFParamUtil.getPaintValues(strASeriesBg));
panel = new ChartPanel(chart, true, true, true, true, true);
//this.setContentPane(panel);
}
public void start() {
panel.setVisible(true);
getContentPane().add(panel, BorderLayout.CENTER);
validate();
}
/**
* Displays a scatter plot in its own frame. Crosshairs are switched on for demo purposes.
*/
public JFreeChart createScatterPlot(String title) {
// make an overlaid plot...
OverlaidXYPlot plot = new OverlaidXYPlot(strX_Label, strY_Label);
HorizontalDateAxis objHrzDtaxis =new HorizontalDateAxis(strX_Label);
objHrzDtaxis.configure();
plot.setDomainAxis(objHrzDtaxis);
// create a default chart based on some sample data...
//XYDataset data = new SampleXYDataset2();//objDblXValues
XYDataset data = new ScatterPlotDataSet(objDblXValues, objDblYValues, strASeries);
JFreeChart chart = ChartFactory.createScatterPlot(title,strX_Label,strY_Label,data,true);
chart.setBackgroundPaint(new GradientPaint(0, 0,
JFParamUtil.getColor( strAGradient[0] ),
1000,0,
JFParamUtil.getColor(strAGradient[1]) ));
XYPlot xyplot = (XYPlot)chart.getPlot();
ValueAxis domainAxis = xyplot.getDomainAxis();
domainAxis.setCrosshairVisible(true);
NumberAxis rangeAxis = (NumberAxis)xyplot.getRangeAxis();
rangeAxis.setCrosshairVisible(true);
rangeAxis.setAutoRangeIncludesZero(false);
//rangeAxis.setAutoRangeIncludesZero(true);
return chart;
}
}
I hope now, you will understand clearly. Please help me how include line graph into this.
Thanking you,
Regards,
Mallesh
Thanks for your reply. Here I am sending my source. In this JFParamUtil class is written by me. This class is used basically for parsing and saving into respective datatype fields. Class ScatterPlotDataSet is same as SampleXYDataset2, passing values to the constructor and getting XYDataset.
================================
package com.jrefinery.chart.demo;
import com.jrefinery.data.*;
import com.jrefinery.chart.JFreeChart;
import com.jrefinery.chart.XYPlot;
import com.jrefinery.chart.ValueAxis;
import com.jrefinery.chart.NumberAxis;
import com.jrefinery.ui.ApplicationFrame;
import com.jrefinery.chart.ChartPanel;
import com.jrefinery.chart.ChartFactory;
import com.jrefinery.chart.JFParamUtil;
import com.jrefinery.chart.demo.ScatterPlotDataSet;
import java.awt.Color;
import java.awt.GradientPaint;
import javax.swing.JApplet;
import java.awt.BorderLayout;
public class ScatterPlotApplet extends JApplet{
ChartPanel panel = null;
String strY_Label;
String strX_Label;
String strAGradient[];
String strABgColor[];
String strASeries[];
String strASeriesBg[];
Double objDblXValues[][] = null;
Double objDblYValues[][] = null;
public void init(){
String strTitle = getParameter("Header");
strY_Label = getParameter("Y_Label");
strX_Label = getParameter("X_Label");
String strXValues = getParameter("xValues");
String strYValues = getParameter("yValues");
String strSeries = getParameter("Series");
String strSeriesBg = getParameter("SeriesBg");
String strBgColor = getParameter("BgColor");
String strGradient = getParameter("GtColor");
strABgColor = (String[]) JFParamUtil.getStrArray(strBgColor,"}");
strAGradient = (String[]) JFParamUtil.getStrArray(strGradient,"}");
strASeries = (String[]) JFParamUtil.getStrArray(strSeries,",");
strASeriesBg = (String[]) JFParamUtil.getStrArray(strSeriesBg,"}");
objDblXValues = (Double[][])JFParamUtil.getDblDataVal(strXValues,"}");
objDblYValues = (Double[][])JFParamUtil.getDblDataVal(strYValues,"}");
JFreeChart chart = createScatterPlot(strTitle);
//Setting BackGround Color
chart.getPlot().setBackgroundPaint(new GradientPaint(0, 0,
JFParamUtil.getColor( strABgColor[0] ),
1000,0,
JFParamUtil.getColor(strABgColor[1])));
// set the color for each series...
chart.getPlot().setSeriesPaint(JFParamUtil.getPaintValues(strASeriesBg));
panel = new ChartPanel(chart, true, true, true, true, true);
//this.setContentPane(panel);
}
public void start() {
panel.setVisible(true);
getContentPane().add(panel, BorderLayout.CENTER);
validate();
}
/**
* Displays a scatter plot in its own frame. Crosshairs are switched on for demo purposes.
*/
public JFreeChart createScatterPlot(String title) {
// make an overlaid plot...
OverlaidXYPlot plot = new OverlaidXYPlot(strX_Label, strY_Label);
HorizontalDateAxis objHrzDtaxis =new HorizontalDateAxis(strX_Label);
objHrzDtaxis.configure();
plot.setDomainAxis(objHrzDtaxis);
// create a default chart based on some sample data...
//XYDataset data = new SampleXYDataset2();//objDblXValues
XYDataset data = new ScatterPlotDataSet(objDblXValues, objDblYValues, strASeries);
JFreeChart chart = ChartFactory.createScatterPlot(title,strX_Label,strY_Label,data,true);
chart.setBackgroundPaint(new GradientPaint(0, 0,
JFParamUtil.getColor( strAGradient[0] ),
1000,0,
JFParamUtil.getColor(strAGradient[1]) ));
XYPlot xyplot = (XYPlot)chart.getPlot();
ValueAxis domainAxis = xyplot.getDomainAxis();
domainAxis.setCrosshairVisible(true);
NumberAxis rangeAxis = (NumberAxis)xyplot.getRangeAxis();
rangeAxis.setCrosshairVisible(true);
rangeAxis.setAutoRangeIncludesZero(false);
//rangeAxis.setAutoRangeIncludesZero(true);
return chart;
}
}
I hope now, you will understand clearly. Please help me how include line graph into this.
Thanking you,
Regards,
Mallesh
Is there Scatter Plot renderer exist
Hi,
Thanks for your reply. I gone through API, didn't find ScatterPlot renderer. As you know, am trying to display combined graph of Scatter Plot and Line graph.
Any help will be appreciated. Thanks in advance.
-Regards,
Mallesh
Thanks for your reply. I gone through API, didn't find ScatterPlot renderer. As you know, am trying to display combined graph of Scatter Plot and Line graph.
Any help will be appreciated. Thanks in advance.
-Regards,
Mallesh
Re: How combine Scatter and Line graphs into one
On a quick scan of your code, it looks like you create an OverlaidXYPlot but never use it. You should look at the OverlaidXYPlotDemo class to get an idea of what to do.
Line plots and scatter plots are both generated using the StandardXYItemRenderer class. The constructor allows you to specify whether items are represented by lines, or shapes, or both.
Regards,
DG.
Line plots and scatter plots are both generated using the StandardXYItemRenderer class. The constructor allows you to specify whether items are represented by lines, or shapes, or both.
Regards,
DG.