Example usage for org.jfree.chart ChartFactory createXYStepChart

List of usage examples for org.jfree.chart ChartFactory createXYStepChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createXYStepChart.

Prototype

public static JFreeChart createXYStepChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a stepped XY plot with default settings.

Usage

From source file:net.sf.jsfcomp.chartcreator.utils.ChartUtils.java

public static JFreeChart createChartWithXYDataSet(ChartData chartData) {
    XYDataset dataset = (XYDataset) chartData.getDatasource();
    String type = chartData.getType();
    String xAxis = chartData.getXlabel();
    String yAxis = chartData.getYlabel();
    boolean legend = chartData.isLegend();

    JFreeChart chart = null;//from   ww  w .  ja v  a  2s .c  o m
    PlotOrientation plotOrientation = ChartUtils.getPlotOrientation(chartData.getOrientation());

    if (type.equalsIgnoreCase("timeseries")) {
        chart = ChartFactory.createTimeSeriesChart("", xAxis, yAxis, dataset, legend, true, false);
    } else if (type.equalsIgnoreCase("xyline")) {
        chart = ChartFactory.createXYLineChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("polar")) {
        chart = ChartFactory.createPolarChart("", dataset, legend, true, false);
    } else if (type.equalsIgnoreCase("scatter")) {
        chart = ChartFactory.createScatterPlot("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("xyarea")) {
        chart = ChartFactory.createXYAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("xysteparea")) {
        chart = ChartFactory.createXYStepAreaChart("", xAxis, yAxis, dataset, plotOrientation, legend, true,
                false);
    } else if (type.equalsIgnoreCase("xystep")) {
        chart = ChartFactory.createXYStepChart("", xAxis, yAxis, dataset, plotOrientation, legend, true, false);
    } else if (type.equalsIgnoreCase("bubble")) {
        chart = ChartFactory.createBubbleChart("", xAxis, yAxis, (XYZDataset) dataset, plotOrientation, legend,
                true, false);
    } else if (type.equalsIgnoreCase("candlestick")) {
        chart = ChartFactory.createCandlestickChart("", xAxis, yAxis, (OHLCDataset) dataset, legend);
    } else if (type.equalsIgnoreCase("boxandwhisker")) {
        chart = ChartFactory.createBoxAndWhiskerChart("", xAxis, yAxis, (BoxAndWhiskerXYDataset) dataset,
                legend);
    } else if (type.equalsIgnoreCase("highlow")) {
        chart = ChartFactory.createHighLowChart("", xAxis, yAxis, (OHLCDataset) dataset, legend);
    } else if (type.equalsIgnoreCase("histogram")) {
        chart = ChartFactory.createHistogram("", xAxis, yAxis, (IntervalXYDataset) dataset, plotOrientation,
                legend, true, false);
    } else if (type.equalsIgnoreCase("wind")) {
        chart = ChartFactory.createWindPlot("", xAxis, yAxis, (WindDataset) dataset, legend, true, false);
    }

    if (chart.getPlot() instanceof XYPlot) {
        chart.getXYPlot().setDomainGridlinesVisible(chartData.isDomainGridLines());
        chart.getXYPlot().setRangeGridlinesVisible(chartData.isRangeGridLines());

        if (chartData.getGenerateMap() != null)
            chart.getXYPlot().getRenderer().setURLGenerator(new StandardXYURLGenerator(""));
    }

    setXYSeriesColors(chart, chartData);

    setXYExtensions(chart, chartData);

    return chart;
}

From source file:desmoj.extensions.grafic.util.Plotter.java

/**
  * Build a JPanel with plotType of a DesmoJ time-series dataset.
 * When allowMultipleValues is set, multiple range values of a time value are allowed.
 * In the opposite Case only the last range value of a time value is accepted.
 * In the case ts.getShowTimeSpansInReport() the data values are interpreted as
 * a timespan in a appropriate time unit. 
  * @param ts               DesmoJ time-series dataset
  * @param plotType          possible Values: 
  *                         Plotter.TimeSeries_ScatterPlot, 
  *                         Plotter.TimeSeries_StepChart
  *                         Plotter.TimeSeries_LinePlot
 * @param allowMultipleValues/*from w  w w.j a  v  a  2  s .  c  o m*/
 * @return
 */
private JPanel getTimeSeriesPanel(TimeSeries ts, int plotType, boolean allowMultipleValues) {
    JFreeChart chart;
    TimeSeriesDataSetAdapter dataset = new TimeSeriesDataSetAdapter(ts, allowMultipleValues);
    switch (plotType) {
    case Plotter.TimeSeries_LineChart:
        chart = ChartFactory.createXYLineChart(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    case Plotter.TimeSeries_ScatterPlot:
        chart = ChartFactory.createScatterPlot(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    case Plotter.TimeSeries_StepChart:
        chart = ChartFactory.createXYStepChart(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    default:
        chart = ChartFactory.createScatterPlot(ts.getName(), "Time", "Observation", dataset,
                PlotOrientation.VERTICAL, false, false, false);
        break;
    }
    if (ts.getDescription() != null)
        chart.setTitle(ts.getDescription());

    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setNoDataMessage("NO DATA");
    if (ts.getShowTimeSpansInReport() && !dataset.isValid())
        xyplot.setNoDataMessage("NO VALID TIMESPANS");
    xyplot.setDomainZeroBaselineVisible(false);
    xyplot.setRangeZeroBaselineVisible(false);

    DateAxis dateAxis = new DateAxis();
    xyplot.setDomainAxis(dateAxis);
    this.configureDomainAxis(dateAxis);

    String numberLabel;
    if (!dataset.isValid())
        numberLabel = "Unit: invalid";
    else if (ts.getShowTimeSpansInReport())
        numberLabel = "Unit: timespan [" + dataset.getRangeTimeUnit().name() + "]";
    else if (ts.getUnit() != null)
        numberLabel = "Unit: [" + ts.getUnit() + "]";
    else
        numberLabel = "Unit: unknown";
    NumberAxis numberAxis = new NumberAxis();
    xyplot.setRangeAxis(numberAxis);
    this.configureRangeAxis(numberAxis, numberLabel);

    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setSeriesOutlinePaint(0, Color.black);
    xylineandshaperenderer.setUseOutlinePaint(true);

    ChartPanel panel = new ChartPanel(chart);
    panel.setVerticalAxisTrace(false);
    panel.setHorizontalAxisTrace(false);
    panel.setPopupMenu(null);
    panel.setDomainZoomable(false);
    panel.setRangeZoomable(false);

    return panel;
}

From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java

/**
 * Build content for animationType StatisticGrafic.ANIMATION_TimeValueDiagram
 * @return// w w  w.j a  va2  s.co m
 * @throws ModelException
 */
private JPanel buildTimeValueDiagramPanel() throws ModelException {
    JPanel out = null;
    XYPlot plot = null;
    switch (this.statistic.getTypeData()) {
    case Statistic.DATA_Observations:
        XYSeriesCollection dataset1 = new XYSeriesCollection();
        dataset1.addSeries(this.statistic.getObservationSerie());
        this.chart = ChartFactory.createScatterPlot(null, "Time", null, dataset1, PlotOrientation.VERTICAL,
                false, true, false);
        this.chart.setBackgroundPaint(Grafic.COLOR_BACKGROUND);
        plot = this.chart.getXYPlot();
        break;
    case Statistic.DATA_TimeSeries:
        TimeSeriesCollection dataset2 = new TimeSeriesCollection();
        dataset2.addSeries(this.statistic.getTimeSerie());
        this.chart = ChartFactory.createXYStepChart(null, "Time", null, dataset2, PlotOrientation.VERTICAL,
                false, true, false);
        this.chart.setBackgroundPaint(Grafic.COLOR_BACKGROUND);
        plot = this.chart.getXYPlot();
        break;
    }
    if (plot != null) {
        plot.setBackgroundPaint(StatisticGrafic.DIAGRAM_BACKGROUND);
        plot.setDomainGridlinePaint(StatisticGrafic.DIAGRAM_GRID);
        plot.setRangeGridlinePaint(StatisticGrafic.DIAGRAM_GRID);
        plot.setDomainCrosshairVisible(true);
        plot.setRangeCrosshairVisible(true);
        String rangeAxisLabel = "";
        switch (statistic.getTypeIndex()) {
        case Statistic.INDEX_Min_Max:
            rangeAxisLabel = "min - max";
            break;
        case Statistic.INDEX_Mean_StdDev:
            rangeAxisLabel = "\u03BC-\u03C3 - mean - \u03BC+\u03C3";
            break;
        }
        //this.buildTimeValueDiagramAxisFormat(plot, rangeAxisLabel);
        plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
        plot.getRenderer().setSeriesPaint(0, StatisticGrafic.DIAGRAM_FORGROUND);

    }
    out = new ChartPanel(chart);
    out.setPreferredSize(new Dimension(350, 200));
    return out;
}

From source file:playground.christoph.evacuation.analysis.AgentsInMunicipalityEventsHandler.java

private JFreeChart getGraphic() {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries insideSerie = new XYSeries("total inside area", false, true);
    final XYSeries residentsSerie = new XYSeries("residents inside area", false, true);
    final XYSeries commutersSerie = new XYSeries("commuters inside area", false, true);

    for (int i = 0; i < plotData.size(); i++) {
        PlotData pd = plotData.get(i);/*ww w.j  a v  a  2 s  .  co  m*/
        double hour = pd.time / 3600.0;
        insideSerie.add(hour, pd.commuterAgentCount + pd.residentAgentCount);
        residentsSerie.add(hour, pd.residentAgentCount);
        commutersSerie.add(hour, pd.commuterAgentCount);
    }
    xyData.addSeries(insideSerie);
    xyData.addSeries(residentsSerie);
    xyData.addSeries(commutersSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart("agents inside area", "time [hour]", "# agents",
            xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    NumberAxis na = new NumberAxis("time [hour]");
    na.setRange(0, maxTime / 3600.0);
    na.setLabelFont(plot.getRangeAxis().getLabelFont());
    na.setTickLabelFont(plot.getRangeAxis().getTickLabelFont());
    plot.setDomainAxis(na);
    return chart;
}

From source file:lucee.runtime.tag.Chart.java

private void chartStep() throws PageException, IOException {
    // create the chart...
    final JFreeChart chart = ChartFactory.createXYStepChart(title, xaxistitle, yaxistitle,
            createXYSeriesCollection(), PlotOrientation.VERTICAL, false, true, false);
    final XYPlot p = chart.getXYPlot();
    Font _font = getFont();//  w ww .ja  v a  2 s.c  o m
    // settings            

    setBackground(chart, p);
    setBorder(chart, p);
    set3d(p);
    setFont(chart, _font);
    setLabelFormat(chart);
    p.getDomainAxis().setRange(
            Range.expandToInclude(p.getDomainAxis().getRange(), p.getDomainAxis().getUpperBound() + 0.25));
    p.getDomainAxis().setRange(
            Range.expandToInclude(p.getDomainAxis().getRange(), p.getDomainAxis().getLowerBound() - 0.25));
    setLegend(chart, p, _font);
    setTooltip(chart);
    setScale(chart);
    setAxis(chart);
    setColor(chart);

    writeOut(chart);
}

From source file:src.planning.PlanSimulator.java

public static List<ChartPanel> drawCharts(Element analysis, Element problem) {
    List<ChartPanel> charts = new ArrayList<ChartPanel>();

    // draw the charts
    List<?> variables = analysis.getChild("variables").getChildren("variable");
    for (Iterator<?> iter = variables.iterator(); iter.hasNext();) {
        Element variable = (Element) iter.next();

        Element domainObject = null;
        try {/*  w w w.  j  a v a 2  s .c om*/
            XPath path = new JDOMXPath("elements/objects/object[@id='"
                    + variable.getChild("object").getAttributeValue("id") + "']");
            domainObject = (Element) path.selectSingleNode(problem.getParentElement().getParentElement());
        } catch (JaxenException e) {
            e.printStackTrace();
        }

        Element attribute = variable.getChild("object").getChild("attribute");
        Element classAttr = null;
        try {
            XPath path = new JDOMXPath(
                    "project/elements/classes/class[@id='" + attribute.getAttributeValue("class")
                            + "']/attributes/attribute[@id='" + attribute.getAttributeValue("id") + "']");
            classAttr = (Element) path.selectSingleNode(problem.getDocument());
        } catch (JaxenException e) {
            e.printStackTrace();
        }

        String chartTitle = domainObject.getChildText("name") + "." + classAttr.getChildText("name");

        if (variable.getAttributeValue("type").equals("attr")) {
            // attribute
            String attrType = variable.getChild("object").getChild("attribute").getAttributeValue("type");
            if (attrType.equals("1")) { //BOOLEAN attribute

                XYSeriesCollection dataset = new XYSeriesCollection();
                XYSeries series = new XYSeries("Boolean");
                int stepIndex = 0;
                for (Iterator<?> iterator = variable.getChild("values").getChildren("value")
                        .iterator(); iterator.hasNext();) {
                    Element value = (Element) iterator.next();
                    series.add(stepIndex++, (value.getText().equals("false") ? 0 : 1));
                }
                dataset.addSeries(series);

                JFreeChart chart = ChartFactory.createXYStepChart(chartTitle, "Values", "Steps", dataset,
                        PlotOrientation.VERTICAL, false, true, false);

                XYPlot plot = (XYPlot) chart.getPlot();
                NumberAxis domainAxis = new NumberAxis("Steps");
                domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                domainAxis.setAutoRangeIncludesZero(false);
                plot.setDomainAxis(domainAxis);

                String[] values = { "false", "true" };
                SymbolAxis rangeAxis = new SymbolAxis("Values", values);
                plot.setRangeAxis(rangeAxis);

                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new Dimension(chartPanel.getSize().width, 175));

                charts.add(chartPanel);

            } else if (attrType.equals("2") || attrType.equals("3")) { //NUMERIC attributes

                XYSeriesCollection dataset = new XYSeriesCollection();
                XYSeries series = new XYSeries("variable");
                int stepIndex = 0;
                for (Iterator<?> iterator = variable.getChild("values").getChildren("value")
                        .iterator(); iterator.hasNext();) {
                    Element value = (Element) iterator.next();
                    series.add(stepIndex++, Double.parseDouble(value.getText()));
                }
                dataset.addSeries(series);

                JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, "Steps", "Values", dataset,
                        PlotOrientation.VERTICAL, false, true, false);

                XYPlot xyPlot = (XYPlot) chart.getPlot();
                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
                renderer.setShapesVisible(true);
                renderer.setShapesFilled(true);

                NumberAxis rangeAxis = (NumberAxis) xyPlot.getRangeAxis();
                rangeAxis.setAutoRangeIncludesZero(true);
                rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                if (attrType.equals("2")) {
                    NumberAxis domainAxis = (NumberAxis) xyPlot.getDomainAxis();
                    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                }

                ChartPanel chartPanel = new ChartPanel(chart);

                charts.add(chartPanel);
            } else if (!attrType.equals("4")) {//NOT PRIMITIVE attributes

                Element attrClass = null;
                try {
                    XPath path = new JDOMXPath(
                            "project/elements/classes/class[@id='" + classAttr.getChildText("type") + "']");
                    attrClass = (Element) path.selectSingleNode(problem.getDocument());
                } catch (JaxenException e) {
                    e.printStackTrace();
                }

                if (attrClass != null) {

                    List<Element> classes = XMLUtilities.getClassDescendents(attrClass);
                    String query = "elements/objects/object[";
                    for (Iterator<?> iterator = classes.iterator(); iterator.hasNext();) {
                        Element childClass = (Element) iterator.next();
                        query += "class='" + childClass.getAttributeValue("id") + "'";

                        query += " or ";// the last or is for the parent class                     

                    }
                    query += "class='" + attrClass.getAttributeValue("id") + "']";

                    // get all the objects of all descendant classes, including the parent class
                    List<?> objects = null;
                    try {
                        XPath path = new JDOMXPath(query);
                        objects = path.selectNodes(problem.getParentElement().getParentElement());
                    } catch (JaxenException e) {
                        e.printStackTrace();
                    }
                    if (objects.size() > 0) {
                        //build a list with all the objects names                     
                        String[] names = new String[objects.size() + 1];// the array is for the axis
                        names[0] = "null";// default null value

                        List<String> objectNames = new ArrayList<String>();
                        int i = 1;
                        for (Iterator<?> iterator = objects.iterator(); iterator.hasNext();) {
                            Element object = (Element) iterator.next();
                            names[i++] = object.getChildText("name");
                            objectNames.add(object.getChildText("name").toLowerCase());
                        }

                        XYSeriesCollection dataset = new XYSeriesCollection();
                        XYSeries series = new XYSeries("Objects");
                        int stepIndex = 0;
                        for (Iterator<?> iterator = variable.getChild("values").getChildren("value")
                                .iterator(); iterator.hasNext();) {
                            Element value = (Element) iterator.next();

                            series.add(stepIndex++, objectNames.indexOf(value.getText().toLowerCase()) + 1);
                        }
                        dataset.addSeries(series);

                        // draw the chart
                        JFreeChart chart = ChartFactory.createXYStepChart(chartTitle, "Objects", "Steps",
                                dataset, PlotOrientation.VERTICAL, false, true, false);

                        XYPlot plot = (XYPlot) chart.getPlot();
                        NumberAxis domainAxis = new NumberAxis("Steps");
                        domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                        domainAxis.setAutoRangeIncludesZero(false);
                        plot.setDomainAxis(domainAxis);

                        SymbolAxis rangeAxis = new SymbolAxis("Objects", names);
                        plot.setRangeAxis(rangeAxis);

                        ChartPanel chartPanel = new ChartPanel(chart);

                        charts.add(chartPanel);
                    }
                }
            }
        }
    }

    return charts;
}