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:Perfil_Deportivo.graficaProgCargas.java

public graficaProgCargas() {
    datos.removeAllSeries();//from  w w w  .  ja  va  2 s .c  o  m
    //sxy.add(x[0], y[0]);
    pesos = new double[Progresiones_cargas.pesoentreno.length];
    fecha = new String[Progresiones_cargas.fechaentreno.length];
    pesos = Progresiones_cargas.pesoentreno;
    fecha = Progresiones_cargas.fechaentreno;
    ///////////////77

    Date fechaDate = null;

    int n = pesos.length;
    Calendar calendar = Calendar.getInstance();

    for (int i = 0; i < n; i++) {
        // JOptionPane.showMessageDialog(null, "fecha tio:"+fecha[i]);
        try {
            fechaDate = formato.parse(fecha[i]);
            calendar.setTime(fechaDate);
        } catch (ParseException ex) {

        }
        //  JOptionPane.showMessageDialog(null, calendar.get(Calendar.DAY_OF_MONTH)+" "+calendar.get(Calendar.MONTH)+1+" "+ calendar.get(Calendar.YEAR));
        s1.add(new Day(calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.YEAR)), pesos[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datos.addSeries(s1);
    grafica = ChartFactory.createTimeSeriesChart("Progreso de cargas", "Fecha", "Peso", 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:imc.graficaIMC.java

public graficaIMC() {
    TimeSeries s1 = new TimeSeries("REGISTRO DE IMC ");
    datos.removeAllSeries();// w ww.j  a  v a 2 s  .  com
    //sxy.add(x[0], y[0]);
    pesos = new double[imc.imc.length];
    fecha = new String[imc.fecha.length];
    pesos = imc.imc;
    fecha = imc.fecha;
    ///////////////77

    Date fechaDate = null;

    int n = pesos.length;
    Calendar calendar = Calendar.getInstance();

    for (int i = 0; i < n; i++) {
        // JOptionPane.showMessageDialog(null, "fecha tio:"+fecha[i]);
        try {
            fechaDate = formato.parse(fecha[i]);
            calendar.setTime(fechaDate);
        } catch (ParseException ex) {

        }
        //  JOptionPane.showMessageDialog(null, calendar.get(Calendar.DAY_OF_MONTH)+" "+calendar.get(Calendar.MONTH)+1+" "+ calendar.get(Calendar.YEAR));
        s1.add(new Day(calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1,
                calendar.get(Calendar.YEAR)), pesos[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datos.addSeries(s1);
    grafica = ChartFactory.createTimeSeriesChart("Progreso de MCM", "Fecha", "IMC", 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:dpnm.netmsuite.plc.manager.frontend.graph.TimeSeriesChartDemo1.java

/**
 * Creates a chart.//w  w w  .  j  a v  a2 s .  com
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = null;
    if (this.graphType == 1) {
        chart = ChartFactory.createTimeSeriesChart(title, // title
                "Minute", // x-axis label
                "Packets/sec", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false // generate URLs?
        );
    } else if (this.graphType == 2) {
        chart = ChartFactory.createTimeSeriesChart(title, // title
                "Minute", // x-axis label
                "Bytes/sec", // y-axis label
                dataset, // data
                true, // create legend?
                true, // generate tooltips?
                false // generate URLs?
        );
    } else {
        chart = ChartFactory.createTimeSeriesChart(title, // title
                "Minute", // x-axis label
                "KBps", // 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);

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

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));

    return chart;

}

From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java

public ChartPanel criaGrafico() {

    // create the chart...  
    JFreeChart graf = ChartFactory.createXYLineChart("MAP ENTRE AS QUERYS", // chart title  
            "QUERY", // x axis label  
            "MAP", // y axis label  
            createDataset1(), // data  
            PlotOrientation.VERTICAL, true, // include legend  
            true, // tooltips  
            false // urls  
    );//from ww  w. j  a v a2 s. c  o  m

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

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

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(false);

    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(1, renderer2);

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

    ChartPanel myChartPanel = new ChartPanel(graf, true);
    return myChartPanel;
}

From source file:Simulator.PerformanceCalculation.java

JPanel minmaxwaitTime2(boolean minCheck) {
    LinkedHashSet no = new LinkedHashSet();
    LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>();

    for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) {
        TraceObject traceObject = entry.getValue();

        if (wait1.get(traceObject.getSurgeonId()) == null) {
            ArrayList details = new ArrayList();
            details.add(traceObject.getWaitTime2());
            wait1.put(traceObject.getSurgeonId(), details);
        } else {//from  w w  w . j  a  va 2 s.c o m
            wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2());
        }

        no.add(traceObject.getSurgeonId());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();

    LinkedHashMap<Integer, Double> average = new LinkedHashMap<>();

    for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) {
        Integer integer = entry.getKey();
        ArrayList<Double> arrayList = entry.getValue();
        double value = 0;
        if (minCheck) {
            value = Collections.min(arrayList);
            value = value / 600;
        } else {
            value = Collections.max(arrayList);
            value = value / 600;
        }

        average.put(integer, value);
    }

    XYSeries series = new XYSeries("Surgeon Minimum Wait Time 2");
    for (int i = 1; i <= average.size(); i++) {
        series.add(i, average.get(i));
    }
    dataset.addSeries(series);
    String name;
    if (minCheck) {
        name = "Minimum";
    } else {
        name = "Maximum";
    }
    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(name + " Wait Time 2 For Patients", // Title
            "Surgeon ID", // x-axis Label
            "Time (Days)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

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

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    renderer.setBaseShapesVisible(true);
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);

    return new ChartPanel(chart);
}

From source file:Simulator.PerformanceCalculation.java

JPanel minmaxwaitTime1(boolean minCheck) {
    LinkedHashSet no = new LinkedHashSet();
    LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>();

    for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) {
        TraceObject traceObject = entry.getValue();

        if (wait1.get(traceObject.getSurgeonId()) == null) {
            ArrayList details = new ArrayList();
            details.add(traceObject.getWaitTime1());
            wait1.put(traceObject.getSurgeonId(), details);
        } else {/*from   w  w  w. j  av  a  2s .  c o m*/
            wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1());
        }

        no.add(traceObject.getSurgeonId());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();

    LinkedHashMap<Integer, Double> average = new LinkedHashMap<>();

    for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) {
        Integer integer = entry.getKey();
        ArrayList<Double> arrayList = entry.getValue();
        double value = 0;
        if (minCheck) {
            value = Collections.min(arrayList);
            value = value / 600;
        } else {
            value = Collections.max(arrayList);
            value = value / 600;
        }

        average.put(integer, value);
    }

    XYSeries series = new XYSeries("Surgeon Minimum Wait Time 1");
    for (int i = 1; i <= average.size(); i++) {
        series.add(i, average.get(i));
    }
    dataset.addSeries(series);
    String name;
    if (minCheck) {
        name = "Minimum";
    } else {
        name = "Maximum";
    }
    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(name + " Wait Time 1 For Patients", // Title
            "Surgeon ID", // x-axis Label
            "Time (Days)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

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

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    renderer.setBaseShapesVisible(true);
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);

    return new ChartPanel(chart);
}

From source file:gov.nih.nci.caintegrator.ui.graphing.chart.plot.PrincipalComponentAnalysisPlot.java

protected void createChart() {

    String xLabel = component1.toString();
    String yLabel = component2.toString();

    pcaChart = ChartFactory.createScatterPlot("Principal Component Analysis", xLabel, yLabel, null,
            PlotOrientation.VERTICAL, true, true, false);

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

    if (!this.colorBy.equals(PCAcolorByType.NONE)) {
        buildLegend();//from  w w  w. j  a  v a  2  s  . c o m
    }

    plot.setNoDataMessage(null);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setUseOutlinePaint(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(false);

    //        XYShapeAnnotation annotation = new XYShapeAnnotation(new Rectangle2D.Double(25.0, 25.0, 5, 5));
    //           
    //        plot.addAnnotation(annotation);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    //should determine axis range using datapoints.
    DataRange component1Range = getDataRange(dataPoints, PCAcomponent.PC1);
    DataRange component2Range = getDataRange(dataPoints, PCAcomponent.PC2);
    DataRange component3Range = getDataRange(dataPoints, PCAcomponent.PC3);

    Double pc1AbsMax = Math.max(Math.abs(component1Range.getMaxRange()),
            Math.abs(component1Range.getMinRange()));
    Double pc2AbsMax = Math.max(Math.abs(component2Range.getMaxRange()),
            Math.abs(component2Range.getMinRange()));
    Double pc3AbsMax = Math.max(Math.abs(component3Range.getMaxRange()),
            Math.abs(component3Range.getMinRange()));

    Double maxAbsVal = Math.max(pc1AbsMax, pc2AbsMax);

    maxAbsVal = Math.max(maxAbsVal, pc3AbsMax);

    maxAbsVal = Math.max(150.0, maxAbsVal);

    domainAxis.setAutoRangeIncludesZero(false);

    domainAxis.setRange(-maxAbsVal, maxAbsVal);
    rangeAxis.setRange(-maxAbsVal, maxAbsVal);

    domainAxis.setTickUnit(new NumberTickUnit(25.0));
    rangeAxis.setTickUnit(new NumberTickUnit(25.0));

    createGlyphsAndAddToPlot(plot);

    // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green);
    //try and match the UI e9e9e9
    Paint p = new Color(233, 233, 233);

    pcaChart.setBackgroundPaint(p);
}

From source file:graficoComparacion.graficaCompa.java

public graficaCompa() {

    //sxy.add(x[0], y[0]);

    ///////////////
    /*   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); 
       //////////////////////////////////////
       datos.addSeries(s1);/*from w  ww  . j  av a 2s.c o  m*/
    */
    grafica = ChartFactory.createTimeSeriesChart("Progreso de cargas", "Fechas", "Peso", 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:org.simbrain.plot.histogram.HistogramPanel.java

/**
 * Create the histogram panel based on the data.
 *///from  w  w  w  .j a v  a 2 s  . c  o m
public void createHistogram() {
    try {
        if (this.getModel().getData() != null) {
            mainChart = ChartFactory.createHistogram(title, xAxisName, yAxisName, model.getDataSet(),
                    PlotOrientation.VERTICAL, true, true, false);
            mainChart.setBackgroundPaint(UIManager.getColor("this.Background"));

            XYPlot plot = (XYPlot) mainChart.getPlot();
            plot.setForegroundAlpha(0.75F);
            // Sets y-axis ticks to integers.
            NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
            rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
            renderer.setDrawBarOutline(false);
            renderer.setShadowVisible(false);

            Iterator<ColoredDataSeries> series = model.getSeriesData().iterator();
            for (int i = 0; i < model.getData().size(); i++) {
                if (i < colorPallet.length) {
                    ColoredDataSeries s = series.next();
                    Color c = s.color;
                    if (c == null) {
                        c = assignColor();
                        s.color = c;
                    }
                    renderer.setSeriesPaint(i, c, true);
                }
            }

        } else {

            mainChart = ChartFactory.createHistogram(title, xAxisName, yAxisName, model.getDataSet(),
                    PlotOrientation.VERTICAL, true, true, false);
            mainChart.setBackgroundPaint(UIManager.getColor("this.Background"));

        }

    } catch (IllegalArgumentException iaEx) {
        iaEx.printStackTrace();
        JOptionPane.showMessageDialog(null, iaEx.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    } catch (IllegalStateException isEx) {
        isEx.printStackTrace();
        JOptionPane.showMessageDialog(null, isEx.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
    mainPanel = new ChartPanel(mainChart);

}

From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java

private JFreeChart createChart(final XYDataset dataset, final XYDataset dataset_centroids,
        ArrayList<Cluster_KMeans> clusters) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Sensors", "Time", "Erlang", dataset, false, //t
            true, //t
            false //f
    );//w  w w  .j  av a2s  .  co  m

    ChartUtilities.applyCurrentTheme(chart);

    //chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //        sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();

    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        //rr.setPlotShapes(true);
        rr.setShapesFilled(true);
        rr.setItemLabelsVisible(true);
    }

    int temp_count = 0;

    //for (int i = 0; i < clusters.size(); i++)
    for (int i = 0; (i < 11) && (i < clusters.size()); i++) {
        Cluster_KMeans current_cluster = clusters.get(i);
        ArrayList<Sensor> member_time_series = current_cluster.getMembership();

        for (int j = 0; j < member_time_series.size(); j++) {
            renderer.setSeriesPaint(j + temp_count, getColor(i));
        }
        temp_count = temp_count + member_time_series.size();
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));

    //final ValueAxis axis_y = plot.getRangeAxis();
    //axis_y.setRange(0, 20);

    plot.setDataset(1, dataset_centroids);
    plot.setRenderer(1, new StandardXYItemRenderer());

    for (int i = 0; (i < clusters.size()); i++) {
        //plot.getRenderer(1).setSeriesPaint(i, getColor(i));
        plot.getRenderer(1).setSeriesPaint(i, Color.BLACK);
        plot.getRenderer(1).setSeriesStroke(i, new BasicStroke(3.0f, BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f));
    }

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    return chart;
}