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:imc.graficaIMC.java

public void iejmplo() {
    TimeSeries s1 = new TimeSeries("Entrenamiento Actual");
    s1.add(new Month(2, 2001), 181.8);
    //s1.add(new Week(1, 1), null);
    s1.add(new Month(3, 2001), 167.3);
    s1.add(new Month(4, 2001), 153.8);
    s1.add(new Month(5, 2001), 167.6);
    s1.add(new Month(6, 2001), 158.8);
    s1.add(new Month(7, 2001), 148.3);
    s1.add(new Month(8, 2001), 153.9);
    s1.add(new Month(9, 2001), 142.7);
    s1.add(new Month(10, 2001), 123.2);
    s1.add(new Month(11, 2001), 131.8);
    s1.add(new Month(12, 2001), 139.6);
    s1.add(new Month(1, 2002), 142.9);
    s1.add(new Month(2, 2002), 138.7);
    s1.add(new Month(3, 2002), 137.3);
    s1.add(new Month(4, 2002), 143.9);
    s1.add(new Month(5, 2002), 139.8);
    s1.add(new Month(6, 2002), 137.0);
    s1.add(new Month(7, 2002), 132.8);

    TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
    s2.add(new Month(2, 2001), 129.6);
    s2.add(new Month(3, 2001), 123.2);
    s2.add(new Month(4, 2001), 117.2);
    s2.add(new Month(5, 2001), 124.1);
    s2.add(new Month(6, 2001), 122.6);
    s2.add(new Month(7, 2001), 119.2);
    s2.add(new Month(8, 2001), 116.5);
    s2.add(new Month(9, 2001), 112.7);
    s2.add(new Month(10, 2001), 101.5);
    s2.add(new Month(11, 2001), 106.1);
    s2.add(new Month(12, 2001), 110.3);
    s2.add(new Month(1, 2002), 111.7);
    s2.add(new Month(2, 2002), 111.0);
    s2.add(new Month(3, 2002), 109.6);
    s2.add(new Month(4, 2002), 113.2);
    s2.add(new Month(5, 2002), 111.6);
    s2.add(new Month(6, 2002), 108.8);
    s2.add(new Month(7, 2002), 101.6);

    TimeSeries s3 = new TimeSeries("andres2255");
    s3.add(new Month(2, 2001), 129.6);

    s3.add(new Month(10, 2001), 106.1);
    s3.add(new Month(1, 2002), 111.7);
    s3.add(new Month(2, 2002), 111.0);
    datos.addSeries(s1);/* w  w  w . j a v a 2 s.c  o  m*/
    datos.addSeries(s2);
    datos.addSeries(s3);

    grafica = ChartFactory.createTimeSeriesChart("titulo", "etiquetas X", "etiquetaY", datos, true, true,
            false);
    /// 
    grafica.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) grafica.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);

    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"));
}

From source file:MWC.GUI.JFreeChart.ColourStandardXYItemRenderer.java

/**
 * Returns a legend item for a series.// w  w  w . ja  va  2s .  c  o  m
 * 
 * @param series
 *          the series (zero-based index).
 * 
 * @return a legend item for the series.
 */
public LegendItem getLegendItem(final int series) {

    final XYPlot plot = this.getPlot();

    final XYDataset dataset = plot.getDataset();
    final String label = (String) dataset.getSeriesKey(series);
    final String description = label;
    final Shape shape = null;
    final Paint paint = this.getSeriesPaint(series);
    final Paint outlinePaint = paint;
    final Stroke stroke = plot.getRenderer().getSeriesStroke(series);

    return new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint);
}

From source file:org.jgrasstools.gears.ui.OmsMatrixCharter.java

@SuppressWarnings("deprecation")
private JFreeChart doLineChart() {
    XYSeriesCollection collection = getSeriesCollection();
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    if (doHorizontal) {
        orientation = PlotOrientation.HORIZONTAL;
    }/*from w  w w.  j a v  a 2s.c  om*/

    JFreeChart chart = ChartFactory.createXYLineChart(inTitle, inLabels[0], inLabels[1], collection,
            orientation, doLegend, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();

    // plot.setDomainGridlinePaint(Color.red);
    // plot.setRangeGridlinePaint(Color.cyan);
    // plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer plotRenderer = plot.getRenderer();
    if (plotRenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plotRenderer;
        if (doPoints) {
            renderer.setShapesVisible(true);
            renderer.setShapesFilled(true);
        }

        if (inColors != null) {
            String[] colorSplit = inColors.split(";");
            for (int i = 0; i < colorSplit.length; i++) {
                String[] split = colorSplit[i].split(",");
                int r = (int) Double.parseDouble(split[0]);
                int g = (int) Double.parseDouble(split[1]);
                int b = (int) Double.parseDouble(split[2]);
                renderer.setSeriesPaint(i, new Color(r, g, b));
            }
        }
    }

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    double delta = (max - min) * 0.1;
    yAxis.setRange(min, max + delta);
    yAxis.setMinorTickCount(4);
    yAxis.setMinorTickMarksVisible(true);
    if (inFormats != null && inFormats.length > 1 && inFormats[1].trim().length() > 0) {
        yAxis.setNumberFormatOverride(new DecimalFormat(inFormats[1]));
    }

    if (inFormats != null && inFormats.length > 0 && inFormats[0].trim().length() > 0) {
        ValueAxis domainAxis = plot.getDomainAxis();
        if (domainAxis instanceof NumberAxis) {
            NumberAxis xAxis = (NumberAxis) domainAxis;
            xAxis.setNumberFormatOverride(new DecimalFormat(inFormats[0]));
        }
    }
    return chart;
}

From source file:com.rapidminer.gui.viewer.metadata.model.DateTimeAttributeStatisticsModel.java

/**
 * Creates the histogram chart./*  w w w . j  ava 2s .  c  o m*/
 *
 * @param exampleSet
 * @return
 */
private JFreeChart createHistogramChart(final ExampleSet exampleSet) {
    JFreeChart chart = ChartFactory.createHistogram(null, null, null, createHistogramDataset(exampleSet),
            PlotOrientation.VERTICAL, false, false, false);
    AbstractAttributeStatisticsModel.setDefaultChartFonts(chart);
    chart.setBackgroundPaint(null);
    chart.setBackgroundImageAlpha(0.0f);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeGridlinesVisible(false);
    plot.setDomainGridlinesVisible(false);
    plot.setOutlineVisible(false);
    plot.setRangeZeroBaselineVisible(false);
    plot.setDomainZeroBaselineVisible(false);
    plot.getDomainAxis().setTickLabelsVisible(false);
    plot.setBackgroundPaint(COLOR_INVISIBLE);
    plot.setBackgroundImageAlpha(0.0f);

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, AttributeGuiTools.getColorForValueType(Ontology.DATE_TIME));
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);

    return chart;
}

From source file:org.hammurapi.inspectors.metrics.reporting.LocCharts.java

private void customizeChartBars(JFreeChart chart) {
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    // set the background color for the chart...
    chart.setBackgroundPaint(new Color(0xBBBBDD));
    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // disable bar outlines...
    XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer();
    // renderer.ssetDrawBarOutline(false);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp1);//from  ww w  .  j a v a  2s  . c o m
    renderer.setSeriesPaint(1, gp2);
    ValueAxis domainAxis = plot.getDomainAxis();
    //domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    //domainAxis.setMaxCategoryLabelWidthRatio(5.0f);
    // OPTIONAL CUSTOMISATION COMPLETED.
}

From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java

private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String uri = request.getRequestURI();
    String requestString = uri.split("test_images/")[1];
    String[] requestParams = requestString.split("/");

    String reportName = URLDecoder.decode(requestParams[0], charset);
    String categoryName = URLDecoder.decode(requestParams[1], charset);
    // String className = URLDecoder.decode(requestParams[2], charset);
    String testName = URLDecoder.decode(requestParams[3], charset);
    String agent = URLDecoder.decode(requestParams[4], charset);

    ReportDatabase db = ReportDatabase.getInstance();
    Report report = db.getReport(reportName);
    List<Category> categories = report.getCategories();
    Category category = getCategoryByName(categories, categoryName);
    List<Benchmark> benchmarks = category.getBenchmarks();
    Benchmark benchmark = getBenchmarkByName(benchmarks, testName);
    List<Result> results = benchmark.getResults();
    Result result = getResultsByAgent(results, agent);

    String title = BrowserInfo.getBrowser(agent);
    JFreeChart chart = createChart(testName, result, title, results);

    chart.getTitle().setFont(Font.decode("Verdana BOLD 12"));
    chart.setAntiAlias(true);/*from w  ww .  j  a  v  a  2s  .  c  o  m*/
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(new Color(241, 241, 241));

    Plot plot = chart.getPlot();

    plot.setDrawingSupplier(getDrawingSupplier());
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 640, 480, new Color(200, 200, 200)));

    if (plot instanceof XYPlot) {
        XYPlot xyplot = (XYPlot) plot;
        Font labelFont = Font.decode("Verdana PLAIN");
        xyplot.getDomainAxis().setLabelFont(labelFont);
        xyplot.getRangeAxis().setLabelFont(labelFont);
        org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
        xyitemrenderer.setStroke(new BasicStroke(4));
        if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
            xylineandshaperenderer.setShapesVisible(true);
            xylineandshaperenderer.setShapesFilled(true);
        }
    }

    // Try to fit all the graphs into a 1024 window, with a min of 240 and a max
    // of 480
    final int graphWidth = Math.max(240, Math.min(480, (1024 - 10 * results.size()) / results.size()));
    BufferedImage img = chart.createBufferedImage(graphWidth, 240);
    byte[] image = EncoderUtil.encode(img, ImageFormat.PNG);

    // The images have unique URLs; might as well set them to never expire.
    response.setHeader("Cache-Control", "max-age=0");
    response.setHeader("Expires", "Fri, 2 Jan 1970 00:00:00 GMT");
    response.setContentType("image/png");
    response.setContentLength(image.length);

    OutputStream output = response.getOutputStream();
    output.write(image);
}

From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformQQNormalPlotChart.java

/**
 * Creates a chart.//  w w w  . ja va  2 s . c o m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, //"Power Tranfomed Normal Q-Q plot",      // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    // renderer.setShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    //  renderer.setLinesVisible(false);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, true);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);

    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0);
    rangeAxis.setLowerMargin(0);

    // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0);
    domainAxis.setLowerMargin(0);

    // domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.
    //setQQSummary(dataset);    // very confusing   
    return chart;

}

From source file:sim.app.sugarscape.util.ResultsGrapher.java

JFreeChart createChart1(XYSeries[] series) {
    JFreeChart chart3 = ChartFactory.createXYLineChart("Results", x_axis_fieldname, y_axis_fieldname, null, //new XYSeriesCollection(series[2]),
            PlotOrientation.VERTICAL, true, true, false);
    //System.out.println("Series count = " +series[0].getItemCount());
    XYPlot plot = chart3.getXYPlot();

    ValueAxis yAxis = plot.getRangeAxis();
    //xAxis.setFixedDimension(100);
    //yAxis.setFixedDimension(1.0);
    //yAxis.setRange(0,1);
    ValueAxis xAxis = plot.getDomainAxis();
    //xAxis.setFixedDimension(50);

    StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);
    renderer.setStroke(new BasicStroke(2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));

    renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 20));
    renderer.setItemLabelsVisible(true);

    renderer.setSeriesItemLabelsVisible(1, true);
    renderer.setBaseShapesVisible(true);
    //XYLabelGenerator generator = new StandardXYLabelGenerator();

    //"{2}", new DecimalFormat("0.00") );
    //renderer.setLabelGenerator(generator);
    //NumberAxis axis2 = new NumberAxis("Average Agent Vision");
    //renderer.setItemLabelsVisible(true);
    //axis2.setAutoRangeIncludesZero(false);
    //axis2.setRange(0,12);
    //plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision);
    //plot.setDataset(1, vision);
    //String first_letter = x_param_fieldname.substring(0,1)+"=";
    XYSeriesCollection xys = new XYSeriesCollection();
    for (int a = 0; a < series.length; a++) {
        xys.addSeries(series[a]);/* w  w w.  j  a va 2 s  .c o m*/
        //xys.
        //xys.getSeriesName(4);
        System.out.println(xys.getSeries(a).getDescription());
    }
    plot.setDataset(0, xys);
    return chart3;

}

From source file:kardex.graficakardex.java

public graficakardex() {
    datosxy.removeAllSeries();//  w  w w  .j a  v  a2 s  .c  o  m
    //sxy.add(x[0], y[0]);
    y = new double[kardex.valor.length];
    y = kardex.valor;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Stock de Producto", "transacciones", "cantidades",
            datosxy, PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

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

From source file:entrenamiento.grafica.java

public grafica() {
    XYSeries sxy = new XYSeries("pesos");
    datosxy.removeAllSeries();/*from  ww w  .  j av  a  2 s.co m*/
    //sxy.add(x[0], y[0]);
    y = new double[Entrenamiento.valor.length];
    y = Entrenamiento.valor;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy,
            PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.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);

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    configurarDomainAxis(domainAxis);

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