org.jfree.chart.renderer.xy.XYLineAndShapeRenderer Java Examples

The following examples show how to use org.jfree.chart.renderer.xy.XYLineAndShapeRenderer. 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: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
@Test
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #2
Source File: ChartFactory.java    From ECG-Viewer with GNU General Public License v2.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 #3
Source File: ChartFactory.java    From astor with GNU General Public License v2.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 legend  a flag specifying whether or not a legend is required.
 *
 * @return The chart.
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel,
        String yAxisLabel, XYDataset dataset, boolean legend) {

    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);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #4
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
@Test 
public void testGetRendererForDataset2() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    // add a second dataset
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(new XYSeries("Series in dataset 2"));
    plot.setDataset(99, dataset2);
   
    // by default, the renderer with index 0 is used
    assertEquals(renderer, plot.getRendererForDataset(dataset2));
    
    // add a second renderer with the same index as dataset2, now it will
    // be used
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(99, renderer);
    assertEquals(renderer2, plot.getRendererForDataset(dataset2));
}
 
Example #5
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 #6
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void loadMVWAPIndicator(String key) throws XPathException{
    int timeFrameMVWAP = Integer.parseInt(parameter.getParameter(key, "Time Frame VWAP"));
    int timeFrameVWAP = Integer.parseInt(parameter.getParameter(key, "Time Frame MVWAP"));

    VWAPIndicator vwap = new VWAPIndicator(series.get(),timeFrameVWAP);
    MVWAPIndicator mvwap = new MVWAPIndicator(vwap,timeFrameMVWAP);

    List<Indicator> ilVwap = new ArrayList<>();
    List<String> nlVwap = new ArrayList<>();

    XYLineAndShapeRenderer wapRenderer = createRenderer(key, "Color MVWAP", "Shape MVWAP", "Stroke MVWAP");
    Color vwapColor = ConverterUtils.ColorAWTConverter.fromString(parameter.getParameter(key, "Color VWAP"));
    
    StrokeType vwapStroke = StrokeType.valueOf(parameter.getParameter(key, "Stroke VWAP"));
    ShapeType vwapShape = ShapeType.valueOf(parameter.getParameter(key, "Shape VWAP"));
    wapRenderer.setSeriesPaint(1, vwapColor);
    wapRenderer.setSeriesStroke(1, vwapStroke.stroke);
    wapRenderer.setSeriesShape(1, vwapShape.shape);
    IndicatorCategory category = parameter.getCategory(key);
    ChartType chartType = parameter.getChartType(key);
    ilVwap.add(mvwap);
    ilVwap.add(vwap);
    nlVwap.add(String.format("%s [%s] (%s)",getIdentifier(key), getID(key), timeFrameMVWAP));
    nlVwap.add(String.format("%s [%s] (%s)","VWAP", getID(key), timeFrameVWAP));
    addChartIndicator(key, ilVwap, nlVwap,"MVWAP/VWAP ",wapRenderer, chartType.toBoolean(), category);
}
 
Example #7
Source File: ChartFactory.java    From ccu-historian 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 #8
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDomainMarkerIndices() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second x axis
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(new XYSeries("Series in dataset 2"));
    plot.setDataset(99, dataset);    
    NumberAxis xAxis2 = new NumberAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToDomainAxis(99, 1);
    
    ValueMarker xMarker1 = new ValueMarker(123);
    plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
    assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(
            xMarker1));
}
 
Example #9
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testRangeMarkerIndices() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second axis
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(new XYSeries("Series in dataset 2"));
    plot.setDataset(99, dataset);    
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToRangeAxis(99, 1);
    
    ValueMarker yMarker1 = new ValueMarker(123);
    plot.addRangeMarker(99, yMarker1, Layer.FOREGROUND);
    assertTrue(plot.getRangeMarkers(99, Layer.FOREGROUND).contains(yMarker1));
}
 
Example #10
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a time series chart.  A time series chart is an
 * {@link XYPlot} with a {@link DateAxis} for the x-axis and a
 * {@link NumberAxis} for the y-axis.  The default renderer is an
 * {@link XYLineAndShapeRenderer}. A convenient dataset to use with this
 * chart is a {@link TimeSeriesCollection}.
 *
 * @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 time series chart.
 */
public static JFreeChart createTimeSeriesChart(String title,
        String timeAxisLabel, String valueAxisLabel, XYDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    timeAxis.setLowerMargin(0.02);  // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    valueAxis.setAutoRangeIncludesZero(false);  // override default
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    XYToolTipGenerator toolTipGenerator = null;
    toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,
            false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    plot.setRenderer(renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #11
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
@Test 
public void testGetRendererForDataset2() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    // add a second dataset
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(new XYSeries("Series in dataset 2"));
    plot.setDataset(99, dataset2);
   
    // by default, the renderer with index 0 is used
    assertEquals(renderer, plot.getRendererForDataset(dataset2));
    
    // add a second renderer with the same index as dataset2, now it will
    // be used
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(99, renderer);
    assertEquals(renderer2, plot.getRendererForDataset(dataset2));
}
 
Example #12
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
@Test 
public void testRendererIndices() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    
    assertEquals(renderer, plot.getRenderer(0));
    
    // we should be able to give a renderer an arbitrary index
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(20, renderer2);
    assertEquals(2, plot.getRendererCount());
    assertEquals(renderer2, plot.getRenderer(20));
    
    assertEquals(20, plot.getIndexOf(renderer2));
}
 
Example #13
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    boolean success = false;
    try {
        BufferedImage image = new BufferedImage(200 , 100, 
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
 
Example #14
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
public static JFreeChart createFunctionChart(String title,
                                             String xAxisLabel,
                                             String yAxisLabel,
                                             XYDataset dataset,
                                             boolean legend,
                                             boolean tooltips) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    FunctionPlot plot = new FunctionPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }

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

    return chart;
}
 
Example #15
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDomainMarkerIndices() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second x axis
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(new XYSeries("Series in dataset 2"));
    plot.setDataset(99, dataset);    
    NumberAxis xAxis2 = new NumberAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToDomainAxis(99, 1);
    
    ValueMarker xMarker1 = new ValueMarker(123);
    plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
    assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(
            xMarker1));
}
 
Example #16
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
public JFreeChart scatterGridPlot(String xLabel, String yLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xLabel
            , yLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    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);
        plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example #17
Source File: ChartIndicator.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constuctor to create a ChartIndicator instance for just one {@link Indicator}
 * @param indicator the ta4j indicator
 * @param name the name colorOf the indicator (with parameters)
 * @param renderer the renderer for line, shape etc.
 * @param isSubchart true if the ChartIndicator should be plotted as subchart
 * @param c the category colorOf the indicator in the menu colorOf this application
 */
public ChartIndicator(Indicator<Type> indicator, String name, XYLineAndShapeRenderer renderer, boolean isSubchart, IndicatorCategory c){
    indicators = new ArrayList<>();
    indicatorsNames = new ArrayList<>();
    indicators.add(indicator);
    indicatorsNames.add(name);
    generalName = name;
    this.renderer = renderer;
    this.isSubchart = isSubchart;
    category = c;
}
 
Example #18
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Renderers that belong to the plot are being cloned but they are
 * retaining a reference to the original plot.
 */
@Test
public void testBug2817504() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot();
    XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer();
    p1.setRenderer(r1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // check for independence
    XYLineAndShapeRenderer r2 = (XYLineAndShapeRenderer) p2.getRenderer();
    assertTrue(r2.getPlot() == p2);
}
 
Example #19
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 5 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) {

    if (orientation == null) {
        throw new IllegalArgumentException("Null 'orientation' argument.");
    }
    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.setBaseURLGenerator(new StandardXYURLGenerator());
    }

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

    return chart;

}
 
Example #20
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    // check the case where there is a secondary dataset that doesn't
    // have a renderer (i.e. falls back to renderer 0)
    XYDataset d0 = createDataset1();
    XYDataset d1 = createDataset2();
    XYItemRenderer r0 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot();
    plot.setDataset(0, d0);
    plot.setDataset(1, d1);
    plot.setRenderer(0, r0);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
}
 
Example #21
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
@Test
public void testSetRenderer() {
    XYPlot plot = new XYPlot();
    XYItemRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
 
Example #22
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    // check the case where there is a secondary dataset that doesn't
    // have a renderer (i.e. falls back to renderer 0)
    XYDataset d0 = createDataset1();
    XYDataset d1 = createDataset2();
    XYItemRenderer r0 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot();
    plot.setDataset(0, d0);
    plot.setDataset(1, d1);
    plot.setRenderer(0, r0);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
}
 
Example #23
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void loadPVIIndicator(String key) throws XPathExpressionException {
    IndicatorCategory category = parameter.getCategory(key);
    ChartType chartType = parameter.getChartType(key);
    XYLineAndShapeRenderer renderer = createRenderer(key, "Color", "Shape", "Stroke");

    addChartIndicator(key,
            new PVIIndicator(series.get()),
            String.format("%s [%s]",getIdentifier(key), getID(key)),
            renderer,
            chartType.toBoolean(),
            category);
}
 
Example #24
Source File: XYPlotTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Renderers that belong to the plot are being cloned but they are
 * retaining a reference to the original plot.
 */
@Test
public void testBug2817504() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot();
    XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer();
    p1.setRenderer(r1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // check for independence
    XYLineAndShapeRenderer r2 = (XYLineAndShapeRenderer) p2.getRenderer();
    assertTrue(r2.getPlot() == p2);
}
 
Example #25
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void loadOnBalanceVolumeIndicator(String key) throws XPathExpressionException {
    IndicatorCategory category = parameter.getCategory(key);
    ChartType chartType = parameter.getChartType(key);
    XYLineAndShapeRenderer renderer = createRenderer(key, "Color", "Shape", "Stroke");

    addChartIndicator(key,
            new OnBalanceVolumeIndicator(series.get()),
            String.format("%s [%s]",getIdentifier(key), getID(key)),
            renderer,
            chartType.toBoolean(),
            category);
}
 
Example #26
Source File: XYBoxAnnotationTest.java    From ccu-historian with GNU General Public License v3.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.
 */
public void testDrawWithNullInfo() {
    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 XYLineAndShapeRenderer());
        plot.addAnnotation(new XYBoxAnnotation(10.0, 12.0, 3.0, 4.0,
                new BasicStroke(1.2f), Color.red, Color.blue));
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200,
                null);
    }
    catch (NullPointerException e) {
        fail("No exception should be triggered.");
    }
}
 
Example #27
Source File: Scatter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private void setShapeLinesVisibility( XYPlot plot ) {
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    int seriesCount = plot.getSeriesCount();
    for( int i = 0; i < seriesCount; i++ ) {
        if (showShapes != null) {
            renderer.setSeriesShapesVisible(i, showShapes.get(i));
        }
        if (showLines != null) {
            renderer.setSeriesLinesVisible(i, showLines.get(i));
        }
    }
}
 
Example #28
Source File: DomLineChart.java    From DominionSim with MIT License 5 votes vote down vote up
private JFreeChart createChart(XYDataset dataset) {
        JFreeChart chart = ChartFactory.createXYLineChart(
            myType.equals("VP")? "Average Victory Points gained/turn" : "Average $ generated/turn",      // chart title
            "turns",                      // x axis label
            myType.equals("VP")? "VP gained" : "available money",                      // y axis label
            dataset,                  // data
            PlotOrientation.VERTICAL,
            true,                     // include legend
            true,                     // tooltips
            false                     // urls
        );
//        chart.setBackgroundPaint(Color.darkGray);
//        final StandardLegend legend = (StandardLegend) chart.getLegend();
  //      legend.setDisplaySeriesShapes(true);
        // get a reference to the plot for further customisation...
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.white);
//        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
        plot.setDomainGridlinePaint(Color.black);
        plot.setRangeGridlinePaint(Color.black);
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setSeriesPaint(0,Color.black);
        renderer.setSeriesPaint(1,Color.blue);
        renderer.setSeriesPaint(2,Color.red);
        renderer.setSeriesPaint(3,Color.cyan);
        renderer.setBaseShapesVisible(true);
        plot.setRenderer(renderer);
        // change the auto tick unit selection to integer units only...
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//        domainAxis.setTickUnit( new NumberTickUnit( 1 ) );
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//        rangeAxis.setTickUnit( new NumberTickUnit( 1 ) );
                
        return chart;
	}
 
Example #29
Source File: ChartUtils.java    From PDV with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set line style
 * @param plot XYPlot
 */
public static void setLineRender(XYPlot plot) {
    plot.setInsets(new RectangleInsets(10, 10, 0, 10), false);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    renderer.setLegendItemToolTipGenerator(
            new StandardXYSeriesLabelGenerator("Legend {0}"));

    setXAixs(plot);
    setYAixs(plot);
}
 
Example #30
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests cloning to ensure that the cloned plot is registered as a listener
 * on the cloned renderer.
 */
@Test
public void testCloning4() throws CloneNotSupportedException {
    XYLineAndShapeRenderer r1 = new XYLineAndShapeRenderer();
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), r1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // verify that the plot is listening to the cloned renderer
    XYLineAndShapeRenderer r2 = (XYLineAndShapeRenderer) p2.getRenderer();
    assertTrue(r2.hasListener(p2));
}