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

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

Introduction

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

Prototype

public void setRenderer(XYItemRenderer renderer) 

Source Link

Document

Sets the renderer for the primary dataset and sends a change event to all registered listeners.

Usage

From source file:GraphUI.java

/**
 * Creates new form GraphUI/*from  www  . j a  va 2 s.  com*/
 */
public GraphUI() {
    try {
        //graphPane is the jPanel in the jFrame
        //cp is the ChartPanel that needs to be held inside jPanel1
        initComponents();
        data = Pinwheel.getData();
        this.batch = data[0];

        //jPanel1 = createChartPanel();
        cp = createChartPanel();
        //cp = new ChartPanel(chart);
        cp.setMouseWheelEnabled(true);

        jPanel1.add(cp);

        XYPlot plot = chart.getXYPlot();

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

        renderer.setSeriesStroke(0, new BasicStroke(3.0f));
        renderer.setSeriesStroke(1, new BasicStroke(3.0f));

        plot.setBackgroundPaint(Color.DARK_GRAY);

        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.BLACK);

        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.BLACK);

        plot.setRenderer(renderer);

        this.addWindowListener(new java.awt.event.WindowAdapter() {
            @Override
            public void windowClosing(java.awt.event.WindowEvent windowEvent) {
                backBtn.doClick();
            }
        });

    } catch (SQLException ex) {
        Logger.getLogger(GraphUI.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.freedomotic.jfrontend.extras.GraphPanel.java

private void createChart(UsageDataFrame points, String title) {
    series = new TimeSeries(title);

    for (UsageData d : points.getData()) {
        Date resultdate = d.getDateTime();
        Millisecond ms_read = new Millisecond(resultdate);
        int poweredValue = -1;
        if (d.getObjBehavior().equalsIgnoreCase("powered")) {
            poweredValue = d.getObjValue().equalsIgnoreCase("true") ? 1 : 0;
        } else if (d.getObjBehavior().equalsIgnoreCase("brigthness")) {
            try {
                poweredValue = Integer.parseInt(d.getObjValue());
            } catch (NumberFormatException ex) {
                poweredValue = -1;/* w  ww.  ja v  a2  s.c om*/
            }
        }
        series.addOrUpdate(ms_read, poweredValue);
    }

    XYDataset xyDataset = new TimeSeriesCollection(series);

    chart = ChartFactory.createTimeSeriesChart("Chart", "TIME", "VALUE", xyDataset, true, // legend
            true, // tooltips
            false // urls
    );
    chart.setAntiAlias(true);
    // Set plot styles
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    // Set series line styles
    plot.setRenderer(new XYStepRenderer());

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

    // Set date axis style
    DateAxis axis = (DateAxis) plot.getDomainAxis();

    String formatString = "MM-dd HH";
    DateTickUnitType dtut = DateTickUnitType.HOUR;

    if (jComboGranularity.getSelectedItem().equals("Year")) {
        formatString = "yyyy";
        dtut = DateTickUnitType.YEAR;
    } else if (jComboGranularity.getSelectedItem().equals("Month")) {
        axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM"));
        dtut = DateTickUnitType.MONTH;
    } else if (jComboGranularity.getSelectedItem().equals("Day")) {
        axis.setDateFormatOverride(new SimpleDateFormat("MM-dd"));
        dtut = DateTickUnitType.DAY;
    } else if (jComboGranularity.getSelectedItem().equals("Minute")) {
        formatString = "MM-dd HH:mm";
        dtut = DateTickUnitType.MINUTE;
    } else if (jComboGranularity.getSelectedItem().equals("Second")) {
        formatString = "HH:mm:SS";
        dtut = DateTickUnitType.SECOND;
    }

    DateFormat formatter = new SimpleDateFormat(formatString);
    DateTickUnit unit = new DateTickUnit(dtut, 1, formatter);
    axis.setTickUnit(unit);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
    graphPanel.removeAll();
    graphPanel.add(chartPanel);

}

From source file:ui.FitnessGraph.java

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

    // create the chart...
    final JFreeChart chart = ChartFactory.createScatterPlot("Fitness v generation", // chart title
            "X", // x axis label
            "Y", // 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);

    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);
    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    // renderer.setSeriesShape(0, new Ellipse2D.Float(1.0f, 1.0f, 1.0f,
    // 1.0f));
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);
    // renderer.setSeriesStroke(1, new BasicStroke(0.01f));
    plot.setRenderer(renderer);

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

    return chart;

}

From source file:SciTK.PlotXYStep.java

/** Initialization routine (common to both constructors) */
private void init(String x_label, String y_label, String window_title, double x_min, double x_max) {
    chart = ChartFactory.createXYStepChart("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true,
            false);/*from ww  w  .  j a  v  a 2  s  .  c o m*/

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = chart.getXYPlot(); // the plot itself

    // Use a step renderer for this type of chart:
    XYStepRenderer renderer = new XYStepRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    renderer.setLegendItemLabelGenerator(new MultipleXYSeriesLabelGenerator());
    // need to tell the plot to use this renderer
    plot.setRenderer(renderer);

    // create new axis with range set by dataset max/min:
    NumberAxis domainAxis = new NumberAxis(x_label);
    domainAxis.setRange(x_min, x_max);
    plot.setDomainAxis(domainAxis);

    // for some reason default is white, change it to black:
    setGridlineColor(Color.BLACK);

    super.window_title = window_title;
    super.initUI();
}

From source file:syg_package01.PanelRysunek.java

private void initGUI() {
    try {//from w  ww . ja v a 2 s  .c o  m
        GridLayout thisLayout = new GridLayout(1, 1);
        thisLayout.setHgap(5);
        thisLayout.setVgap(5);
        thisLayout.setColumns(1);
        this.setLayout(thisLayout);
        setPreferredSize(new Dimension(400, 300));

        if (this.wykres) {
            double punkt = this.sygnalWyswietlany.gett1();
            double punktZapisu = this.sygnalWyswietlany.gett1();
            XYSeries series = new XYSeries("Wykres");

            double krok;
            int typ = this.sygnalWyswietlany.gettyp();
            double f = 1.0 / this.sygnalWyswietlany.getT();
            double t = this.sygnalWyswietlany.gett1();

            // if (this.sygnalWyswietlany.gettyp()==1){
            /*
             * for (double i = this.sygnalWyswietlany.gett1(); i <
             * this.sygnalWyswietlany.t1+this.sygnalWyswietlany.getts();
             * i++){ punkt= this.sygnalWyswietlany.wykres_punkty(punkt, i);
             * series.add(i, punkt)} ;
             */

            double ta = this.sygnalWyswietlany.gett1();

            if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY
                    || sygnalWyswietlany.getPunktyY().size() <= 0) {
                while (ta <= this.sygnalWyswietlany.gett1() + this.sygnalWyswietlany.getd()) {
                    // punkt=this.sygnalWyswietlany.sygnalS1();
                    punkt = this.sygnalWyswietlany.wykres_punkty(punkt, ta);
                    this.sygnalWyswietlany.setPunktyY(punkt);
                    // punkt=this.sygnalWyswietlany.sygnalS3(ta);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.gettyp() < 10)
                        ta = ta + this.sygnalWyswietlany.getkroczek();
                    else
                        ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                }
            } else if (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.DYSKRETNY
                    && sygnalWyswietlany.getPunktyY().size() > 0) {
                int iloscProbek = (int) (this.sygnalWyswietlany.getPunktyY().size());
                for (int i = 0; i < iloscProbek; i++) {
                    // punkt=this.sygnalWyswietlany.sygnalS1();
                    punkt = this.sygnalWyswietlany.getPunktzindexu(i);
                    // punkt=this.sygnalWyswietlany.sygnalS3(ta);
                    series.add(ta, punkt);
                    if (this.sygnalWyswietlany.gettyp() < 10)
                        ta = ta + this.sygnalWyswietlany.getkroczek();
                    else
                        ta = ta + this.sygnalWyswietlany.getkroczek() * 10;
                }
            }

            // this.sygnalWyswietlany.ustawPunkty();
            /*
             * int liczba= this.sygnalWyswietlany.punktyY.size(); int
             * liczba2= 0;
             * 
             * while (liczba2<liczba) { ta= ta+
             * this.sygnalWyswietlany.getkroczek();
             * series.add(ta,this.sygnalWyswietlany
             * .getPunktzindexu(liczba2));
             * 
             * }
             */

            XYSeriesCollection dataset = new XYSeriesCollection(series);

            // JFreeChart chart = ChartFactory.createHistogram("Histogram",
            // "x", "y", dataset, PlotOrientation.VERTICAL, false, false,
            // false);

            JFreeChart chart;

            /*
             * JFreeChart chart = ChartFactory.createScatterPlot("Wykres",
             * "t[s]", "Warto", dataset, PlotOrientation.VERTICAL, false,
             * false, false);
             */
            if ((this.sygnalWyswietlany.gettyp() < 10)
                    || (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY)) {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
                renderer.setSeriesLinesVisible(0, false);
            } else {
                chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
                        true, true, true);

                final XYPlot plot = chart.getXYPlot();
                // plot.setBackgroundPaint(Color.lightGray);
                // plot.setDomainGridlinePaint(Color.white);
                // plot.setRangeGridlinePaint(Color.white);

                // final XYLineAndShapeRenderer renderer = new
                // XYLineAndShapeRenderer();
                final XYDotRenderer renderer = new XYDotRenderer();
                renderer.setDotHeight(3);
                renderer.setDotWidth(3);
                plot.setRenderer(renderer);

                final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
                rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            }

            // ChartPanel chartpanel = new ChartPanel(wykres2);
            ChartPanel chartpanel = new ChartPanel(chart);
            chartpanel.setDomainZoomable(true);

            this.add(chartpanel);
        }

        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java

private JFreeChart getMemoryChart(int intervalSize, List<MemoryData> memory) {

    if (null == memory || memory.isEmpty()) {
        return null;
    }//from  ww  w  .j  a  va2  s .  co m

    JFreeChart chart;

    TimeSeries freeSeries = new TimeSeries("Free");
    TimeSeries maxSeries = new TimeSeries("Max");
    TimeSeries totalSeries = new TimeSeries("Total");

    memory.remove(memory.size() - 1);

    for (MemoryData memoryEntry : memory) {
        freeSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getFreeMemory());

        maxSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getMaxMemory());

        totalSeries.add(new Second(memoryEntry.getDate()), memoryEntry.getTotalMemory());
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(freeSeries);
    dataset.addSeries(maxSeries);
    dataset.addSeries(totalSeries);
    chart = ChartFactory.createTimeSeriesChart("eID Trust Service Memory Usage History",
            "Time (interval size " + intervalSize + " msec)", "Memory", dataset, true, false, false);

    chart.addSubtitle(new TextTitle(
            memory.get(0).getDate().toString() + " - " + memory.get(memory.size() - 1).getDate().toString()));

    chart.setBackgroundPaint(Color.WHITE);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRenderer(renderer);

    return chart;
}

From source file:br.prof.salesfilho.oci.image.GraphicBuilder.java

public void createChart() {
    chart = ChartFactory.createXYLineChart(this.title, this.xLabel, this.yLabel, this.collectionDataset,
            PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);

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

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    List<XYSeries> listSeries = collectionDataset.getSeries();
    for (int i = 0; i < listSeries.size(); i++) {
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, true);
        renderer.setSeriesShapesFilled(i, false);
    }/*from  w  w w .j  av  a2  s . com*/

    plot.setRenderer(renderer);
    plot.setRangePannable(true);
    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chartPanel.setChart(chart);

}

From source file:org.encog.workbench.tabs.visualize.scatter.ScatterPlotTab.java

private JPanel createPanel(int xIndex, int yIndex, boolean legend) {

    XYDataset dataset = new ScatterXY(file, xIndex, yIndex);
    JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, dataset, PlotOrientation.VERTICAL,
            legend, true, false);//from w ww. j a v  a 2s  .  co m

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

    XYDotRenderer renderer = new XYDotRenderer();
    renderer.setDotWidth(4);
    renderer.setDotHeight(4);

    if (this.file.isRegression()) {
        int per = 255 / 10;
        int r = 0;
        int b = 255;
        for (int i = 0; i < file.getSeriesCount(); i++) {
            renderer.setSeriesPaint(i, new Color(r, 0, b));
            r += per;
            b -= per;
        }
    } else {
        for (int i = 0; i < file.getSeriesCount(); i++) {
            renderer.setSeriesPaint(i, COLORS[i % COLORS.length]);
        }
    }

    plot.setRenderer(renderer);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    plot.getRangeAxis().setInverted(false);

    ChartPanel result = new ChartPanel(chart);
    result.setBorder(BorderFactory.createLineBorder(Color.black));

    // we need one to draw the legend off of
    if (this.samplePlot == null)
        this.samplePlot = plot;
    //chart.removeLegend();
    return result;
}

From source file:org.ow2.clif.jenkins.chart.MovingStatChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection coreDataset = new XYSeriesCollection();
    coreDataset.addSeries(this.eventSerie);

    long periodMs = this.chartConfiguration.getStatisticalPeriod() * 1000L;

    XYSeriesCollection movingDataset = calculateMovingDataset(coreDataset, periodMs);
    XYSeriesCollection throughputDataset = calculateThroughputDataset(coreDataset, periodMs);

    JFreeChart chart;/*  w  w w.j  ava 2 s .co m*/
    chart = ChartFactory
            .createXYLineChart(
                    getBasicTitle() + " "
                            + Messages.MovingChart_StatisticalPeriod(
                                    this.chartConfiguration.getStatisticalPeriod()),
                    // chart title
                    Messages.MovingChart_Time(), // x axis label
                    Messages.MovingChart_ResponseTime(), // y axis label
                    movingDataset, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
    );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    configureBasicPlotProperties(plot);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);

    attachThroughputDatasetToDedicatedAxis(throughputDataset, plot);

    // Global renderer for moving stats
    plot.setRenderer(getGlobalRenderer());

    // Dedicated Throughput renderer
    plot.setRenderer(1, getThroughputRenderer());

    return chart;
}

From source file:ac.kaist.ccs.presentation.CCSHubSelectionCoverage.java

/**
 * Creates a chart.//w ww .  j  a  v a 2  s . c  o m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            "Number of Hubs", // x axis label
            "Percent of CO2 emission source node coverage (%)", // 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);

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

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    //final NumberAxis xAxis = (NumberAxis) plot.getRangeAxis();
    //xAxis.setTickUnit(new NumberTickUnit(10));
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    //renderer.setSeriesLinesVisible(0, false);
    //renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}