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

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

Introduction

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

Prototype

public void setSeriesPaint(int series, Paint paint) 

Source Link

Document

Sets the paint used for a series and sends a RendererChangeEvent to all registered listeners.

Usage

From source file:com.hello2morrow.sonargraph.jenkinsplugin.model.TimeSeriesPlot.java

@Override
protected void applyRendering(XYPlot plot) {
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(StringUtility.getDateFormat());

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesPaint(0, DATA_COLOR);

    if (m_markerTimestamp > 0) {
        final Marker target = new ValueMarker(m_markerTimestamp);
        target.setPaint(Color.RED);
        target.setLabel("Short Term");
        if ((m_markerPosition * 2) > getDatasetSize()) {
            //Move the label to the left of the marker
            target.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
            target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        } else {//from w w  w .  j  a  v  a 2 s.c  o  m
            target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
            target.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        }
        plot.addDomainMarker(target);
    }
}

From source file:GeMSE.Visualization.ElbowPlot.java

public void Plot(ArrayList<Double[]> pvData, ArrayList<Double[]> dData, int cut) {
    double maxY = 0;

    float[] secYColor = new float[3];
    Color.RGBtoHSB(153, 245, 255, secYColor);

    float[] priYColor = new float[3];
    Color.RGBtoHSB(255, 255, 255, priYColor);

    float[] cutColor = new float[3];
    Color.RGBtoHSB(255, 255, 0, cutColor);

    //create the series - add some dummy data
    XYSeries pvSeries = new XYSeries("Percentage of variance        ");
    for (int i = 1; i < pvData.size(); i++) {
        pvSeries.add(pvData.get(i)[0], pvData.get(i)[1]);
        maxY = Math.max(maxY, pvData.get(i)[1]);
    }/*from w  w  w  .  j a  v a2 s. c  om*/

    XYSeries dSeries = new XYSeries("Percentage of differences between slopes        ");
    for (int i = 0; i < dData.size(); i++)
        dSeries.add(dData.get(i)[0], dData.get(i)[1]);

    XYSeries cutSeries = new XYSeries("Cut        ");
    cutSeries.add(cut, 0.0);
    cutSeries.add(cut, maxY);

    //create the datasets
    XYSeriesCollection pvDataSeries = new XYSeriesCollection();
    pvDataSeries.addSeries(pvSeries);

    XYSeriesCollection cutDataSeries = new XYSeriesCollection();
    cutDataSeries.addSeries(cutSeries);

    XYSeriesCollection dDataSeries = new XYSeriesCollection();
    dDataSeries.addSeries(dSeries);

    //construct the plot
    XYPlot plot = new XYPlot();
    plot.setDataset(0, pvDataSeries);
    plot.setDataset(1, cutDataSeries);
    plot.setDataset(2, dDataSeries);

    // use XYSplineRenderer if you want to smooth the lines.
    XYLineAndShapeRenderer pvRenderer = new XYLineAndShapeRenderer();
    pvRenderer.setSeriesPaint(0, Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));

    BasicStroke dstroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 1.0f, 10.0f }, 0.0f);
    XYLineAndShapeRenderer dRenderer = new XYLineAndShapeRenderer();
    dRenderer.setSeriesPaint(0, Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    dRenderer.setSeriesStroke(0, dstroke);

    BasicStroke cutStoke = new BasicStroke(4);
    // use XYSplineRenderer if you want to smooth the lines.
    //XYSplineRenderer cutRenderer = new XYSplineRenderer();
    XYLineAndShapeRenderer cutRenderer = new XYLineAndShapeRenderer();
    cutRenderer.setSeriesPaint(0, Color.getHSBColor(cutColor[0], cutColor[1], cutColor[2]));
    cutRenderer.setSeriesStroke(0, cutStoke);

    plot.setRenderer(0, pvRenderer);
    plot.setRenderer(1, cutRenderer);
    plot.setRenderer(2, dRenderer);

    plot.setRangeAxis(0, new NumberAxis("\n\nPercentage of Variance"));
    plot.setRangeAxis(1, new NumberAxis("Percentage of Difference Between Slopes"));
    plot.setDomainAxis(new NumberAxis("Number of Clusters\n\n"));

    //Map the data to the appropriate axis
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 0);
    plot.mapDatasetToRangeAxis(2, 1);

    float[] hsbValues = new float[3];
    Color.RGBtoHSB(16, 23, 67, hsbValues);
    plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2]));

    Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14);
    Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12);
    Font legendFont = new Font("Dialog", Font.PLAIN, 14);

    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(axisLabelFont);
    plot.getDomainAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelPaint(Color.getHSBColor(priYColor[0], priYColor[1], priYColor[2]));
    plot.getRangeAxis().setLabelFont(axisLabelFont);
    plot.getRangeAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis(1).setTickLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelPaint(Color.getHSBColor(secYColor[0], secYColor[1], secYColor[2]));
    plot.getRangeAxis(1).setLabelFont(axisLabelFont);
    plot.getRangeAxis(1).setTickLabelFont(axisTickLabelFont);

    //generate the chart
    JFreeChart chart = new JFreeChart("\nSuggested number of clusters determined using Elbow method", getFont(),
            plot, true);

    chart.getTitle().setPaint(Color.white);
    chart.getLegend().setBackgroundPaint(Color.black);
    chart.getLegend().setItemPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    chart.getLegend().setItemFont(legendFont);

    float[] hsbValues2 = new float[3];
    Color.RGBtoHSB(36, 43, 87, hsbValues2);
    chart.setBackgroundPaint(Color.getHSBColor(hsbValues2[0], hsbValues2[1], hsbValues2[2]));
    JPanel chartPanel = new ChartPanel(chart);

    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    chartPanel.setPreferredSize(
            new java.awt.Dimension((int) Math.round((gd.getDisplayMode().getWidth() * 1.5) / 3.0),
                    (int) Math.round((gd.getDisplayMode().getHeight() * 1.5) / 3.0)));

    setContentPane(chartPanel);
}

From source file:org.sonar.server.charts.jruby.TrendsChart.java

public void initSerie(Long serieId, String legend, boolean isPercent) {
    TimeSeries series = new TimeSeries(legend);

    int index = seriesById.size();
    seriesById.put(serieId, series);//from ww w.j a  v a2s .  com

    TimeSeriesCollection timeSeriesColl = new TimeSeriesCollection();
    timeSeriesColl.addSeries(series);
    plot.setDataset(index, timeSeriesColl);

    if (isPercent) {
        if (percentAxisId == -1) {
            NumberAxis rangeAxis = new NumberAxis();
            rangeAxis.setNumberFormatOverride(new DecimalFormat("0'%'"));
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            rangeAxis.setUpperBound(100.0);
            rangeAxis.setLowerBound(0.0);
            plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_LEFT);
            plot.setRangeAxis(index, rangeAxis);
            plot.mapDatasetToRangeAxis(index, index);
            percentAxisId = index;

        } else {
            plot.mapDatasetToRangeAxis(index, percentAxisId);
        }
    } else {
        NumberAxis rangeAxis = new NumberAxis(displayLegend ? legend : null);
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setAutoRangeMinimumSize(2.0);
        plot.setRangeAxisLocation(index, AxisLocation.TOP_OR_RIGHT);
        plot.setRangeAxis(index, rangeAxis);
        plot.mapDatasetToRangeAxis(index, index);
    }

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer.setSeriesPaint(0, COLORS[index % COLORS.length]);
    plot.setRenderer(index, renderer);
}

From source file:diplomawork.model.ViewForDiagram.java

/**
 * Creates a chart.//from w w w  . j a v  a2 s . co m
 *
 * @param dataset a dataset.
 *
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("EUR/USD", // title
            "Date", // x-axis label
            "Price Per Unit", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setOutlinePaint(null);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
        renderer.setSeriesPaint(0, Color.BLUE);
    }
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("dd HH:mm:ss"));
    return chart;
}

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

/**
 * Creates the chart/*w w  w  . ja  v a 2 s .c om*/
 */
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:com.bt.aloha.sipstone.GenGraph.java

private JFreeChart createCombinedChart() {
    XYDataset xydatasetArray[] = createDataset_TotalCallCreated_CallsPerSecond();
    XYDataset xydataset = xydatasetArray[0];
    final XYDataset percXydataset = xydatasetArray[1];
    JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone graph", "Calls", "Call rate", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = new NumberAxis("Avg. Response Time");
    numberaxis.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis);/*from   w w w.  j  av  a2s .  c  o  m*/
    xyplot.setDataset(1, createDataset_TotalCallCreated_AvgResponseTime());
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setShapesFilled(true);
    }
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer1.setBaseShapesVisible(true);
    xylineandshaperenderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xyplot.setRenderer(1, xylineandshaperenderer1);
    NumberAxis timeaxis = (NumberAxis) xyplot.getDomainAxis();
    timeaxis.setAutoRange(true);
    timeaxis.setAxisLineVisible(true);
    LegendTitle legendtitle = new LegendTitle(xyitemrenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));

    XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer();
    xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset));
    xyrenderer.setBaseItemLabelsVisible(true);

    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.SurefirePercentAxisDecorator.java

/**
 *
 *///from   w  w w.ja v  a2s. c  o  m
public void createChart() {

    XYPlot xyplot = (XYPlot) report.getPlot();
    if (this.decoratedChart instanceof TimeChartRenderer && this.results != null && !this.results.isEmpty()) {

        Iterator iter = this.results.iterator();
        TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
        TimeSeries s1 = new TimeSeries("% success", Day.class);

        while (iter.hasNext()) {
            SurefireReportBean surefire = (SurefireReportBean) iter.next();
            Date date = surefire.getDateGeneration();
            s1.addOrUpdate(new Day(TimePeriod.DAY.normalize(date)), surefire.getSucessRate() / PCENT);

        }

        defaultdataset.addSeries(s1);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesPaint(0, ChartColor.DARK_BLUE);
        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        StandardXYItemLabelGenerator labelgenerator = new StandardXYItemLabelGenerator(
                StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, TimePeriod.DAY.getDateFormat(),
                NumberFormat.getPercentInstance(Locale.getDefault()));
        renderer.setBaseItemLabelGenerator(labelgenerator);
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, ITEM_LABEL_FONT_SIZE));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));

        renderer.setBaseStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));

        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle.setFrame(new BlockBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);

        LegendTitle legendtitle1 = new LegendTitle(renderer);
        legendtitle1.setMargin(new RectangleInsets(2D, 2D, 2D, 2D));
        legendtitle1.setFrame(new BlockBorder());
        legendtitle1.setBackgroundPaint(ChartColor.WHITE);

        BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
        blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
        blockcontainer.add(new EmptyBlock(BLOCK_CONTAINER_WIDTH, 0.0D));

        CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
        compositetitle.setPosition(RectangleEdge.BOTTOM);

        report.clearSubtitles();
        report.addSubtitle(compositetitle);

        xyplot.setDataset(1, defaultdataset);

        NumberAxis valueaxis = new NumberAxis("% success");
        valueaxis.setLowerMargin(0.0D);
        valueaxis.setUpperMargin(AXIS_UPPER_MARGIN);
        valueaxis.setRangeWithMargins(0.0D, 1.0D);
        valueaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
        xyplot.setRangeAxis(1, valueaxis);
        xyplot.mapDatasetToRangeAxis(1, 1);
        xyplot.setRenderer(1, renderer);
    }

}

From source file:fi.smaa.jsmaa.gui.views.CriterionView.java

private JPanel buildValueFunctionChartPanel(ScaleCriterion criterion) {
    UtilityFunctionDataset dataset = new UtilityFunctionDataset(criterion);

    JFreeChart chart = ChartFactory.createXYLineChart("", "x", "v(x)", dataset, PlotOrientation.VERTICAL, false,
            true, true);//from   w  w  w .  j  a v a  2s.  c  o  m

    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(0, renderer);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3.0f));
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());

    ValueAxis rAxis = plot.getRangeAxis();
    rAxis.setAutoRange(false);
    rAxis.setRange(new Range(-0.03, 1.03));
    ValueAxis dAxis = plot.getDomainAxis();
    dAxis.setLowerMargin(0.03);
    dAxis.setUpperMargin(0.03);

    ChartPanel chartPanel = new ChartPanel(chart, false, true, true, false, true);
    chartPanel.addChartMouseListener(new ValueFunctionMouseListener(chartPanel, criterion, parent));

    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);
    chartPanel.setDisplayToolTips(true);
    chartPanel.setToolTipText("Click to add/remove partial value function points");
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setMouseZoomable(false);

    plot.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairLockedOnData(false);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    FormLayout layout = new FormLayout("left:pref", "p, 3dlu, p");

    PanelBuilder builder = new PanelBuilder(layout);
    CellConstraints cc = new CellConstraints();
    builder.add(chartPanel, cc.xy(1, 1));
    builder.add(new ValueFunctionPointsPanel(criterion), cc.xy(1, 3));

    return builder.getPanel();
}

From source file:com.joey.software.Tools.AScanViewerTool.java

public void setMax(float max) {
    for (int i = 0; i < maxData.length; i++) {
        maxData[i] = max;/*from www.j a v  a 2s.c  om*/
    }

    XYSeriesCollection maxCol = PlotingToolkit.getCollection(xData, maxData, "Max");

    XYLineAndShapeRenderer maxRender = new XYLineAndShapeRenderer(true, false);
    maxRender.setSeriesPaint(0, Color.MAGENTA);

    previewPlot.getXYPlot().setRenderer(2, maxRender);
    dataPlot.getXYPlot().setRenderer(2, maxRender);

    dataPlot.getXYPlot().setDataset(2, maxCol);
    previewPlot.getXYPlot().setDataset(2, maxCol);
}

From source file:com.joey.software.Tools.AScanViewerTool.java

public void setMin(float min) {
    for (int i = 0; i < minData.length; i++) {
        minData[i] = min;//from   ww w  . jav  a 2s.  c o  m
    }

    XYSeriesCollection minCol = PlotingToolkit.getCollection(xData, minData, "Min");

    XYLineAndShapeRenderer minRender = new XYLineAndShapeRenderer(true, false);
    minRender.setSeriesPaint(0, Color.RED);

    previewPlot.getXYPlot().setRenderer(1, minRender);
    dataPlot.getXYPlot().setRenderer(1, minRender);

    dataPlot.getXYPlot().setDataset(1, minCol);
    previewPlot.getXYPlot().setDataset(1, minCol);
}