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

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

Introduction

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

Prototype

public Paint getSeriesPaint(int series) 

Source Link

Document

Returns the paint used to color an item drawn by the renderer.

Usage

From source file:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java

private void plotCompare() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    XYSeries xyBoundsPositive = null;//from   w  w  w  .jav a2  s.com
    XYSeries xyBoundsNegative = null;
    Trace[] posNeg = null;

    Component[] siblings = this.getParent().getComponents();
    Trace[] allTraces = new Trace[siblings.length];

    int rows = tableWindowSize.getRowCount();
    double coverage = 0.99;
    int wsize = 100;
    for (int i = 0; i < rows; i++) {
        try {
            wsize = (Integer) tableWindowSize.getValueAt(i, 0);
            coverage = (Double) tableWindowSize.getValueAt(i, 1);
        } catch (NullPointerException e) {
            //Ignore: cell value is null
            ;
        }
    }

    for (int i = 0; i < siblings.length; i++) {
        allTraces[i] = ((TracePanel) siblings[i]).getTrace();

        if (allTraces[i].hasNegativeValues()) {
            posNeg = allTraces[i].splitPositiveNegative();
            xyBoundsPositive = Plotter.arrayToSeries(posNeg[0].getDynamicBound(coverage, wsize),
                    allTraces[i].getName(), wsize - 1);
            xyBoundsNegative = Plotter.arrayToSeriesInvert(posNeg[1].getDynamicBound(coverage, wsize),
                    allTraces[i].getName() + "(neg)", wsize - 1);
            dataset.addSeries(xyBoundsPositive);
            dataset.addSeries(xyBoundsNegative);
        } else {
            dataset.addSeries(Plotter.arrayToSeries(allTraces[i].getDynamicBound(coverage, wsize),
                    allTraces[i].getName(), wsize - 1));
        }
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("Comparative Plot (c=" + coverage + ",w=" + wsize + ")",
            // Title
            "Time Point",
            // x-axis Labels
            "Value",
            // y-axis Label
            dataset,
            // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true,
            // Show Legend
            true,
            // Use tooltips
            false
    // Configure chart to generate URLs?
    );

    chart.setBackgroundPaint(Color.WHITE);
    chart.getXYPlot().setBackgroundPaint(ChartColor.VERY_LIGHT_YELLOW);
    chart.getXYPlot().setBackgroundAlpha(0.05f);
    chart.getXYPlot().setRangeGridlinePaint(Color.LIGHT_GRAY);
    chart.getXYPlot().setDomainGridlinePaint(Color.LIGHT_GRAY);

    chart.getTitle().setFont(new Font("Dialog", Font.BOLD, 14));

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setDrawSeriesLineAsPath(true);
    chart.getXYPlot().setRenderer(renderer);

    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesPaint(1, ChartColor.DARK_GREEN);
    renderer.setSeriesPaint(2, ChartColor.DARK_BLUE);
    renderer.setSeriesPaint(3, ChartColor.RED);

    int nSeries = chart.getXYPlot().getSeriesCount();
    for (int i = 0; i < nSeries; i++) {
        renderer.setSeriesShapesVisible(i, false);
    }
    if (posNeg != null) {
        renderer.setSeriesVisibleInLegend(5, false);
        renderer.setSeriesPaint(5, renderer.getSeriesPaint(4));
    }

    //      Stroke plainStroke = new BasicStroke(
    //                    1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f
    //                );
    //      
    //      renderer.setSeriesStroke(0, plainStroke);
    //      renderer.setSeriesStroke(1, 
    //            new BasicStroke(
    //                 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 3.0f }, 0.0f
    //             ));
    //      renderer.setSeriesStroke(2, 
    //            new BasicStroke(
    //                 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 3.0f, 0.5f, 3.0f }, 0.0f
    //             ));
    //      renderer.setSeriesStroke(3, 
    //            new BasicStroke(
    //                 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 3.0f }, 0.0f
    //             ));

    JPanel plotPanel = new ChartPanel(chart);
    JFrame plotFrame = new JFrame();
    plotFrame.add(plotPanel);
    plotFrame.setVisible(true);
    plotFrame.pack();
    plotFrame.setTitle(TracePanel.this.trace.getName());
    plotFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

From source file:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java

private void plotTrace() {
    XYSeriesCollection dataset = new XYSeriesCollection();

    XYSeries xyBoundsPositive = null;//from w  ww.j  ava  2  s  .co m
    XYSeries xyBoundsNegative = null;
    Trace[] posNeg = null;

    dataset.addSeries(Plotter.traceToSeries(trace));
    dataset.addSeries(Plotter.valueToSeries(trace.getMax(), "Max", trace.getSampleSize()));
    dataset.addSeries(Plotter.valueToSeries(trace.getAverage(), "Average", trace.getSampleSize()));
    dataset.addSeries(Plotter.valueToSeries(trace.getMin(), "Min", trace.getSampleSize()));

    int rows = tableWindowSize.getRowCount();
    double coverage;
    int wsize;
    for (int i = 0; i < rows; i++) {
        try {
            wsize = (Integer) tableWindowSize.getValueAt(i, 0);
            coverage = (Double) tableWindowSize.getValueAt(i, 1);

            if (trace.hasNegativeValues()) {
                posNeg = trace.splitPositiveNegative();
                xyBoundsPositive = Plotter.arrayToSeries(posNeg[0].getDynamicBound(coverage, wsize),
                        "c=" + coverage + ",w=" + wsize, wsize - 1);
                xyBoundsNegative = Plotter.arrayToSeriesInvert(posNeg[1].getDynamicBound(coverage, wsize),
                        "c=" + coverage + ",w=" + wsize + "(neg)", wsize - 1);
                dataset.addSeries(xyBoundsPositive);
                dataset.addSeries(xyBoundsNegative);
            } else {
                dataset.addSeries(Plotter.arrayToSeries(trace.getDynamicBound(coverage, wsize),
                        "c=" + coverage + ",w=" + wsize, wsize - 1));
            }
        } catch (NullPointerException e) {
            //Ignore: cell value is null
            ;
        }
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(trace.getName(),
            // Title
            "Time Point",
            // x-axis Labels
            "Value",
            // y-axis Label
            dataset,
            // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true,
            // Show Legend
            true,
            // Use tooltips
            false
    // Configure chart to generate URLs?
    );

    chart.setBackgroundPaint(Color.WHITE);
    chart.getXYPlot().setBackgroundPaint(ChartColor.VERY_LIGHT_YELLOW);
    chart.getXYPlot().setBackgroundAlpha(0.05f);
    chart.getXYPlot().setRangeGridlinePaint(Color.LIGHT_GRAY);
    chart.getXYPlot().setDomainGridlinePaint(Color.LIGHT_GRAY);

    chart.getTitle().setFont(new Font("Dialog", Font.BOLD, 14));

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setDrawSeriesLineAsPath(true);
    chart.getXYPlot().setRenderer(renderer);

    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesPaint(1, ChartColor.DARK_BLUE);
    renderer.setSeriesPaint(2, ChartColor.DARK_GRAY);
    renderer.setSeriesPaint(3, ChartColor.DARK_BLUE);
    renderer.setSeriesPaint(4, ChartColor.RED);

    int nSeries = chart.getXYPlot().getSeriesCount();
    for (int i = 0; i < nSeries; i++) {
        renderer.setSeriesShapesVisible(i, false);
    }
    if (posNeg != null) {
        renderer.setSeriesVisibleInLegend(5, false);
        renderer.setSeriesPaint(5, renderer.getSeriesPaint(4));
    }

    Stroke plainStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f);

    renderer.setSeriesStroke(0, plainStroke);
    renderer.setSeriesStroke(1, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 3.0f }, 0.0f));
    renderer.setSeriesStroke(2, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 3.0f, 0.5f, 3.0f }, 0.0f));
    renderer.setSeriesStroke(3, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 3.0f }, 0.0f));

    JPanel plotPanel = new ChartPanel(chart);
    JFrame plotFrame = new JFrame();
    plotFrame.add(plotPanel);
    plotFrame.setVisible(true);
    plotFrame.pack();
    plotFrame.setTitle(TracePanel.this.trace.getName());
    plotFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

From source file:org.operamasks.faces.render.graph.LineChartRenderer.java

private void setSeriesLineStyles(XYLineAndShapeRenderer renderer, UIChart comp, int index, UIDataItem item) {
    Boolean drawLines = item.getDrawLines();
    if (drawLines != null) {
        renderer.setSeriesLinesVisible(index, drawLines);
    }/* w  w w. ja v  a2 s .  com*/

    Float lineWidth = item.getLineWidth();
    LineStyleType lineStyle = item.getLineStyle();
    if (lineWidth == null)
        lineWidth = comp.getLineWidth();
    if (lineStyle == null)
        lineStyle = comp.getLineStyle();
    if (lineWidth != null || lineStyle != null) {
        if (lineWidth == null)
            lineWidth = 1.0f;
        renderer.setSeriesStroke(index, createLineStroke(lineWidth, lineStyle));
    }

    Boolean drawMarkers = item.getDrawMarkers();
    if (drawMarkers != null) {
        renderer.setSeriesShapesVisible(index, drawMarkers);
    }

    Boolean fillMarkers = item.getFillMarkers();
    if (fillMarkers != null) {
        renderer.setSeriesShapesFilled(index, fillMarkers);
    }

    Paint markerFillColor = item.getMarkerFillColor();
    if (markerFillColor == null) {
        markerFillColor = comp.getMarkerFillColor();
        if (markerFillColor == null)
            markerFillColor = renderer.getSeriesPaint(index);
    }
    renderer.setSeriesFillPaint(index, markerFillColor);
}

From source file:cs.cirg.cida.CIDAView.java

@Action
public void changeSeriesColor() {
    SeriesPair series = (SeriesPair) lineSeriesComboBox.getSelectedItem();
    JFreeChart chart = ((ChartPanel) chartPanel).getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(series.getKey(), JColorChooser.showDialog(this.getFrame(),
            CIDAConstants.DIALOG_CHOOSE_COLOR_MSG, (Color) renderer.getSeriesPaint(series.getKey())));
}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

/**
 * ?jfreechart/*from   w w w.  jav a2  s.co  m*/
 */
public void initChart() {
    ts_LP = new TimeSeries("LowPressure", Millisecond.class);
    ts_HP = new TimeSeries("HighPressure", Millisecond.class);
    ts_humidity = new TimeSeries("Humidity", Millisecond.class);
    ts_temprature = new TimeSeries("Temperature", Millisecond.class);
    ts_time = new TimeSeries("TestTime", Millisecond.class);
    ts_num = new TimeSeries("num", Millisecond.class);
    ts_reserved1 = new TimeSeries("reserved1", Millisecond.class);
    ts_reserved2 = new TimeSeries("reserved2", Millisecond.class);
    ts_reserved3 = new TimeSeries("reserved3", Millisecond.class);
    trcollection = new TimeSeriesCollection(ts_LP);

    trcollection.addSeries(ts_HP);

    trcollection2 = new TimeSeriesCollection(ts_humidity);

    trcollection2.addSeries(ts_temprature);

    //        trcollection2.addSeries(ts_num);
    //        trcollection2.addSeries(ts_time);
    //trcollection2.addSeries(ts_reserved1);
    //trcollection2.addSeries(ts_reserved2);
    //trcollection2.addSeries(ts_reserved3);

    //        timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1));
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection,
            true, true, false);
    XYPlot xyplot = jfreechart.getXYPlot();

    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    Font fs = new Font("", Font.BOLD, 14);
    Font fs2 = new Font("", Font.BOLD, 12);

    XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

    Color purple = new Color(139, 0, 255);

    line0render.setSeriesPaint(0, Color.blue);
    line0render.setSeriesPaint(1, Color.green);
    line0render.setSeriesPaint(2, Color.red);
    line0render.setSeriesPaint(3, purple);

    //        line0render.setSeriesPaint(3, Color.ORANGE);
    XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer();
    Color Rosered = new Color(230, 28, 100);
    line1render.setSeriesPaint(0, Color.cyan);
    line1render.setSeriesPaint(1, Rosered);
    line1render.setSeriesPaint(2, Color.orange);
    line1render.setSeriesPaint(3, Color.yellow);
    line1render.setBaseShapesVisible(false);
    xyplot.setRenderer(1, line1render);

    //??
    ValueAxis valueaxis = xyplot.getDomainAxis();

    //
    valueaxis.setLabelFont(fs);

    //
    valueaxis.setTickLabelFont(fs2);

    ValueAxis valueaxis2 = new NumberAxis("");
    valueaxis2.setLabelFont(fs);
    valueaxis2.setTickLabelFont(fs2);

    xyplot.setRangeAxis(1, valueaxis2);
    xyplot.setDataset(1, trcollection2);
    xyplot.mapDatasetToRangeAxis(1, 1);

    //??
    valueaxis.setAutoRange(true);
    //?? 7days
    //                valueaxis.setFixedAutoRange(604800000D);
    valueaxis = xyplot.getRangeAxis();

    valueaxis.setLabelFont(new Font("", Font.BOLD, 14));
    valueaxis.setLabelPaint(line0render.getSeriesPaint(0));
    valueaxis2.setLabelPaint(line1render.getSeriesPaint(0));

    jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));//
    jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    chartPanel = new ChartPanel(jfreechart);

    initChartMenu();
    //        chartPanel.getPopupMenu().add(jmenuitem2);
    //        chartPanel.getPopupMenu().getPopupMenuListeners();

    chartPanel.setSize(950, 620);
    chartPanel.setPreferredSize(new Dimension(950, 620));
    jPanel_Show.add(chartPanel, BorderLayout.CENTER);
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

/**
 * ?jfreechart/*from  w w w  .ja v a  2s  .c om*/
 */
public void initChart() {
    ts_wppm = new TimeSeries("PPM", Millisecond.class);
    ts_wppm_zero = new TimeSeries("PPM-Zero", Millisecond.class);
    ts_flux = new TimeSeries("Flux", Millisecond.class);
    ts_wvtr = new TimeSeries("WVTR", Millisecond.class);
    ts_tempcell = new TimeSeries(" Cell Temperature", Millisecond.class);
    ts_tempambi = new TimeSeries("Ambient Temperature", Millisecond.class);
    ts_status = new TimeSeries("Status", Millisecond.class);
    ts_fitting = new TimeSeries("fitting curve1", Millisecond.class);
    ts_fitting2 = new TimeSeries("fitting curve2", Millisecond.class);
    trcollection = new TimeSeriesCollection(ts_wppm);

    trcollection.addSeries(ts_wppm_zero);

    trcollection.addSeries(ts_wvtr);

    trcollection.addSeries(ts_fitting2);//ppm
    trcollection2 = new TimeSeriesCollection(ts_flux);

    trcollection2.addSeries(ts_fitting);//temp3

    trcollection2.addSeries(ts_tempcell);

    trcollection2.addSeries(ts_tempambi);

    trcollection2.addSeries(ts_status);
    //        timeseriescopylist.add(getTimeSeries(3).createCopy(0, getTimeSeries(3).getItemCount() - 1));
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("", "Time(s)", "PPM", trcollection,
            true, true, false);
    XYPlot xyplot = jfreechart.getXYPlot();

    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);

    Font fs = new Font("", Font.BOLD, 14);
    Font fs2 = new Font("", Font.BOLD, 12);

    XYLineAndShapeRenderer line0render = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

    Color purple = new Color(139, 0, 255);

    line0render.setSeriesPaint(0, Color.blue);
    line0render.setSeriesPaint(1, Color.green);
    line0render.setSeriesPaint(2, Color.red);
    line0render.setSeriesPaint(3, purple);

    //        line0render.setSeriesPaint(3, Color.ORANGE);
    XYLineAndShapeRenderer line1render = new XYLineAndShapeRenderer();
    Color Rosered = new Color(230, 28, 100);
    line1render.setSeriesPaint(0, Color.orange);
    line1render.setSeriesPaint(1, Color.yellow);
    line1render.setSeriesPaint(2, Color.cyan);
    line1render.setSeriesPaint(3, Rosered);
    line1render.setBaseShapesVisible(false);
    xyplot.setRenderer(1, line1render);

    //??
    ValueAxis valueaxis = xyplot.getDomainAxis();

    //
    valueaxis.setLabelFont(fs);

    //
    valueaxis.setTickLabelFont(fs2);

    ValueAxis valueaxis2 = new NumberAxis("");
    valueaxis2.setLabelFont(fs);
    valueaxis2.setTickLabelFont(fs2);

    xyplot.setRangeAxis(1, valueaxis2);
    xyplot.setDataset(1, trcollection2);
    xyplot.mapDatasetToRangeAxis(1, 1);

    //??
    valueaxis.setAutoRange(true);
    //?? 7days
    //                valueaxis.setFixedAutoRange(604800000D);
    valueaxis = xyplot.getRangeAxis();

    valueaxis.setLabelFont(new Font("", Font.BOLD, 14));
    valueaxis.setLabelPaint(line0render.getSeriesPaint(0));
    valueaxis2.setLabelPaint(line1render.getSeriesPaint(0));

    jfreechart.getTitle().setFont(new Font("", Font.BOLD, 20));//
    jfreechart.getLegend().setItemFont(new Font("", Font.ITALIC, 15));
    xyplot.getRenderer(0).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    xyplot.getRenderer(1).setSeriesToolTipGenerator(0, new StandardXYToolTipGenerator("{1}, {2}",
            new SimpleDateFormat("MM-dd HH:mm:ss"), new DecimalFormat("0.0000")));
    chartPanel = new ChartPanel(jfreechart);

    initChartMenu();
    //        chartPanel.getPopupMenu().add(jmenuitem2);
    //        chartPanel.getPopupMenu().getPopupMenuListeners();

    chartPanel.setSize(950, 620);
    chartPanel.setPreferredSize(new Dimension(950, 620));
    jPanel_Show.add(chartPanel, BorderLayout.CENTER);
}