org.jfree.chart.plot.XYPlot Java Examples

The following examples show how to use org.jfree.chart.plot.XYPlot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChartFactory.java    From openstock with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Creates a wind plot with default settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the x-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag that controls whether or not a legend is created.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A wind plot.
 *
 */
public static JFreeChart createWindPlot(String title, String xAxisLabel,
        String yAxisLabel, WindDataset dataset, boolean legend,
        boolean tooltips, boolean urls) {

    ValueAxis xAxis = new DateAxis(xAxisLabel);
    ValueAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setRange(-12.0, 12.0);

    WindItemRenderer renderer = new WindItemRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #2
Source File: XYLineAndShapeRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    XYSeriesCollection dataset
            = RendererXYPackageUtils.createTestXYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.9));
    assertTrue(bounds.contains(1.0));
    assertTrue(bounds.contains(2.0));
    assertFalse(bounds.contains(2.10));
}
 
Example #3
Source File: ChartFactory.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
                                                String timeAxisLabel,
                                                String valueAxisLabel,
                                                OHLCDataset dataset,
                                                boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example #4
Source File: XYLineChartTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #5
Source File: ProjectionPlotRenderer.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public ProjectionPlotRenderer(XYPlot plot, ProjectionPlotDataset dataset) {
  super(false, true);
  this.dataset = dataset;
  this.setSeriesShape(0, dataPointsShape);

  paintsForGroups = new Paint[dataset.getNumberOfGroups()];
  DrawingSupplier drawSupp = plot.getDrawingSupplier();
  for (int groupNumber = 0; groupNumber < dataset.getNumberOfGroups(); groupNumber++) {

    Paint nextPaint = drawSupp.getNextPaint();
    while (isAvoidColor((Color) nextPaint))
      nextPaint = drawSupp.getNextPaint();

    paintsForGroups[groupNumber] = nextPaint;

  }

}
 
Example #6
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #7
Source File: XYDrawableAnnotation.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the annotation.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis, 
                 int rendererIndex,
                 PlotRenderingInfo info) {

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);
    float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, 
            domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, 
            rangeEdge);
    Rectangle2D area = new Rectangle2D.Double(j2DX - this.width / 2.0, 
            j2DY - this.height / 2.0, this.width, this.height);
    this.drawable.draw(g2, area);
    String toolTip = getToolTipText();
    String url = getURL();
    if (toolTip != null || url != null) {
        addEntity(info, area, rendererIndex, toolTip, url);
    }
    
}
 
Example #8
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getRendererForDataset() method.
 */
public void testGetRendererForDataset() {
    XYDataset d0 = new XYSeriesCollection();
    XYDataset d1 = new XYSeriesCollection();
    XYDataset d2 = new XYSeriesCollection();
    XYDataset d3 = new XYSeriesCollection();  // not used by plot
    XYItemRenderer r0 = new XYLineAndShapeRenderer();
    XYItemRenderer r2 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot();
    plot.setDataset(0, d0);
    plot.setDataset(1, d1);
    plot.setDataset(2, d2);
    plot.setRenderer(0, r0);
    // no renderer 1
    plot.setRenderer(2, r2);
    assertEquals(r0, plot.getRendererForDataset(d0));
    assertEquals(r0, plot.getRendererForDataset(d1));
    assertEquals(r2, plot.getRendererForDataset(d2));
    assertEquals(null, plot.getRendererForDataset(d3));
    assertEquals(null, plot.getRendererForDataset(null));
}
 
Example #9
Source File: DateTimeAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates the histogram chart.
 *
 * @param exampleSet
 * @return
 */
private JFreeChart createHistogramChart(final ExampleSet exampleSet) {
	JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet),
			PlotOrientation.VERTICAL, false, false, false);
	AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
	chart.setBackgroundPaint(null);
	chart.setBackgroundImageAlpha(0.0f);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setRangeGridlinesVisible(false);
	plot.setDomainGridlinesVisible(false);
	plot.setOutlineVisible(false);
	plot.setRangeZeroBaselineVisible(false);
	plot.setDomainZeroBaselineVisible(false);
	plot.getDomainAxis().setTickLabelsVisible(false);
	plot.setBackgroundPaint(COLOR_INVISIBLE);
	plot.setBackgroundImageAlpha(0.0f);

	XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
	renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME));
	renderer.setBarPainter(new StandardXYBarPainter());
	renderer.setDrawBarOutline(true);
	renderer.setShadowVisible(false);

	return chart;
}
 
Example #10
Source File: XYBarChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);

    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #11
Source File: AbstractXYItemRenderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fills a band between two values on the axis.  This can be used to color
 * bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the domain axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
@Override
public void fillDomainGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double start, double end) {

    double x1 = axis.valueToJava2D(start, dataArea,
            plot.getDomainAxisEdge());
    double x2 = axis.valueToJava2D(end, dataArea,
            plot.getDomainAxisEdge());
    Rectangle2D band;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        band = new Rectangle2D.Double(Math.min(x1, x2), dataArea.getMinY(),
                Math.abs(x2 - x1), dataArea.getHeight());
    }
    else {
        band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(x1, x2),
                dataArea.getWidth(), Math.abs(x2 - x1));
    }
    Paint paint = plot.getDomainTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example #12
Source File: NumberAxisTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that the auto-range for the domain axis on an XYPlot is
 * working as expected.
 */
@Test
public void testXYAutoRange1() {
    XYSeries series = new XYSeries("Series 1");
    series.add(1.0, 1.0);
    series.add(2.0, 2.0);
    series.add(3.0, 3.0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y",
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getDomainAxis();
    axis.setAutoRangeIncludesZero(false);
    assertEquals(0.9, axis.getLowerBound(), EPSILON);
    assertEquals(3.1, axis.getUpperBound(), EPSILON);
}
 
Example #13
Source File: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
public void testFindDomainBounds() {
    TableXYDataset dataset 
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, 
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #14
Source File: XYDifferenceRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color 
 *              information etc).
 * @param domainAxis  the domain (horizontal) axis.
 * @param rangeAxis  the range (vertical) axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot 
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
public void drawItem(Graphics2D g2,
                     XYItemRendererState state,
                     Rectangle2D dataArea,
                     PlotRenderingInfo info,
                     XYPlot plot,
                     ValueAxis domainAxis,
                     ValueAxis rangeAxis,
                     XYDataset dataset,
                     int series,
                     int item,
                     CrosshairState crosshairState,
                     int pass) {

    if (pass == 0) {
        drawItemPass0(g2, dataArea, info, plot, domainAxis, rangeAxis, 
                dataset, series, item, crosshairState);
    }
    else if (pass == 1) {
        drawItemPass1(g2, dataArea, info, plot, domainAxis, rangeAxis, 
                dataset, series, item, crosshairState);
    }

}
 
Example #15
Source File: XYLineChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #16
Source File: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return The chart.
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel,
        String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
        boolean legend, boolean tooltips, boolean urls) {

    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #17
Source File: ChartFactory.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a box and whisker chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A box and whisker chart.
 */
public static JFreeChart createBoxAndWhiskerChart(String title,
        String timeAxisLabel, String valueAxisLabel,
        BoxAndWhiskerXYDataset dataset, boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);
    XYBoxAndWhiskerRenderer renderer = new XYBoxAndWhiskerRenderer(10.0);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #18
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a high-low-open-close chart 
 * with a special timeline. This timeline can be a 
 * {@link org.jfree.chart.axis.SegmentedTimeline} such as the Monday 
 * through Friday timeline that will remove Saturdays and Sundays from
 * the axis.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param timeline  the timeline.
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A high-low-open-close chart.
 */
public static JFreeChart createHighLowChart(String title,
                                            String timeAxisLabel,
                                            String valueAxisLabel,
                                            OHLCDataset dataset,
                                            Timeline timeline,
                                            boolean legend) {

    DateAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setTimeline(timeline);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    HighLowRenderer renderer = new HighLowRenderer();
    renderer.setBaseToolTipGenerator(new HighLowItemLabelGenerator());
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example #19
Source File: ScatterPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #20
Source File: XYStepAreaRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultTableXYDataset dataset = new DefaultTableXYDataset();

        XYSeries s1 = new XYSeries("Series 1", true, false);
        s1.add(5.0, 5.0);
        s1.add(10.0, 15.5);
        s1.add(15.0, 9.5);
        s1.add(20.0, 7.5);
        dataset.addSeries(s1);

        XYSeries s2 = new XYSeries("Series 2", true, false);
        s2.add(5.0, 5.0);
        s2.add(10.0, 15.5);
        s2.add(15.0, 9.5);
        s2.add(20.0, 3.5);
        dataset.addSeries(s2);
        XYPlot plot = new XYPlot(dataset,
                new NumberAxis("X"), new NumberAxis("Y"),
                new XYStepAreaRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200,
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
 
Example #21
Source File: LegendTitleTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the equals() method distinguishes all fields.
 */
public void testEquals() {
    XYPlot plot1 = new XYPlot();
    LegendTitle t1 = new LegendTitle(plot1);
    LegendTitle t2 = new LegendTitle(plot1);
    assertEquals(t1, t2);

    t1.setBackgroundPaint(
        new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)
    );
    assertFalse(t1.equals(t2));
    t2.setBackgroundPaint(
        new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.yellow)
    );
    assertTrue(t1.equals(t2));

    t1.setLegendItemGraphicEdge(RectangleEdge.BOTTOM);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicEdge(RectangleEdge.BOTTOM);
    assertTrue(t1.equals(t2));

    t1.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicAnchor(RectangleAnchor.BOTTOM_LEFT);
    assertTrue(t1.equals(t2));

    t1.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT);
    assertFalse(t1.equals(t2));
    t2.setLegendItemGraphicLocation(RectangleAnchor.TOP_LEFT);
    assertTrue(t1.equals(t2));

    t1.setItemFont(new Font("Dialog", Font.PLAIN, 19));
    assertFalse(t1.equals(t2));
    t2.setItemFont(new Font("Dialog", Font.PLAIN, 19));
    assertTrue(t1.equals(t2));
}
 
Example #22
Source File: JPanelAnalysisTimeTemperature.java    From Course_Generator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Update the Time/Distance chart
 */
public void Refresh(TrackData track, CgSettings settings) {
	if (track == null)
		return;

	if (track.data.isEmpty())
		return;
	this.track = track;
	this.settings = settings;

	// -- Clear all series
	if (datasetElevTime.getSeriesCount() > 0)
		datasetElevTime.removeAllSeries();

	if (datasetTemperatureTime.getSeriesCount() > 0)
		datasetTemperatureTime.removeAllSeries();

	XYPlot plot = chart.getXYPlot();

	// -- Populate the series
	XYSeries serie1 = new XYSeries("Elevation/Time");
	XYSeries serie2 = new XYSeries("Temperature/Time");
	for (CgData r : track.data) {
		double x = r.getTotal(settings.Unit) / 1000;
		double y = r.getElevation(settings.Unit);
		serie1.add(x, y);
	}
	datasetElevTime.addSeries(serie1);
	datasetTemperatureTime.addSeries(serie2);

	if (track.getMaxElev(settings.Unit) > track.getMinElev(settings.Unit)) {
		ValueAxis axisYElev = plot.getRangeAxis(0);
		axisYElev.setRange(Math.floor(track.getMinElev(settings.Unit) / 100.0) * 100.0,
				Math.ceil(track.getMaxElev(settings.Unit) / 100.0) * 100.0);
	}

	chart = CreateChart(datasetElevTime, datasetTemperatureTime);
	RefreshInfo(0);
}
 
Example #23
Source File: GraphPanel.java    From swift-k with Apache License 2.0 5 votes vote down vote up
protected void removeSeries(JFreeChart chart, int seriesIndex) {
    Color color = (Color) chart.getPlot().getLegendItems().get(seriesIndex).getLinePaint();
    palette.release(color);
    String key = enabled.remove(seriesIndex);
    XYPlot plot = chart.getXYPlot();
    Series<?> series = sampler.getSeries(key);
    Unit unit = series.getUnit();
    
    Integer datasetIndex = datasetMapping.get(unit);
    TimeSeriesCollection col = (TimeSeriesCollection) plot.getDataset(datasetIndex);
    
    List<String> colIndices = seriesMapping.get(unit);
    int colIndex = colIndices.indexOf(key);
    colIndices.remove(key);
    
    col.removeSeries(colIndex);
    if (col.getSeriesCount() == 0) {
        plot.setDataset(datasetIndex, null);
        plot.setRangeAxis(datasetIndex, null);
        seriesMapping.remove(unit);
        datasetMapping.remove(unit);
    }
    
    rebuildLegend();
    repaint();
    gp.saveLayout();
}
 
Example #24
Source File: XYAreaRenderer2Test.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYAreaRenderer2 r = new XYAreaRenderer2();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example #25
Source File: GUIUtils.java    From egads with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a combined chart.
 *
 * @return The combined chart.
 */
private JFreeChart createCombinedChart(DataSequence tsOne, DataSequence tsTwo, ArrayList<Anomaly> anomalyList) {

    // create subplot 1.
    final XYDataset data1 = createDataset(tsOne, "Original");
    final XYItemRenderer renderer1 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis1 = new NumberAxis("Original Value");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    
    // plot anomalies on subplot 1.
    addAnomalies(subplot1, anomalyList);
    
    // create subplot 2.
    final XYDataset data2 = createDataset(tsTwo, "Forecast");
    final XYItemRenderer renderer2 = new StandardXYItemRenderer();
    final NumberAxis rangeAxis2 = new NumberAxis("Forecast Value");
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot.
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Time"));
    plot.setGap(10.0);
    
    // add the subplots.
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    
    // Add anomaly score time-series.
    addAnomalyTS(plot, tsOne, tsTwo);
    
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot.
    return new JFreeChart("EGADS GUI",
                          JFreeChart.DEFAULT_TITLE_FONT,
                          plot,
                          true);
}
 
Example #26
Source File: XYLineChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  super.configureChart( chart );

  final XYPlot xypl = chart.getXYPlot();
  final XYItemRenderer renderer = xypl.getRenderer();
  renderer.setStroke( translateLineStyle( lineWidth, lineStyle ) );
  if ( renderer instanceof XYLineAndShapeRenderer ) {
    final XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) renderer;
    renderer1.setShapesVisible( isMarkersVisible() );
    renderer1.setBaseShapesFilled( isMarkersVisible() );
  }

}
 
Example #27
Source File: XYAreaRendererTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYAreaRenderer r = new XYAreaRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example #28
Source File: LegendTitleTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
@Test
public void testHashcode() {
    XYPlot plot1 = new XYPlot();
    LegendTitle t1 = new LegendTitle(plot1);
    LegendTitle t2 = new LegendTitle(plot1);
    assertTrue(t1.equals(t2));
    int h1 = t1.hashCode();
    int h2 = t2.hashCode();
    assertEquals(h1, h2);
}
 
Example #29
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 5 votes vote down vote up
public JFreeChart scatterPlot(String xAxisLabel,String yAxisLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xAxisLabel
            , yAxisLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    switch(seriesTypes.get(0)){
            case DOTS:
                plot.setRenderer(0, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(0, new XYLineAndShapeRenderer(true, true));
                break;
        }
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        switch(seriesTypes.get(i)){
            case DOTS:
                plot.setRenderer(i, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
                break;
        }
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example #30
Source File: CandlestickRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialises the renderer then returns the number of 'passes' through the
 * data that the renderer will require (usually just one).  This method
 * will be called before the first item is rendered, giving the renderer
 * an opportunity to initialise any state information it wants to maintain.
 * The renderer can do nothing if it chooses.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param plot  the plot.
 * @param dataset  the data.
 * @param info  an optional info collection object to return data back to
 *              the caller.
 *
 * @return The number of passes the renderer requires.
 */
@Override
public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea,
        XYPlot plot, XYDataset dataset, PlotRenderingInfo info) {

    // calculate the maximum allowed candle width from the axis...
    ValueAxis axis = plot.getDomainAxis();
    double x1 = axis.getLowerBound();
    double x2 = x1 + this.maxCandleWidthInMilliseconds;
    RectangleEdge edge = plot.getDomainAxisEdge();
    double xx1 = axis.valueToJava2D(x1, dataArea, edge);
    double xx2 = axis.valueToJava2D(x2, dataArea, edge);
    this.maxCandleWidth = Math.abs(xx2 - xx1);
        // Absolute value, since the relative x
        // positions are reversed for horizontal orientation

    // calculate the highest volume in the dataset...
    if (this.drawVolume) {
        OHLCDataset highLowDataset = (OHLCDataset) dataset;
        this.maxVolume = 0.0;
        for (int series = 0; series < highLowDataset.getSeriesCount();
             series++) {
            for (int item = 0; item < highLowDataset.getItemCount(series);
                 item++) {
                double volume = highLowDataset.getVolumeValue(series, item);
                if (volume > this.maxVolume) {
                    this.maxVolume = volume;
                }

            }
        }
    }

    return new XYItemRendererState(info);
}