patch: make crosshairs work with multiple axes in xyplot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
michael75
Posts: 16
Joined: Thu Sep 15, 2005 4:42 pm

patch: make crosshairs work with multiple axes in xyplot

Post by michael75 » Wed Oct 05, 2005 10:25 am

hello david,

this is a first but wokring try. please have a look at it and tell me if it's the right way to go.

Code: Select all

diff -ruN -X jfreechart.exclude jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/plot/CrosshairState.java jfreechart-1.0.0-rc1\source/org/jfree/chart/plot/CrosshairState.java
--- jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/plot/CrosshairState.java	2005-06-02 17:41:34.000000000 +0200
+++ jfreechart-1.0.0-rc1\source/org/jfree/chart/plot/CrosshairState.java	2005-10-04 21:36:39.415749300 +0200
@@ -49,6 +49,8 @@
 
 import java.awt.geom.Point2D;
 
+import org.jfree.chart.axis.ValueAxis;
+
 /**
  * Maintains state information about crosshairs on a plot.
  *
@@ -73,9 +75,15 @@
     /** The x-value for the crosshair point. */
     private double crosshairX;
 
+    /** The x-axis for the crosshair point */
+    private ValueAxis crosshairXAxis;
+    
     /** The y-value for the crosshair point. */
     private double crosshairY;
 
+    /** The y-axis for the crosshair point */
+    private ValueAxis crosshairYAxis;
+
     /** 
      * The smallest distance so far between the anchor point and a data point. 
      */
@@ -158,6 +166,37 @@
 
     }
 
+    public void updateCrosshairPoint(double x, double y, double transX,
+			double transY, PlotOrientation orientation, ValueAxis domainAxis, ValueAxis rangeAxis) {
+
+		if (this.anchor != null) {
+			double d = 0.0;
+			if (this.calculateDistanceInDataSpace) {
+				d = (x - this.anchorX) * (x - this.anchorX)
+						+ (y - this.anchorY) * (y - this.anchorY);
+			} else {
+				double xx = this.anchor.getX();
+				double yy = this.anchor.getY();
+				if (orientation == PlotOrientation.HORIZONTAL) {
+					double temp = yy;
+					yy = xx;
+					xx = temp;
+				}
+				d = (transX - xx) * (transX - xx) + (transY - yy)
+						* (transY - yy);
+			}
+
+			if (d < this.distance) {
+				this.crosshairX = x;
+				this.crosshairY = y;
+				this.crosshairXAxis = domainAxis;
+				this.crosshairYAxis = rangeAxis;
+				this.distance = d;
+			}
+		}
+
+	}
+
     /**
      * Evaluates an x-value and if it is the closest to the anchor point it
      * becomes the new crosshair point.
@@ -177,6 +216,17 @@
 
     }
 
+    public void updateCrosshairX(double candidateX, ValueAxis domainAxis) {
+
+        double d = Math.abs(candidateX - this.anchorX);
+        if (d < this.distance) {
+            this.crosshairX = candidateX;
+            this.crosshairXAxis = domainAxis;
+            this.distance = d;
+        }
+
+    }
+
     /**
      * Evaluates a y-value and if it is the closest to the anchor point it
      * becomes the new crosshair point.
@@ -196,6 +246,17 @@
 
     }
 
+    public void updateCrosshairY(double candidateY, ValueAxis rangeAxis) {
+
+        double d = Math.abs(candidateY - this.anchorY);
+        if (d < this.distance) {
+            this.crosshairY = candidateY;
+            this.crosshairYAxis = rangeAxis;
+            this.distance = d;
+        }
+
+    }
+
     /** 
      * Sets the anchor point.  This is usually the mouse click point in a chart
      * panel, and the crosshair point will often be the data item that is 
@@ -245,4 +306,32 @@
         this.crosshairY = y;
     }
 
+	/**
+	 * @return Returns the crosshairXAxis.
+	 */
+	public ValueAxis getCrosshairXAxis() {
+		return crosshairXAxis;
+	}
+
+	/**
+	 * @param crosshairXAxis The crosshairXAxis to set.
+	 */
+	public void setCrosshairXAxis(ValueAxis crosshairXAxis) {
+		this.crosshairXAxis = crosshairXAxis;
+	}
+
+	/**
+	 * @return Returns the crosshairYAxis.
+	 */
+	public ValueAxis getCrosshairYAxis() {
+		return crosshairYAxis;
+	}
+
+	/**
+	 * @param crosshairYAxis The crosshairYAxis to set.
+	 */
+	public void setCrosshairYAxis(ValueAxis crosshairYAxis) {
+		this.crosshairYAxis = crosshairYAxis;
+	}
+
 }
diff -ruN -X jfreechart.exclude jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/plot/XYPlot.java jfreechart-1.0.0-rc1\source/org/jfree/chart/plot/XYPlot.java
--- jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/plot/XYPlot.java	2005-06-02 17:41:32.000000000 +0200
+++ jfreechart-1.0.0-rc1\source/org/jfree/chart/plot/XYPlot.java	2005-10-05 10:45:07.352344800 +0200
@@ -349,6 +349,9 @@
     /** The domain crosshair value. */
     private double domainCrosshairValue;
 
+    /** The domain axis used if the crosshair is locked on data */
+    private ValueAxis domainCrosshairAxis;
+    
     /** The pen/brush used to draw the crosshair (if any). */
     private transient Stroke domainCrosshairStroke;
 
@@ -367,6 +370,9 @@
     /** The range crosshair value. */
     private double rangeCrosshairValue;
 
+    /** The range axis used if the crosshair is locked on data */
+    private ValueAxis rangeCrosshairAxis;
+
     /** The pen/brush used to draw the crosshair (if any). */
     private transient Stroke rangeCrosshairStroke;
 
@@ -523,11 +529,13 @@
 
         this.domainCrosshairVisible = false;
         this.domainCrosshairValue = 0.0;
+        this.domainCrosshairAxis = null;
         this.domainCrosshairStroke = DEFAULT_CROSSHAIR_STROKE;
         this.domainCrosshairPaint = DEFAULT_CROSSHAIR_PAINT;
 
         this.rangeCrosshairVisible = false;
         this.rangeCrosshairValue = 0.0;
+        this.rangeCrosshairAxis = null;
         this.rangeCrosshairStroke = DEFAULT_CROSSHAIR_STROKE;
         this.rangeCrosshairPaint = DEFAULT_CROSSHAIR_PAINT;
 
@@ -2186,44 +2194,53 @@
 
         PlotOrientation orient = getOrientation();
 
+        // update crosshair location
+        setDomainCrosshairAxis(crosshairState.getCrosshairXAxis(), false);
+        setRangeCrosshairAxis(crosshairState.getCrosshairYAxis(), false);
+        setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
+        setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
+
         // draw domain crosshair if required...
         if (!this.domainCrosshairLockedOnData && anchor != null) {
-            double xx = getDomainAxis().java2DToValue(
+            double xx = getDomainCrosshairAxis().java2DToValue(
                 anchor.getX(), dataArea, getDomainAxisEdge()
             );
             crosshairState.setCrosshairX(xx);
         }
-        setDomainCrosshairValue(crosshairState.getCrosshairX(), false);
-        if (isDomainCrosshairVisible()) {
+        if (isDomainCrosshairVisible() && getDomainCrosshairAxis() != null
+        	&& getDomainCrosshairAxis().getRange().contains(getDomainCrosshairValue())) {
             double x = getDomainCrosshairValue();
             Paint paint = getDomainCrosshairPaint();
             Stroke stroke = getDomainCrosshairStroke();
+            ValueAxis domainAxis = getDomainCrosshairAxis();
+            ValueAxis rangeAxis = getRangeCrosshairAxis();
             if (orient == PlotOrientation.HORIZONTAL) {
-                drawHorizontalLine(g2, dataArea, x, stroke, paint);
+                drawHorizontalLine(g2, dataArea, x, stroke, paint, domainAxis, rangeAxis);
             }
             else if (orient == PlotOrientation.VERTICAL) {
-                drawVerticalLine(g2, dataArea, x, stroke, paint);
+                drawVerticalLine(g2, dataArea, x, stroke, paint, domainAxis, rangeAxis);
             }
         }
 
         // draw range crosshair if required...
         if (!this.rangeCrosshairLockedOnData && anchor != null) {
-            double yy = getRangeAxis().java2DToValue(
+            double yy = getRangeCrosshairAxis().java2DToValue(
                 anchor.getY(), dataArea, getRangeAxisEdge()
             );
             crosshairState.setCrosshairX(yy);
         }
-        setRangeCrosshairValue(crosshairState.getCrosshairY(), false);
-        if (isRangeCrosshairVisible()
-            && getRangeAxis().getRange().contains(getRangeCrosshairValue())) {
+        if (isRangeCrosshairVisible() && getRangeCrosshairAxis() != null
+            && getRangeCrosshairAxis().getRange().contains(getRangeCrosshairValue())) {
             double y = getRangeCrosshairValue();
             Paint paint = getRangeCrosshairPaint();
             Stroke stroke = getRangeCrosshairStroke();
+            ValueAxis domainAxis = getDomainCrosshairAxis();
+            ValueAxis rangeAxis = getRangeCrosshairAxis();
             if (orient == PlotOrientation.HORIZONTAL) {
-                drawVerticalLine(g2, dataArea, y, stroke, paint);
+                drawVerticalLine(g2, dataArea, y, stroke, paint, domainAxis, rangeAxis);
             }
             else if (orient == PlotOrientation.VERTICAL) {
-                drawHorizontalLine(g2, dataArea, y, stroke, paint);
+                drawHorizontalLine(g2, dataArea, y, stroke, paint, domainAxis, rangeAxis);
             }
         }
 
@@ -2928,6 +2945,36 @@
     }
 
     /**
+     * Utility method for drawing a horizontal line across the data area of the
+     * plot.
+     *
+     * @param g2  the graphics device.
+     * @param dataArea  the data area.
+     * @param value  the coordinate, where to draw the line.
+     * @param stroke  the stroke to use.
+     * @param paint  the paint to use.
+     * @param domainAxis  the domain axis to which the value is mapped
+     * @param rangeAxis  the range axis to which the value is mapped
+     */
+    protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea,
+			double value, Stroke stroke, Paint paint, ValueAxis domainAxis, ValueAxis rangeAxis) {
+
+		ValueAxis axis = rangeAxis;
+		if (getOrientation() == PlotOrientation.HORIZONTAL) {
+			axis = domainAxis;
+		}
+		if (axis.getRange().contains(value)) {
+			double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
+			Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea
+					.getMaxX(), yy);
+			g2.setStroke(stroke);
+			g2.setPaint(paint);
+			g2.draw(line);
+		}
+
+	}
+
+    /**
      * Utility method for drawing a vertical line on the data area of the plot.
      *
      * @param g2  the graphics device.
@@ -2958,6 +3005,36 @@
     }
 
     /**
+     * Utility method for drawing a vertical line on the data area of the plot.
+     *
+     * @param g2  the graphics device.
+     * @param dataArea  the data area.
+     * @param value  the coordinate, where to draw the line.
+     * @param stroke  the stroke to use.
+     * @param paint  the paint to use.
+     * @param domainAxis  the domain axis to which the value is mapped
+     * @param rangeAxis  the range axis to which the value is mapped
+     */
+    protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea,
+			double value, Stroke stroke, Paint paint, ValueAxis domainAxis, ValueAxis rangeAxis) {
+
+		ValueAxis axis = domainAxis;
+		if (getOrientation() == PlotOrientation.HORIZONTAL) {
+			axis = rangeAxis;
+		}
+		if (axis.getRange().contains(value)) {
+			double xx = axis.valueToJava2D(value, dataArea,
+					RectangleEdge.BOTTOM);
+			Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx,
+					dataArea.getMaxY());
+			g2.setStroke(stroke);
+			g2.setPaint(paint);
+			g2.draw(line);
+		}
+
+	}
+    
+    /**
      * Handles a 'click' on the plot by updating the anchor values...
      *
      * @param x  the x-coordinate, where the click occurred, in Java2D space.
@@ -3242,6 +3319,15 @@
     }
 
     /**
+     * Returns the domain axis to which the crosshair value has been mapped
+     * 
+     * @return The axis.
+     */
+    public ValueAxis getDomainCrosshairAxis() {
+    	return this.domainCrosshairAxis;
+    }
+    
+    /**
      * Sets the domain crosshair value and sends a {@link PlotChangeEvent} to
      * all registered listeners (provided that the domain crosshair is visible).
      *
@@ -3251,6 +3337,17 @@
         setDomainCrosshairValue(value, true);
     }
 
+    /*
+     * Sets the axis to which the domain crosshair value has been mapped
+     * <P>
+     * @param axis  the domain axis
+     * @param notify  a flag that controls whether or not listeners are
+     *                notified.
+     */
+    public void setDomainCrosshairAxis(ValueAxis axis, boolean notify) {
+    	this.domainCrosshairAxis = axis;
+    }
+    
     /**
      * Sets the domain crosshair value and, if requested, sends a
      * {@link PlotChangeEvent} to all registered listeners (provided that the
@@ -3364,6 +3461,15 @@
     }
 
     /**
+     * Returns the range axis to which the crosshair value has been mapped
+     * 
+     * @return The axis.
+     */
+    public ValueAxis getRangeCrosshairAxis() {
+    	return this.rangeCrosshairAxis;
+    }
+    
+    /**
      * Sets the domain crosshair value.
      * <P>
      * Registered listeners are notified that the plot has been modified, but
@@ -3392,6 +3498,20 @@
         }
     }
 
+    /*
+     * Sets the axis to which the range crosshair value has been mapped
+     * <P>
+     * @param axis  the range axis
+     * @param notify  a flag that controls whether or not listeners are
+     *                notified.
+     */
+    public void setRangeCrosshairAxis(ValueAxis axis, boolean notify) {
+    	this.rangeCrosshairAxis = axis;
+        if (isRangeCrosshairVisible() && notify) {
+            notifyListeners(new PlotChangeEvent(this));
+        }
+    }
+
     /**
      * Returns the Stroke used to draw the crosshair (if visible).
      *
diff -ruN -X jfreechart.exclude jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java jfreechart-1.0.0-rc1\source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java
--- jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java	2005-06-02 17:41:34.000000000 +0200
+++ jfreechart-1.0.0-rc1\source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java	2005-10-04 21:32:57.442140300 +0200
@@ -1317,6 +1317,36 @@
         }
 
     }
+
+    protected void updateCrosshairValues(CrosshairState crosshairState,
+			double x, double y, double transX, double transY,
+			PlotOrientation orientation,
+			ValueAxis domainAxis, ValueAxis rangeAxis) {
+
+		if (orientation == null) {
+			throw new IllegalArgumentException("Null 'orientation' argument.");
+		}
+
+		if (crosshairState != null) {
+			// do we need to update the crosshair values?
+			if (this.plot.isDomainCrosshairLockedOnData()) {
+				if (this.plot.isRangeCrosshairLockedOnData()) {
+					// both axes
+					crosshairState.updateCrosshairPoint(x, y, transX, transY,
+							orientation, domainAxis, rangeAxis);
+				} else {
+					// just the domain axis...
+					crosshairState.updateCrosshairX(x, domainAxis);
+				}
+			} else {
+				if (this.plot.isRangeCrosshairLockedOnData()) {
+					// just the range axis...
+					crosshairState.updateCrosshairY(y, rangeAxis);
+				}
+			}
+		}
+
+	}
     
     /**
      * Draws an item label.
diff -ruN -X jfreechart.exclude jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.java jfreechart-1.0.0-rc1\source/org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.java
--- jfreechart-1.0.0-rc1-orig\source/org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.java	2005-06-02 17:41:32.000000000 +0200
+++ jfreechart-1.0.0-rc1\source/org/jfree/chart/renderer/xy/XYLineAndShapeRenderer.java	2005-10-04 21:33:56.668484700 +0200
@@ -1053,7 +1053,7 @@
         }
 
         updateCrosshairValues(
-            crosshairState, x1, y1, transX1, transY1, plot.getOrientation()
+            crosshairState, x1, y1, transX1, transY1, plot.getOrientation(), domainAxis, rangeAxis
         );
 
         // add an entity for the item...
Last edited by michael75 on Wed Oct 05, 2005 10:32 am, edited 1 time in total.

michael75
Posts: 16
Joined: Thu Sep 15, 2005 4:42 pm

dirty example to demonstrate it

Post by michael75 » Wed Oct 05, 2005 10:29 am

Code: Select all

/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the Free Software Foundation, 
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * -------------------------
 * TimeSeriesChartDemo1.java
 * -------------------------
 * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
 *
 * Original Author:  David Gilbert (for Object Refinery Limited);
 * Contributor(s):   ;
 *
 * $Id: TimeSeriesChartDemo1.java,v 1.2 2005/03/28 19:38:45 mungady Exp $
 *
 * Changes
 * -------
 * 09-Mar-2005 : Version 1, copied from the demo collection that ships with
 *               the JFreeChart Developer Guide (DG);
 *
 */

package de.esslandsberg.tc;

import java.awt.Color;
import java.text.SimpleDateFormat;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;

/**
 * An example of a time series chart.  For the most part, default settings are 
 * used, except that the renderer is modified to show filled shapes (as well as 
 * lines) at each data point.
 */
public class TimeSeriesChartDemo1 extends ApplicationFrame {

    /**
     * A demonstration application showing how to create a simple time series 
     * chart.  This example uses monthly data.
     *
     * @param title  the frame title.
     */
    public TimeSeriesChartDemo1(String title) {
        super(title);
        XYDataset dataset = createDataset();
        JFreeChart chart = createChart(dataset);
        ChartPanel chartPanel = new ChartPanel(chart, false);
        chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
        chartPanel.setMouseZoomable(true, false);
        setContentPane(chartPanel);
    }

    /**
     * Creates a chart.
     * 
     * @param dataset  a dataset.
     * 
     * @return A chart.
     */
    private static JFreeChart createChart(XYDataset dataset) {

        JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "Legal & General Unit Trust Prices",  // title
            "Date",             // x-axis label
            "Price Per Unit",   // y-axis label
            dataset,            // data
            true,               // create legend?
            true,               // generate tooltips?
            false               // generate URLs?
        );

        chart.setBackgroundPaint(Color.white);

        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        
        XYItemRenderer r = plot.getRenderer();
        if (r instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
            renderer.setDefaultShapesVisible(true);
            renderer.setDefaultShapesFilled(true);
            
        }
        
        DateAxis axis = (DateAxis) plot.getDomainAxis();
        axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
        ValueAxis vaxis = (ValueAxis) plot.getRangeAxis();
        ValueAxis vaxis1 = null;
        ValueAxis haxis = (ValueAxis) plot.getDomainAxis();
        ValueAxis haxis1 = null;
        try {
        	vaxis1 = (ValueAxis)vaxis.clone();
        	haxis1 = (ValueAxis)haxis.clone();
        }
        catch (Exception e) {
        	e.printStackTrace();
        }
        vaxis1.setRange(-20, 200);
        //vaxis1.
        plot.setRangeAxis(1, vaxis1);
        plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);
        plot.setDomainAxis(1, haxis1);
        plot.setDataset(1, createDataset1());
        plot.mapDatasetToRangeAxis(1, 1);
        plot.mapDatasetToDomainAxis(1, 1);
        		
        return chart;

    }
    
    /**
     * Creates a dataset, consisting of two series of monthly data.
     *
     * @return The dataset.
     */
    private static XYDataset createDataset() {

        TimeSeries s1 = new TimeSeries("L&G European Index Trust", Month.class);
        s1.add(new Month(2, 2001), 181.8);
        s1.add(new Month(3, 2001), 167.3);
        s1.add(new Month(4, 2001), 153.8);
        s1.add(new Month(5, 2001), 167.6);
        s1.add(new Month(6, 2001), 158.8);
        s1.add(new Month(7, 2001), 148.3);
        s1.add(new Month(8, 2001), 153.9);
        s1.add(new Month(9, 2001), 142.7);
        s1.add(new Month(10, 2001), 123.2);
        s1.add(new Month(11, 2001), 131.8);
        s1.add(new Month(12, 2001), 139.6);
        s1.add(new Month(1, 2002), 142.9);
        s1.add(new Month(2, 2002), 138.7);
        s1.add(new Month(3, 2002), 137.3);
        s1.add(new Month(4, 2002), 143.9);
        s1.add(new Month(5, 2002), 139.8);
        s1.add(new Month(6, 2002), 137.0);
        s1.add(new Month(7, 2002), 132.8);

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(s1);
        dataset.setDomainIsPointsInTime(true);

        return dataset;

    }

    public static XYDataset createDataset1() {

        TimeSeries s2 = new TimeSeries("Other values", Month.class);
        s2.add(new Month(2, 2002), 129.6);
        s2.add(new Month(3, 2002), 123.2);
        s2.add(new Month(4, 2002), 117.2);
        s2.add(new Month(5, 2002), 124.1);
        s2.add(new Month(6, 2002), 122.6);
        s2.add(new Month(7, 2002), 119.2);
        s2.add(new Month(8, 2002), 116.5);
        s2.add(new Month(9, 2002), 112.7);
        s2.add(new Month(10, 2002), 101.5);
        s2.add(new Month(11, 2002), 106.1);
        s2.add(new Month(12, 2002), 110.3);
        s2.add(new Month(1, 2003), 111.7);
        s2.add(new Month(2, 2003), 111.0);
        s2.add(new Month(3, 2003), 109.6);
        s2.add(new Month(4, 2003), 113.2);
        s2.add(new Month(5, 2003), 111.6);
        s2.add(new Month(6, 2003), 108.8);
        s2.add(new Month(7, 2003), 101.6);

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(s2);

        dataset.setDomainIsPointsInTime(true);

        return dataset;

    }
    /**
     * Creates a panel for the demo (used by SuperDemo.java).
     * 
     * @return A panel.
     */
    public static JPanel createDemoPanel() {
        JFreeChart chart = createChart(createDataset());
        return new ChartPanel(chart);
    }
    
    /**
     * Starting point for the demonstration application.
     *
     * @param args  ignored.
     */
    public static void main(String[] args) {

        TimeSeriesChartDemo1 demo = new TimeSeriesChartDemo1(
            "Time Series Chart Demo 1"
        );
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}

Guest

Post by Guest » Tue Oct 11, 2005 12:58 pm

tried it and it worked didn't see if it affected other stuff but seems to be fine. Now still have to look into the other probleme whereas the tooltip don't show up for the series drawn on the other axis... Thanks though for that code

Locked