Contour Chart problem

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
alsw-2000
Posts: 16
Joined: Thu May 22, 2003 12:53 pm

Contour Chart problem

Post by alsw-2000 » Fri Apr 30, 2004 10:11 am

Dear all,

I am new to Contour Chart.
I have downloaded a Contour Chart's demo program, it shows the following chart, but which is not the one I want.
Image
When I input the same data set to ms excel it generate the following chart.
And which is exactly what I want.
Image
is there any function that can calculate the values betweens data points, so that it can generate a chart like the one generated by excel?

the source code of the Contour Chart's demo program is

Code: Select all

package charts.jfreechart;

import java.awt.Color;
import java.awt.GradientPaint;
import java.util.Date;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ColorBar;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.LogarithmicAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.ContourPlot;
import org.jfree.data.ContourDataset;
import org.jfree.data.DefaultContourDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.ui.ColorPalette;
import org.jfree.chart.ui.RainbowPalette;



public class JFree_Contour extends ApplicationFrame
{
	public ChartPanel panel = null;

	public JFree_Contour(String title)
	{
		super(title);

		JFreeChart chart = createContourPlot();
		panel = new ChartPanel(chart, true, true, true, true, true);
		panel.setPreferredSize(new java.awt.Dimension(500, 270));
		panel.setMaximumDrawHeight(100000); //stop ChartPanel from scaling output
		panel.setMaximumDrawWidth(100000); //stop ChartPanel from scaling output
		panel.setHorizontalZoom(true);
		panel.setVerticalZoom(true);
		panel.setFillZoomRectangle(true);

	}

	/**
	 * Creates a ContourPlot chart.
	 *
	 * @return the chart.
	 */
	private JFreeChart createContourPlot()
	{
		String title = "Contour Plot";
		String xAxisLabel = "X Values";
		String yAxisLabel = "Y Values";
		String zAxisLabel = "Color Values";

		ValueAxis xAxis = null;
		NumberAxis yAxis = null;
		ColorBar zColorBar = null;

		xAxis = new NumberAxis(xAxisLabel);
		yAxis = new NumberAxis(yAxisLabel);
		zColorBar = new ColorBar(zAxisLabel);

		((NumberAxis) xAxis).setAutoRangeIncludesZero(false);

		yAxis.setAutoRangeIncludesZero(false);

		((NumberAxis) xAxis).setLowerMargin(0.0);
		((NumberAxis) xAxis).setUpperMargin(0.0);

		yAxis.setLowerMargin(0.0);
		yAxis.setUpperMargin(0.0);

		zColorBar.getAxis().setTickMarksVisible(true);
		zColorBar.setMinimumValue(-250);
		zColorBar.setMaximumValue(200);

		ContourDataset data = createDataset();

		ColorPalette cp = new RainbowPalette();

		double x[] = {-250,-200,-150,-100,-50, 0, 50, 100, 150, 200};

		cp.setTickValues(x);
		cp.setStepped(true);

		zColorBar.setColorPalette(cp);

		ContourPlot plot = new ContourPlot(data, xAxis, yAxis, zColorBar);

		plot.setDataAreaRatio(0);

		JFreeChart chart = new JFreeChart(title, null, plot, false);

		return chart;
	}

	private ContourDataset createDataset()
	{
		ContourDataset data = null;

		Double[] oDoubleX = new Double[25];
		Double[] oDoubleY = new Double[25];
		Double[] oDoubleZ = new Double[25];

		// 10P
		oDoubleX[0] = new Double(1);
		oDoubleY[0] = new Double(10);
		oDoubleZ[0] = new Double(-50);

		oDoubleX[1] = new Double(1);
		oDoubleY[1] = new Double(20);
		oDoubleZ[1] = new Double(-38.50);

		oDoubleX[2] = new Double(1);
		oDoubleY[2] = new Double(30);
		oDoubleZ[2] = new Double(-38.50);

		oDoubleX[3] = new Double(1);
		oDoubleY[3] = new Double(40);
		oDoubleZ[3] = new Double(-38.50);

		oDoubleX[4] = new Double(1);
		oDoubleY[4] = new Double(50);
		oDoubleZ[4] = new Double(-38.50);

		// 25P
		oDoubleX[5] = new Double(2);
		oDoubleY[5] = new Double(10);
		oDoubleZ[5] = new Double(-13.2);

		oDoubleX[6] = new Double(2);
		oDoubleY[6] = new Double(20);
		oDoubleZ[6] = new Double(-41.05);

		oDoubleX[7] = new Double(2);
		oDoubleY[7] = new Double(30);
		oDoubleZ[7] = new Double(-41.05);

		oDoubleX[8] = new Double(2);
		oDoubleY[8] = new Double(40);
		oDoubleZ[8] = new Double(-41.05);

		oDoubleX[9] = new Double(2);
		oDoubleY[9] = new Double(50);
		oDoubleZ[9] = new Double(-41.05);

		// ATM
		oDoubleX[10] = new Double(3);
		oDoubleY[10] = new Double(10);
		oDoubleZ[10] = new Double(-22.86);

		oDoubleX[11] = new Double(3);
		oDoubleY[11] = new Double(20);
		oDoubleZ[11] = new Double(-138);

		oDoubleX[12] = new Double(3);
		oDoubleY[12] = new Double(30);
		oDoubleZ[12] = new Double(-138);

		oDoubleX[13] = new Double(3);
		oDoubleY[13] = new Double(40);
		oDoubleZ[13] = new Double(-138);

		oDoubleX[14] = new Double(3);
		oDoubleY[14] = new Double(50);
		oDoubleZ[14] = new Double(-138);

		// 25C
		oDoubleX[15] = new Double(4);
		oDoubleY[15] = new Double(10);
		oDoubleZ[15] = new Double(-27.96);

		oDoubleX[16] = new Double(4);
		oDoubleY[16] = new Double(20);
		oDoubleZ[16] = new Double(-51.91);

		oDoubleX[17] = new Double(4);
		oDoubleY[17] = new Double(30);
		oDoubleZ[17] = new Double(-51.91);

		oDoubleX[18] = new Double(4);
		oDoubleY[18] = new Double(40);
		oDoubleZ[18] = new Double(-51.91);

		oDoubleX[19] = new Double(4);
		oDoubleY[19] = new Double(50);
		oDoubleZ[19] = new Double(-51.91);

		// 10C
		oDoubleX[20] = new Double(5);
		oDoubleY[20] = new Double(10);
		oDoubleZ[20] = new Double(-31.01);

		oDoubleX[21] = new Double(5);
		oDoubleY[21] = new Double(20);
		oDoubleZ[21] = new Double(-56.73);

		oDoubleX[22] = new Double(5);
		oDoubleY[22] = new Double(30);
		oDoubleZ[22] = new Double(-56.73);

		oDoubleX[23] = new Double(5);
		oDoubleY[23] = new Double(40);
		oDoubleZ[23] = new Double(-56.73);

		oDoubleX[24] = new Double(5);
		oDoubleY[24] = new Double(50);
		oDoubleZ[24] = new Double(-56.73);

		data = new DefaultContourDataset("Contouring", oDoubleX, oDoubleY, oDoubleZ);

		return data;

	}

	/**
	 * Starting point for the demonstration application.
	 *
	 * @param args  command line options, launch ContourDemoPlot -? for listing of options.
	 */
	public static void main(String[] args)
	{

		JFree_Contour demo = new JFree_Contour("ContourPlot Demo");
		demo.setContentPane(demo.panel);
		demo.pack();
		RefineryUtilities.centerFrameOnScreen(demo);
		demo.setVisible(true);

	}

}
Cheers,
Andy

Locked