Example usage for org.jfree.chart.plot XYPlot getRenderer

List of usage examples for org.jfree.chart.plot XYPlot getRenderer

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getRenderer.

Prototype

public XYItemRenderer getRenderer() 

Source Link

Document

Returns the renderer for the primary dataset.

Usage

From source file:serverrobot.DynamicGraph.java

public JFreeChart createChart(XYDataset dataset, String pos, double minRange, double maxRange) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(pos, "Time (ms)", "Displacement", dataset, true,
            true, false);/*  ww  w.j  av a2 s. c  o  m*/
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(new Color(232, 232, 232));
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.getRenderer().setSeriesPaint(0, Color.BLUE);
    plot.getRenderer().setSeriesPaint(1, Color.RED);

    ValueAxis axis = plot.getDomainAxis();
    //axis.setAutoRange(true);
    axis.setFixedAutoRange(20000.0); // 60 seconds
    axis = plot.getRangeAxis();
    axis.setRange(minRange, maxRange);

    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:com.itemanalysis.jmetrik.swing.GraphPanel.java

public void setXYPlotRendererWithPoints(XYPlot plot) {
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    int n = plot.getSeriesCount();
    int half = (int) (n / 2.0);

    //assume first half are series for lines and second half are series for points

    for (int i = 0; i < n; i++) {
        if (i < half) {
            //Add lines
            Stroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
                    getLineStyle(i), 0.0f);
            renderer.setSeriesStroke(i, stroke);
            renderer.setSeriesPaint(i, getPaintColor(i));
            renderer.setSeriesShapesFilled(i, false);
            renderer.setSeriesShapesVisible(i, showMarkers);
            renderer.setLegendLine(new Line2D.Double(0, 5, 40, 5));
            renderer.setDrawSeriesLineAsPath(true);

        } else {//from w  w w . ja  va2s  .c  om
            //Add points
            renderer.setSeriesLinesVisible(i, false);
            renderer.setSeriesShapesFilled(i, false);
            renderer.setSeriesShapesVisible(i, true);
            renderer.setSeriesPaint(i, getPaintColor(i - half));
        }
    }

    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRenderer(renderer);
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.clusterchart.SimpleCluster.java

public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createBubbleChart(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL,
            legend, true, false);//from www .  j  av a  2 s .co  m

    /*Font font = new Font("Tahoma", Font.BOLD, titleDimension);
    TextTitle title = new TextTitle(name, font);
    chart.setTitle(title);*/

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    Color colorSubInvisibleTitle = Color.decode("#FFFFFF");
    StyleLabel styleSubSubTitle = new StyleLabel("Arial", 12, colorSubInvisibleTitle);
    TextTitle subsubTitle = setStyleTitle("", styleSubSubTitle);
    chart.addSubtitle(subsubTitle);

    chart.setBackgroundPaint(color);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    //plot.setForegroundAlpha(0.50f);
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();

    //define colors
    int seriesN = dataset.getSeriesCount();
    if (colorMap != null) {
        boolean isSerieSel = true;
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getSeriesKey(i);
            String tmpName = serieName.replaceAll(" ", "");
            tmpName = tmpName.replace('.', ' ').trim();
            if (serie_selected != null && serie_selected.size() > 0) {
                String serieSel = serie_selected.get(tmpName).toString();
                isSerieSel = (serieSel.equalsIgnoreCase("TRUE") || serieSel.equalsIgnoreCase("YES")
                        || serieSel.equalsIgnoreCase("1")) ? true : false;
                serieName = tmpName;
            }

            if (color != null && isSerieSel) {
                Color color = (Color) colorMap.get(serieName);
                renderer.setSeriesPaint(i, color);
            } else {
                Color color = new Color(Integer.decode(defaultColor).intValue());
                renderer.setSeriesPaint(i, color);
            }
        }
    }

    // increase the margins to account for the fact that the auto-range 
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    //domainAxis.setAutoRange(true);
    domainAxis.setRange(yMin, yMax);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());

    //rangeAxis.setAutoRange(true);
    rangeAxis.setRange(xMin, xMax);

    TickUnits units = null;
    if (decimalXValues == false)
        units = (TickUnits) NumberAxis.createIntegerTickUnits();
    else
        units = (TickUnits) NumberAxis.createStandardTickUnits();
    rangeAxis.setStandardTickUnits(units);

    TickUnits domainUnits = null;
    if (decimalYValues == false)
        domainUnits = (TickUnits) NumberAxis.createIntegerTickUnits();
    else
        domainUnits = (TickUnits) NumberAxis.createStandardTickUnits();
    domainAxis.setStandardTickUnits(domainUnits);

    rangeAxis.setLowerMargin(1.0);
    rangeAxis.setUpperMargin(1.0);

    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());

    domainAxis.setLowerMargin(1.0);
    domainAxis.setUpperMargin(1.0);
    //DecimalFormat format=(new DecimalFormat("0"));
    //rangeAxis.setNumberFormatOverride(format);

    if (legend == true)
        drawLegend(chart);

    return chart;
}

From source file:netplot.GenericPlotPanel.java

void genericConfig(JFreeChart chart, XYPlot plot, int plotIndex) {
    if (!enableLegend) {
        chart.removeLegend();/*from w w  w. ja va 2s. co m*/
    }

    XYItemRenderer xyItemRenderer = plot.getRenderer();
    //May also be XYBarRenderer
    if (xyItemRenderer instanceof XYLineAndShapeRenderer) {
        XYToolTipGenerator xyToolTipGenerator = xyItemRenderer.getBaseToolTipGenerator();
        //If currently an XYLineAndShapeRenderer replace it so that we inc the colour for every plotIndex
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(linesEnabled, shapesEnabled);
        //Ensure we don't loose the tool tips on the new renderer
        renderer.setBaseToolTipGenerator(xyToolTipGenerator);
        renderer.setBasePaint(getPlotColour(plotIndex));
        renderer.setSeriesStroke(0, new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL),
                true);
        plot.setRenderer(plotIndex, renderer);
    }

    //If we have a new y axis then we need a new data set
    if (yAxisName != null && yAxisName.length() > 0) {
        if (logYAxis) {
            LogAxis yAxis = new LogAxis(yAxisName);
            yAxis.setAutoRange(false);
            yAxis.setNumberFormatOverride(new LogFormat(10, "10", true));
            yAxis.setRange(minScaleValue, maxScaleValue);
            yAxis.setLowerBound(minScaleValue);
            yAxis.setUpperBound(maxScaleValue);
            plot.setRangeAxis(yAxisIndex, yAxis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        } else {
            NumberAxis axis = new NumberAxis(yAxisName);
            axis.setAutoRangeIncludesZero(zeroOnYScale);
            if (autoScaleEnabled) {
                axis.setAutoRange(true);
            } else {
                Range range = new Range(minScaleValue, maxScaleValue);
                axis.setRangeWithMargins(range, true, true);
            }
            if (yAxisTickCount > 0) {
                NumberTickUnit tick = new NumberTickUnit(yAxisTickCount);
                axis.setTickUnit(tick);
            }
            plot.setRangeAxis(yAxisIndex, axis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        }
        yAxisIndex++;
    }
    plot.mapDatasetToRangeAxis(plotIndex, yAxisIndex - 1);
    ValueAxis a = plot.getDomainAxis();
    if (xAxisName.length() > 0) {
        a.setLabel(xAxisName);
    }
    //We can enable/disable zero on the axis if we have a NumberAxis
    if (a instanceof NumberAxis) {
        ((NumberAxis) a).setAutoRangeIncludesZero(zeroOnXScale);
    }
}

From source file:ch.unibe.iam.scg.archie.ui.charts.ConsultationNumberChart.java

/**
 * @see ch.unibe.iam.scg.archie.ui.charts.AbstractChartComposite#
 * initializeChart()//from  ww  w .j  a  va2  s . c o  m
 */
@Override
protected JFreeChart initializeChart() {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(ConsultationNumberChart.CHART_TITLE, // title
            "", // x-axis label
            "Count", // y-axis label
            (XYDataset) this.creator.getDataset(), // data
            false, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(new Color(this.parent.getBackground().getRed(),
            this.parent.getBackground().getGreen(), this.parent.getBackground().getBlue()));

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

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;
}

From source file:MSUmpire.DIA.RTAlignedPepIonMapping.java

private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2)
        throws IOException {
    new File(Workfolder + "/RT_Mapping/").mkdir();
    String pngfile = Workfolder + "/RT_Mapping/"
            + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1))
            + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1))
            + "_RT.png";

    XYSeries smoothline = new XYSeries("RT fitting curve");
    for (XYZData data : regression.PredictYList) {
        smoothline.add(data.getX(), data.getY());
    }/*from   www.  j a  v  a  2s  .  c o m*/
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2,
            "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName),
            "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}

From source file:playground.dgrether.analysis.categoryhistogram.CategoryHistogramWriter.java

public JFreeChart getGraphic(final CategoryHistogram histo, final String modeName) {
    this.checkIndex(histo);
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries(this.departuresName, false, true);
    final XYSeries arrivalsSerie = new XYSeries(this.arrivalsName, false, true);
    final XYSeries onRouteSerie = new XYSeries(this.enRouteName, false, true);
    Integer enRoute = 0;//  ww  w.  ja  va2 s .  c  om
    for (int i = histo.getFirstIndex() - 2; i <= histo.getLastIndex() + 2; i++) {
        int departures = histo.getDepartures(modeName, i);
        int arrivals = histo.getArrivals(modeName, i);
        int stuck = histo.getAbort(modeName, i);
        enRoute = enRoute + departures - arrivals - stuck;
        double hour = i * histo.getBinSizeSeconds() / 60.0 / 60.0;
        departuresSerie.add(hour, departures);
        arrivalsSerie.add(hour, arrivals);
        onRouteSerie.add(hour, enRoute);
    }
    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            this.title + ", " + modeName + ", " + "it." + histo.getIteration(), "time [h]", yTitle, xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(1.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

From source file:com.intel.stl.ui.configuration.view.SC2SLMTBarChartPanel.java

@Override
public void initComponents() {
    dataset = new XYSeriesCollection();

    JFreeChart chart = ComponentFactory.createXYBarChart(K1105_SC.getValue(), K1106_SL.getValue(), dataset,
            (XYItemLabelGenerator) null);

    XYPlot plot = chart.getXYPlot();
    plot.setDomainPannable(true);/*ww  w. j a  va  2 s . c  o  m*/
    plot.setRangePannable(true);
    final String scLabel = "<html>" + K1105_SC.getValue() + ": ";
    final String slLabel = "<br>" + K1106_SL.getValue() + ": ";

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarAlignmentFactor(0);
    renderer.setMargin(0.2);

    renderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int arg1, int arg2) {
            int scNum = (int) dataset.getXValue(arg1, arg2);
            int slCount = (int) dataset.getYValue(arg1, arg2);
            return scLabel + scNum + slLabel + slCount + "</html>";
        }
    });
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(PREFERRED_CHART_SIZE);
    propsPanel.add(chartPanel);
}

From source file:com.intel.stl.ui.configuration.view.SC2VLTMTBarChartPanel.java

@Override
public void initComponents() {
    dataset = new XYSeriesCollection();

    JFreeChart chart = ComponentFactory.createXYBarChart(K1105_SC.getValue(), K1109_VLT.getValue(), dataset,
            (XYItemLabelGenerator) null);

    XYPlot plot = chart.getXYPlot();
    plot.setDomainPannable(true);/*from  w  w  w.j ava 2 s . c o  m*/
    plot.setRangePannable(true);
    final String scLabel = "<html>" + K1105_SC.getValue() + ": ";
    final String vltLabel = "<br>" + K1109_VLT.getValue() + ": ";

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarAlignmentFactor(0);
    renderer.setMargin(0.2);

    renderer.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int arg1, int arg2) {
            int scNum = (int) dataset.getXValue(arg1, arg2);
            int vltCount = (int) dataset.getYValue(arg1, arg2);
            return scLabel + scNum + vltLabel + vltCount + "</html>";
        }
    });
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(PREFERRED_CHART_SIZE);
    propsPanel.add(chartPanel);
}

From source file:edu.wustl.cab2b.client.ui.visualization.charts.LineChart.java

protected JFreeChart createChart(Dataset dataset) {
    XYDataset xyDataset = (XYDataset) dataset;
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Line Chart", "X", "Y", xyDataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();

    xyplot.setBackgroundPaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setShapesVisible(true);
    xylineandshaperenderer.setShapesFilled(true);

    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return jfreechart;
}