Example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer

List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer.

Prototype

public XYLineAndShapeRenderer() 

Source Link

Document

Creates a new renderer with both lines and shapes visible.

Usage

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

/**
 * Creates a sample chart./*  w w w.j a v a2  s . c  o m*/
 *
 * @param dataset  a dataset for the chart.
 *
 * @return A sample chart.
 */
private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    xAxis.setLowerMargin(0.2);
    xAxis.setUpperMargin(0.2);
    xAxis.setStandardTickUnits(createStandardDateTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLowerMargin(0.2);
    yAxis.setUpperMargin(0.2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseLinesVisible(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesShape(1, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5.0f,
            new float[] { 10.0f, 5.0f }, 0.0f));
    renderer.setSeriesFillPaint(0, Color.white);
    renderer.setSeriesFillPaint(1, Color.white);
    renderer.setUseFillPaint(true);

    renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);

    renderer.addAnnotation(new XYDrawableAnnotation(new Month(4, 2005).getFirstMillisecond(), 600, 180, 100,
            3.0, createPieChart()));
    renderer.addAnnotation(new XYDrawableAnnotation(new Month(9, 2007).getFirstMillisecond(), 1250, 120, 100,
            2.0, createBarChart()));
    plot.setRenderer(renderer);
    return chart;
}

From source file:no.ntnu.mmfplanner.ui.graph.SaNpvChart.java

/**
 * Creates the chart//from   w ww  .ja va2  s. c  o  m
 */
private void createChart() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            "Period", // x axis label
            "Discounted Cash", // y axis label
            null, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getDomainAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    setChart(chart);
    setMouseZoomable(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setLegendLine(new Rectangle2D.Double(0.0, 0.0, 6.0, 0.0));
    renderer.setUseFillPaint(true);

    // the x=0 line
    renderer.setSeriesPaint(0, Color.GRAY);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesVisibleInLegend(0, new Boolean(false));

    plot.setRenderer(renderer);
}

From source file:org.jfree.chart.demo.XYLineAndShapeRendererDemo.java

/**
 * Constructs the demo application./*from  ww  w  . ja v a  2 s.com*/
 *
 * @param title  the frame title.
 */
public XYLineAndShapeRendererDemo(final String title) {

    super(title);
    XYDataset dataset = createSampleDataset();
    JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", dataset, PlotOrientation.VERTICAL, true,
            false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, true);
    plot.setRenderer(renderer);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));
    setContentPane(chartPanel);

}

From source file:org.uncommons.maths.demo.GraphPanel.java

public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues,
        double expectedMean, double expectedStandardDeviation, boolean discrete) {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries observedSeries = new XYSeries("Observed");
    dataSet.addSeries(observedSeries);//from  w w w .j  av  a2  s.c o  m
    XYSeries expectedSeries = new XYSeries("Expected");
    dataSet.addSeries(expectedSeries);

    for (Map.Entry<Double, Double> entry : observedValues.entrySet()) {
        observedSeries.add(entry.getKey(), entry.getValue());
    }

    for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) {
        expectedSeries.add(entry.getKey(), entry.getValue());
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    if (discrete) {
        // Render markers at each data point (these discrete points are the
        // distibution, not the lines between them).
        plot.setRenderer(new XYLineAndShapeRenderer());
    } else {
        // Render smooth lines between points for a continuous distribution.
        XYSplineRenderer renderer = new XYSplineRenderer();
        renderer.setBaseShapesVisible(false);
        plot.setRenderer(renderer);
    }

    chartPanel.setChart(chart);
}

From source file:tp2.FCFS.java

@Override
public void printGraph(String filename) {
    int i;//from   w w w. ja  v  a 2  s  .co m
    int y_axis = requestString.length * 10;

    XYSeries series = new XYSeries("FCFS");

    /* Adiciona o pontos XY do grfico de linhas. */
    series.add(y_axis, initCilindro);

    for (i = 0; i < requestString.length; i++) {
        series.add(y_axis - ((i + 1) * 10), requestString[i]);
    }

    /* Adiciona a serie criada a um SeriesCollection. */
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);

    /* Gera o grfico de linhas */
    JFreeChart chart = ChartFactory.createXYLineChart(
            /* Title */
            "FCFS Scheduler Algorithm",
            /* Title x*/
            "",
            /* Title y */
            "Cilindro", dataset,
            /* Plot Orientation */
            PlotOrientation.HORIZONTAL,
            /* Show Legend */
            false,
            /* Use tooltips */
            false,
            /* Configure chart to generate URLs? */
            false);

    /* Configura a espessura da linha do grfico  */
    XYPlot plot = chart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    plot.setRenderer(renderer);

    /* Escreve o grfico para um arquivo indicado. */
    try {
        ChartUtilities.saveChartAsJPEG(new File(filename), chart, 500, 300);
    } catch (IOException ex) {
        Logger.getLogger(FCFS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:no.uio.medicine.virsurveillance.charts.XYLineChart_AWT.java

public XYLineChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<Float>> dataPoints, ArrayList<ArrayList<Float>> xAxis, ArrayList<String> titles) {
    super(applicationTitle);

    this.xAxis = xAxis;
    this.dataPoints = dataPoints;
    this.titles = titles;

    if (this.dataPoints.size() != xAxis.size() && this.dataPoints.size() != titles.size()) {
        System.out.println("Error: Data size not match");
    }/*w w  w . j  av a2s . c o m*/

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;

    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, this.yAxisTitle, this.xAxisTitle,
            createDataset(this.dataPoints, this.xAxis, this.titles), PlotOrientation.VERTICAL, true, true,
            false);

    this.chartPanel = new ChartPanel(xylineChart);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    this.plot = xylineChart.getXYPlot();
    this.renderer = new XYLineAndShapeRenderer();

    for (int i = 0; i < this.dataPoints.size(); i++) {
        this.renderer.setSeriesPaint(i, getColor(i));
    }

    //renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    //renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    //renderer.setSeriesStroke(2, new BasicStroke(2.0f));JOU
    this.plot.setRenderer(this.renderer);
    this.setContentPane(this.chartPanel);
    this.setDefaultCloseOperation(HIDE_ON_CLOSE);

}

From source file:org.jfree.chart.demo.LineChart.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//from   w w  w .  ja v  a  2 s.  co  m

    chart.setBackgroundPaint(Color.white);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;

}

From source file:temp1.RealTimeChart.java

public static JFreeChart createChart(String chartContent, String title, String yaxisName) {
    thread1 = new Thread();
    timeseries1 = new TimeSeries(chartContent, Millisecond.class);
    timeseries2 = new TimeSeries(chartContent, Millisecond.class);
    timeseries3 = new TimeSeries(chartContent, Millisecond.class);
    timeseries4 = new TimeSeries(chartContent, Millisecond.class);

    TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeseries1);
    TimeSeriesCollection timeseriescollection1 = new TimeSeriesCollection(timeseries2);
    TimeSeriesCollection timeseriescollection2 = new TimeSeriesCollection(timeseries3);
    TimeSeriesCollection timeseriescollection3 = new TimeSeriesCollection(timeseries4);

    jfreechart = ChartFactory.createTimeSeriesChart("", "", "", timeseriescollection, false, false, false);

    final XYPlot xyplot = jfreechart.getXYPlot();
    xyplot.setOutlinePaint(Color.magenta);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setRangeGridlinePaint(Color.gray);
    xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setAutoRange(true);//w  w w  .j  a  v a  2 s.co  m
    valueaxis.setFixedAutoRange(20000D);
    //Value
    valueaxis = xyplot.getRangeAxis();
    valueaxis.setRange(800D, 3300D);
    xyplot.setDataset(0, timeseriescollection);
    xyplot.setDataset(1, timeseriescollection1);
    xyplot.setDataset(2, timeseriescollection2);
    xyplot.setDataset(3, timeseriescollection3);
    XYLineAndShapeRenderer xylineandshaperenderer0 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer();
    XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer();
    xylineandshaperenderer0.setBaseShapesVisible(false);
    xylineandshaperenderer1.setBaseShapesVisible(false);
    xylineandshaperenderer2.setBaseShapesVisible(false);
    xylineandshaperenderer3.setBaseShapesVisible(false);
    xylineandshaperenderer0.setSeriesPaint(0, Color.RED);
    xylineandshaperenderer1.setSeriesPaint(0, Color.cyan);
    xylineandshaperenderer2.setSeriesPaint(0, Color.yellow);
    xylineandshaperenderer3.setSeriesPaint(0, Color.blue);
    xyplot.setRenderer(0, xylineandshaperenderer0);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    xyplot.setRenderer(2, xylineandshaperenderer2);
    xyplot.setRenderer(3, xylineandshaperenderer3);
    //xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(0.5F, 1, 1, 5F, new float[] { 5F, 10F }, 0.0F));
    return jfreechart;
}

From source file:adams.gui.visualization.jfreechart.chart.ScatterPlot.java

/**
 * Performs the actual generation of the chart.
 *
 * @param data   the data to use/*from   www.j a  va  2 s.  co  m*/
 * @return      the chart
 */
@Override
protected JFreeChart doGenerate(XYDataset data) {
    JFreeChart result = ChartFactory.createScatterPlot(m_Title, m_LabelX, m_LabelY, data,
            m_Orientation.getOrientation(), m_Legend, m_ToolTips, false);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    if (result.getXYPlot().getSeriesCount() == 2) {
        renderer.setSeriesLinesVisible(0, false);
        renderer.setSeriesLinesVisible(1, true);
        renderer.setSeriesShapesVisible(0, true);
        renderer.setSeriesShapesVisible(1, false);
        result.getXYPlot().setRenderer(renderer);
    }
    return result;
}

From source file:physical_network.OscilloscopePanel.java

public OscilloscopePanel() {

    super("Oscilloscope");

    // Set initial (time, voltage) datapoint of (0.0, 0.0).
    voltages.add(0.0, 0.0);//from   w w  w  .ja v a 2  s  .  c om

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(voltages);

    JFreeChart chart = ChartFactory.createXYLineChart("Oscilloscope", "Time (seconds)", "Voltage", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot plot = (XYPlot) chart.getPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);

    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setRange(0.0, 10.0);
    domain.setTickUnit(new NumberTickUnit(1.0));
    domain.setVerticalTickLabels(true);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(-5.0, 5.0);
    range.setTickUnit(new NumberTickUnit(1.0));

    plot.setRenderer(renderer);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 300));

    setContentPane(chartPanel);
}