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

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

Introduction

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

Prototype

public XYLineAndShapeRenderer() 

Source Link

Document

Creates a new renderer with both lines and shapes visible.

Usage

From source file:syg_Wykresy.PanelRysunek_Wykres.java

private void initGUI() {
    try {/*from   w  ww.ja  v  a2  s.co 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) {

            XYSeries series = new XYSeries("Sygna "
                    + (this.sygnalWyswietlany.getrodzaj() == rodzaj_sygnalu.CIAGLY ? "cigy" : "dyskretny"));
            double punkt;
            double ta = this.sygnalWyswietlany.gett1();

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

            XYSeriesCollection dataset = new XYSeriesCollection(series);
            JFreeChart chart;

            if ((this.sygnalWyswietlany.gettyp() != 9 && 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();
                final XYDotRenderer renderer = new XYDotRenderer();
                renderer.setDotHeight(3);
                renderer.setDotWidth(3);
                plot.setRenderer(renderer);

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

            // JOptionPane.showMessageDialog(null, "Rysowanie wykresu...",
            // "PanelRysunek_Wykres", JOptionPane.INFORMATION_MESSAGE);

            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:msi.gama.hpc.gui.perspective.chart.HeadlessChart.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart from XML output file", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/* w  w w .  j a  v  a  2 s .  c  om*/

    // 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);

    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.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:LineChartDemo6.java

/**
 * Creates a chart./*from  ww  w. jav 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("Line Chart Demo 6", // 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);

    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.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:gov.sandia.umf.platform.ui.jobs.Plot.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from  w ww  . j  a va  2s.  co m*/

    chart.setBackgroundPaint(Color.white);

    LegendTitle legend = chart.getLegend();
    legend.setVisible(dataset.getSeriesCount() <= 5);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    ValueAxis axis = plot.getRangeAxis();
    if (axis instanceof NumberAxis)
        ((NumberAxis) axis).setAutoRangeIncludesZero(false);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < dataset.getSeriesCount(); i++)
        renderer.setSeriesShapesVisible(i, false);
    plot.setRenderer(renderer);

    return chart;
}

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

/**
 * Creates a chart./* w ww .j  a  v  a  2  s . com*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    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 = new XYLineAndShapeRenderer();
    // renderer.setSeriesLinesVisible(0, false);
    //   renderer.setSeriesShapesVisible(1, false);
    renderer.setBaseLinesVisible(false);

    plot.setRenderer(renderer);

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

    return chart;

}

From source file:MainWindowLogic.java

static void drawXYChart(JPanel panelWhenInside, JTable pointsCollector) {
    panelWhenInside.removeAll();//from   ww w  .j ava  2  s.  c  o m
    panelWhenInside.setLayout(new java.awt.BorderLayout());

    //TODO 
    XYSeries seriersAllPoints = new XYSeries("All points");
    addPointsToSeries(seriersAllPoints, pointsCollector);

    // Add the seriersAllPoints to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(seriersAllPoints);

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            null, // x-axis Label
            null, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            false, // Use tooltips
            false // Configure chart to generate URLs?
    );

    final XYPlot plot = chart.getXYPlot();
    ChartPanel chartPanel = new ChartPanel(chart);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));

    plot.setRenderer(renderer);

    panelWhenInside.add(chartPanel, BorderLayout.CENTER);
    panelWhenInside.validate();

}

From source file:de.suse.swamp.modules.scheduledjobs.Statistics.java

/**
 * Generating the graphs that show the amount of running finished wfs over the time.
 *///w  w  w.j  a  v a 2s .  c  om
protected void generateWorkflowGraph(String templateName, Date startDate, Date endDate) throws Exception {
    List stats = StatisticStorage.loadStats(templateName, startDate, endDate);
    // only generate if we have stats: 
    if (stats != null && stats.size() > 0) {
        TimeSeriesCollection dataset = new TimeSeriesCollection();
        TimeSeriesCollection avgdataset = new TimeSeriesCollection();
        TimeSeries serie = new TimeSeries("running workflows", Day.class);
        TimeSeries avgserie = new TimeSeries("average age", Day.class);
        for (Iterator datait = stats.iterator(); datait.hasNext();) {
            Dbstatistics statisticItem = (Dbstatistics) datait.next();
            serie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getRunningcount());
            avgserie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getAvgage() / (3600 * 24));
        }
        dataset.addSeries(serie);
        avgdataset.addSeries(avgserie);

        JFreeChart chart = ChartFactory.createTimeSeriesChart("Running " + templateName + " workflows", "Date",
                "running workflows", dataset, false, false, false);

        // modify chart appearance
        chart.setBackgroundImageAlpha(0.5f);
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.getRangeAxis().setLabelPaint(Color.blue);

        // add the second line: 
        final NumberAxis axis2 = new NumberAxis("Avg. age in days");
        axis2.setLabelPaint(Color.red);
        plot.setRangeAxis(1, axis2);
        plot.setDataset(1, avgdataset);
        plot.mapDatasetToRangeAxis(1, 1);

        final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
        renderer2.setDrawOutlines(false);
        renderer2.setDrawSeriesLineAsPath(true);
        renderer2.setBaseShapesVisible(false);
        plot.setRenderer(1, renderer2);

        File image = new File(statPath + fs + templateName + ".png");
        if (image.exists())
            image.delete();
        try {
            ChartUtilities.saveChartAsPNG(image, chart, 750, 200);
        } catch (Exception e) {
            Logger.ERROR("Error generating graph for " + templateName + ", e: " + e.getMessage());
            e.printStackTrace();
            throw e;
        }
    }
}

From source file:Methods.CalculusBisection.java

public static ChartPanel createChartBisection(XYDataset datasetFunction) {// Method that populates and returns a Chart Pannel object, uses an entering paramether for the equation dataset and a global variable for the iteration points data set 

    datasetPointsBisection();//w  w  w .ja v a2  s.  co m

    JFreeChart chart = ChartFactory.createXYLineChart("Equation Chart", "X Axys", "Y Axys", datasetFunction,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();//declaring a renderer used to plot more than one datatset on the table

    plot.setDataset(1, datasetPoints);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(1, renderer);

    return new ChartPanel(chart);

}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.dec.TwoCoefsDecorator.java

/**
 * Creates a new dataset for visualizing the fitted function.
 * <p>// ww  w  .  j  av a 2  s  . c o  m
 * The new dataset is added to the end of the dataset list of the given plot.
 * </p>
 * 
 * @param aPlot Plot to which the new dataset must be added.
 * @return Index of the newly created dataset in the dataset list of <code>aPlot</code>.
 */
protected static int createDataset(XYPlot aPlot) {
    int i = aPlot.getDatasetCount();
    aPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    XYLineAndShapeRenderer rend = new XYLineAndShapeRenderer();
    rend.setSeriesLinesVisible(0, true);
    rend.setSeriesShapesVisible(0, false);
    aPlot.setRenderer(i, rend);
    return i;
}

From source file:asl.util.PlotMaker.java

public void plotZNE_3x3(ArrayList<double[]> channelData, double[] xsecs, int nstart, int nend,
        String eventString, String plotString) {

    // Expecting 9 channels packed like:            Panel   Trace1  Trace2  Trace3
    // channels[0] = 00-LHZ                           1     00-LHZ   10-LHZ   20-LHZ
    // channels[1] = 00-LHND                          2     00-LHND  10-LHND  20-LHND
    // channels[2] = 00-LHED                          3     00-LHED  10-LHED  20-LHED
    // channels[3] = 10-LHZ                           
    // channels[4] = 10-LHND                          
    // channels[5] = 10-LHED                          
    // channels[6] = 20-LHZ                           
    // channels[7] = 20-LHND                         
    // channels[8] = 20-LHED                        

    final String plotTitle = String.format("%04d%03d [Stn:%s] [Event:%s] %s", date.get(Calendar.YEAR),
            date.get(Calendar.DAY_OF_YEAR), station, eventString, plotString);
    final String pngName = String.format("%s/%s.%s.%s.png", outputDir, eventString, station, plotString);
    File outputFile = new File(pngName);

    // Check that we will be able to output the file without problems and if not --> return
    if (!checkFileOut(outputFile)) {
        System.out.format("== plotZNE_3x3: request to output plot=[%s] but we are unable to create it "
                + " --> skip plot\n", pngName);
        return;/*w w  w  . j a  v  a  2 s  .  com*/
    }

    if (channelData.size() != channels.length) {
        System.out.format("== plotZNE_3x3: Error: We have [%d channels] but [%d channelData]\n",
                channels.length, channelData.size());
        return;
    }

    XYSeries[] series = new XYSeries[channels.length];
    for (int i = 0; i < channels.length; i++) {
        series[i] = new XYSeries(channels[i].toString());
        double[] data = channelData.get(i);
        //for (int k = 0; k < xsecs.length; k++){
        for (int k = 0; k < data.length; k++) {
            series[i].add(xsecs[k], data[k]);
        }
    }

    // I. Panel I = Verticals

    // Use the first data array, within the plotted range (nstart - nend) to scale the plots:
    double[] data = channelData.get(0);
    double ymax = 0;
    for (int k = nstart; k < nend; k++) {
        if (data[k] > ymax)
            ymax = data[k];
    }

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    Paint[] paints = new Paint[] { Color.red, Color.blue, Color.green };
    for (int i = 0; i < paints.length; i++) {
        renderer.setSeriesPaint(i, paints[i]);
        renderer.setSeriesLinesVisible(i, true);
        renderer.setSeriesShapesVisible(i, false);
    }

    final NumberAxis verticalAxis = new NumberAxis("Displacement (m)");
    verticalAxis.setRange(new Range(-ymax, ymax));
    //verticalAxis.setTickUnit( new NumberTickUnit(5) );

    final NumberAxis horizontalAxis = new NumberAxis("Time (s)");
    horizontalAxis.setRange(new Range(nstart, nend));
    //horizontalAxis.setRange( new Range(0.00009 , 110) );
    final NumberAxis hAxis = new NumberAxis("Time (s)");
    hAxis.setRange(new Range(nstart, nend));

    final XYSeriesCollection seriesCollection1 = new XYSeriesCollection();
    seriesCollection1.addSeries(series[0]);
    seriesCollection1.addSeries(series[3]);
    seriesCollection1.addSeries(series[6]);
    //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, null, verticalAxis, renderer);
    //final XYPlot xyplot1 = new XYPlot((XYDataset)seriesCollection1, horizontalAxis, verticalAxis, renderer);
    final XYPlot xyplot1 = new XYPlot((XYDataset) seriesCollection1, hAxis, verticalAxis, renderer);
    double x = .95 * xsecs[nend];
    double y = .90 * ymax;
    XYTextAnnotation annotation1 = new XYTextAnnotation("Vertical", x, y);
    annotation1.setFont(new Font("SansSerif", Font.PLAIN, 14));
    xyplot1.addAnnotation(annotation1);

    // II. Panel II = North

    // Use the first data array, within the plotted range (nstart - nend) to scale the plots:
    data = channelData.get(1);
    ymax = 0;
    for (int k = nstart; k < nend; k++) {
        if (data[k] > ymax)
            ymax = data[k];
    }
    final NumberAxis verticalAxisN = new NumberAxis("Displacement (m)");
    verticalAxisN.setRange(new Range(-ymax, ymax));

    final XYSeriesCollection seriesCollection2 = new XYSeriesCollection();
    seriesCollection2.addSeries(series[1]);
    seriesCollection2.addSeries(series[4]);
    seriesCollection2.addSeries(series[7]);
    final XYPlot xyplot2 = new XYPlot((XYDataset) seriesCollection2, null, verticalAxisN, renderer);
    XYTextAnnotation annotation2 = new XYTextAnnotation("North-South", x, y);
    annotation2.setFont(new Font("SansSerif", Font.PLAIN, 14));
    xyplot2.addAnnotation(annotation2);

    // III. Panel III = East

    // Use the first data array, within the plotted range (nstart - nend) to scale the plots:
    data = channelData.get(2);
    ymax = 0;
    for (int k = nstart; k < nend; k++) {
        if (data[k] > ymax)
            ymax = data[k];
    }
    final NumberAxis verticalAxisE = new NumberAxis("Displacement (m)");
    verticalAxisE.setRange(new Range(-ymax, ymax));

    final XYSeriesCollection seriesCollection3 = new XYSeriesCollection();
    seriesCollection3.addSeries(series[2]);
    seriesCollection3.addSeries(series[5]);
    seriesCollection3.addSeries(series[8]);
    final XYPlot xyplot3 = new XYPlot((XYDataset) seriesCollection3, null, verticalAxisE, renderer);
    XYTextAnnotation annotation3 = new XYTextAnnotation("East-West", x, y);
    annotation3.setFont(new Font("SansSerif", Font.PLAIN, 14));
    xyplot3.addAnnotation(annotation3);

    //CombinedXYPlot combinedPlot = new CombinedXYPlot( horizontalAxis, CombinedXYPlot.VERTICAL );
    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.add(xyplot1, 1);
    combinedPlot.add(xyplot2, 1);
    combinedPlot.add(xyplot3, 1);
    combinedPlot.setGap(15.);

    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle));

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 800);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");

    }

}