Example usage for org.jfree.chart ChartFactory createXYLineChart

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

Introduction

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

Prototype

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

Source Link

Document

Creates a line chart (based on an XYDataset ) with default settings.

Usage

From source file:uk.co.moonsit.rmi.GraphClient.java

private void init(String config) throws IOException {
    //sp = ev3.createSampleProvider(portName, sensorClass, mode);
    String[] pars = config.split(";");
    String labels = pars[0];/*  ww w.jav a  2 s.  c o m*/
    String category = pars[1];
    String units = pars[2];
    //int minValue = Integer.parseInt(pars[3]);
    //int maxValue = Integer.parseInt(pars[4]);

    if (log) {
        openFile(labels);
    }

    String[] labelsArray = labels.split(",");
    //seriesArray = new XYSeries[labelsArray.length];
    int i = 0;
    for (String label : labelsArray) {
        XYSeries series = new XYSeries(label);
        series.setMaximumItemCount(dataLength);
        dataset.addSeries(series);
        //seriesArray[i++] = series;
    }
    JFreeChart chart = ChartFactory.createXYLineChart(title, category, units, (XYDataset) dataset,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(chart);
    //chartPanel.setMinimumSize(new Dimension(windowWidth, windowHeight));
    chartPanel.setPreferredSize(new Dimension(windowWidth, windowHeight));
    setContentPane(chartPanel);

    //XYPlot plot = chart.getXYPlot();
    //NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    //rangeAxis.setRange(minValue, maxValue);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    pack();
    setVisible(true);
}

From source file:org.openmrs.module.usagestatistics.web.view.chart.DateRangeChartView.java

@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) {
    UsageStatisticsService svc = Context.getService(UsageStatisticsService.class);
    List<Object[]> stats = svc.getDateRangeStats(null, null, null);

    String xAxisLabel = ContextProvider.getMessage("usagestatistics.chart.date");
    String yAxisLabel = ContextProvider.getMessage("usagestatistics.chart.records");
    String seriesUsages = ContextProvider.getMessage("usagestatistics.results.views");
    String seriesEncounters = ContextProvider.getMessage("usagestatistics.results.encounters");
    String seriesUpdates = ContextProvider.getMessage("usagestatistics.results.updates");

    // Get minimum date value in returned statistics
    Date minDate = (stats.size() > 0) ? (Date) (stats.get(0)[0]) : getFromDate();
    if (minDate.getTime() > getFromDate().getTime()) // Min date must be at least a week ago
        minDate = getFromDate();//w  w w .j a  va  2  s .c  o m
    // Maximum date defaults to today
    Date maxDate = (getUntilDate() != null) ? getUntilDate() : new Date();

    // Build a zeroized dataset of all dates in range       
    TimeTableXYDataset dataset = new TimeTableXYDataset();
    Calendar cal = new GregorianCalendar();
    cal.setTime(minDate);
    while (cal.getTime().getTime() <= maxDate.getTime()) {
        Date day = cal.getTime();
        dataset.add(new Day(day), 0, seriesUsages, false);
        dataset.add(new Day(day), 0, seriesEncounters, false);
        dataset.add(new Day(day), 0, seriesUpdates, false);
        cal.add(Calendar.DATE, 1);
    }

    // Update the dates for which we have statistics
    for (Object[] row : stats) {
        Date date = (Date) row[0];
        int usages = ((Number) row[1]).intValue();
        int encounters = ((Number) row[2]).intValue();
        int updates = ((Number) row[3]).intValue();
        dataset.add(new Day(date), usages, seriesUsages, false);
        dataset.add(new Day(date), encounters, seriesEncounters, false);
        dataset.add(new Day(date), updates, seriesUpdates, false);
    }
    dataset.setDomainIsPointsInTime(true);

    JFreeChart chart = ChartFactory.createXYLineChart(null, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, true, false, false);
    DateAxis xAxis = new DateAxis(xAxisLabel);

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

    return chart;
}

From source file:app.Plot.java

public JFreeChart createPlot(List<WordStatistic> was, Object item) {
    JFreeChart chart = null;//w ww  . jav a  2  s  .c  o m
    for (int i = 0; i < was.size(); i++) {
        if (was.get(i).getWord().equals(item)) {
            chart = ChartFactory.createXYLineChart("", " ?",
                    "? ?? ?? ",
                    createDataset(stepList, was.get(i).getPartFrequency()), PlotOrientation.VERTICAL, false,
                    true, false);
            chart.setBackgroundPaint(Color.white);
        }
    }
    return chart;
}

From source file:de.perdian.apps.dashboard.support.chart.ChartCreator.java

public JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(this.getTitle(), null, null, dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(null);//from   w w  w . jav  a  2 s.c  o  m
    chart.setBackgroundImageAlpha(0.0f);
    if (chart.getTitle() != null) {
        chart.getTitle().setFont(new Font(this.getFontName(), Font.BOLD, 14));
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundAlpha(0.0f);
    plot.setOutlinePaint(this.getColor());
    plot.getDomainAxis().setVisible(false);
    plot.getDomainAxis().setAxisLineVisible(false);
    plot.getDomainAxis().setMinorTickCount(10);
    plot.getDomainAxis().setTickMarksVisible(false);
    if (this.getDomainTickUnits() != null) {
        plot.getDomainAxis().setStandardTickUnits(this.getDomainTickUnits());
    }
    plot.getRangeAxis().setVisible(true);
    plot.getRangeAxis().setAxisLineVisible(false);
    plot.getRangeAxis().setTickLabelFont(new Font(this.getFontName(), Font.PLAIN, 10));
    plot.getRangeAxis().setTickLabelPaint(this.getColor());
    plot.getRangeAxis().setTickMarksVisible(false);
    if (this.getRangeTickUnits() != null) {
        plot.getRangeAxis().setStandardTickUnits(this.getRangeTickUnits());
    }
    plot.getRangeAxis().setAttributedLabel(this.getRangeAxisLabel());

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    for (int i = 0; i < this.getStrokeDefinitions().size(); i++) {
        ChartStrokeDefinition strokeDefinition = this.getStrokeDefinitions().get(i);
        strokeDefinition.applyTo(renderer, i);
    }

    return chart;

}

From source file:org.encog.workbench.tabs.rbf.RadialBasisFunctionsTab.java

public JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(null, "input (x)", "output (y)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

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

    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    plot.setDomainPannable(true);// w  w  w. j a  va2 s.c om
    plot.setRangePannable(true);
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setDrawSeriesLineAsPath(true);
    r.setSeriesStroke(0, new BasicStroke(1.5f));
    r.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 4.0f }, 0.0f));
    r.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 6.0f, 4.0f, 3.0f, 3.0f }, 0.0f));
    r.setSeriesStroke(3, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 4.0f, 4.0f }, 0.0f));

    return chart;
}

From source file:com.mugarov.neview.view.GraphPanel.java

public void setValues(ArrayList<DotBag> dotBags, ArrayList<Median> lines, String name) {

    CoordinateSeries ser;//from  w w  w  .  j  a v a 2s .c o m
    for (DotBag db : dotBags) {

        ser = new CoordinateSeries(db.getName());
        for (Dot d : db) {

            ser.add(d.getCoordinates(), d.getName(), d.getScaffoldName());
            //                System.out.println("New dot:"+d.getLogX()+", "+d.getLogY());
        }

        this.dotSeries.add(ser);
    }

    for (Median med : lines) {
        ser = new CoordinateSeries(med.getName());

        ser.add(med.getStart(), med.getName(), null);
        ser.add(med.getEnd(), med.getName(), null);
        //            System.out.println("New line from " + med.getStart().getX()+","+ med.getStart().getY()+" to "+med.getEnd().getX()+","+ med.getEnd().getY());
        this.lineSeries.add(ser);
    }

    this.seriesCollection = new CoordinateSeriesCollection();

    for (CoordinateSeries dotSeries : this.dotSeries) {
        this.seriesCollection.addSeries(dotSeries);
    }
    for (CoordinateSeries line : this.lineSeries) {
        this.seriesCollection.addSeries(line);
    }

    this.chart = ChartFactory.createXYLineChart(name, GraphPanel.XAxis, GraphPanel.YAxis, this.seriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    this.chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();

    ExpAxis x1Axis = new ExpAxis(GraphPanel.XAxis);
    ExpAxis y1Axis = new ExpAxis(GraphPanel.YAxis);

    NumberAxis x2Axis = new NumberAxis("Proportion to max of " + GraphPanel.XAxis);
    NumberAxis y2Axis = new NumberAxis("Proportion to max of " + GraphPanel.YAxis);

    plot.setDomainAxis(0, x1Axis);
    plot.setDomainAxis(1, x2Axis);
    plot.setRangeAxis(0, y1Axis);
    plot.setRangeAxis(1, y2Axis);
    //        plot.setDomainAxis(1, yAxis);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    for (int i = 0; i < this.dotSeries.size(); i++) {
        renderer.setSeriesLinesVisible(i, false);
        renderer.setSeriesPaint(i, this.colorGen.get(i));
    }

    for (int i = this.dotSeries.size(); i < this.lineSeries.size() + this.dotSeries.size(); i++) {
        renderer.setSeriesShapesVisible(i, false);
        //             renderer.setSeriesPaint(i, Color.black);
        renderer.setSeriesPaint(i, this.colorGen.get(i - this.dotSeries.size()));
    }

    renderer.setBaseToolTipGenerator(new ItemGenerator());

    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.white);

    plot.setDomainGridlinePaint(Color.MAGENTA);
    plot.setRangeGridlinePaint(Color.MAGENTA);

    boolean add = (this.chartPanel == null);
    this.chartPanel = new ChartPanel(chart);

    if (add) {
        this.content.add(this.chartPanel, BorderLayout.CENTER);
        this.scroll.setViewportView(this.chartPanel);
    }

    this.setBackground(Color.green);
    this.chartPanel.setBackground(Color.MAGENTA);
    this.updateUI();
}

From source file:org.jfree.chart.demo.PlotOrientationDemo1.java

private static JFreeChart createChart(int i, XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Chart " + (i + 1), "X", "Y", xydataset,
            PlotOrientation.VERTICAL, false, false, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ValueAxis valueaxis1 = xyplot.getRangeAxis();
    valueaxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:edu.turtlekit2.tools.chart.ChartWindow.java

/**
 * Creates a chart. Local use.// w w  w  . j ava  2 s .co m
 * @param dataset - the data for the chart.
 * @param title - the name of the chart
 * @param xName - the name of the x-axis.
 * @param yName - the name of the y-axis.
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset, String title, String xName, String yName) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xName, // x axis label
            yName, // 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...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

    //      renderer.setSeriesStroke(
    //               0, new BasicStroke(
    //                   2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
    //                   1.0f, new float[] {1.0f, 6.0f}, 0.0f
    //               )
    //           );
    //           renderer.setSeriesStroke(
    //               1, new BasicStroke(
    //                   2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
    //                   1.0f, new float[] {1.0f, 6.0f}, 0.0f
    //               )
    //           );
    //           renderer.setSeriesStroke(
    //               2, new BasicStroke(
    //                   2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
    //                   1.0f, new float[] {1.0f, 6.0f}, 0.0f
    //               )
    //           );
    //      
    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return chart;
}

From source file:edu.gmu.cs.sim.util.media.chart.TimeSeriesChartGenerator.java

protected void buildChart() {
    XYSeriesCollection collection = new XYSeriesCollection();

    chart = ChartFactory.createXYLineChart("Untitled Chart", "Untitled X Axis", "Untitled Y Axis", collection,
            PlotOrientation.VERTICAL, false, true, false);
    ((XYLineAndShapeRenderer) (((XYPlot) (chart.getPlot())).getRenderer())).setDrawSeriesLineAsPath(true);

    chart.setAntiAlias(true);// w w  w .  j  a  v a  2s.  c  o  m
    //chartPanel = new ScrollableChartPanel(chart, true); 
    chartPanel = buildChartPanel(chart);
    setChartPanel(chartPanel);
    //        chartHolder.getViewport().setView(chartPanel);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(collection);
}

From source file:DashboardInterface.LaunchGraph.java

/**
* Creates a chart./*w ww  .  java 2 s . c o  m*/
*
* @param dataset  a dataset.
*
* @return A chart.
*/
private JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart("Speed, Height and Tension v Time:", // title
            "Time", // x-axis label
            "Speed", // y-axis label
            null, // data
            PlotOrientation.VERTICAL, true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    plot = chart.getXYPlot();
    XYSplineRenderer splinerenderer1 = new XYSplineRenderer();
    XYSplineRenderer splinerenderer2 = new XYSplineRenderer();
    XYSplineRenderer splinerenderer3 = new XYSplineRenderer();

    XYDataset dataset1 = createDataset(0L, 130000);
    plot.setDataset(0, dataset1);
    plot.setRenderer(0, splinerenderer1);
    plot.getRenderer().setSeriesPaint(0, Color.MAGENTA);
    NumberAxis domainAxis = new NumberAxis("Time (Seconds from Start of Launch)");
    plot.setDomainAxis(domainAxis);
    //domainAxis.setRange(0, 30);
    NumberAxis heightYAxis = new NumberAxis("Height");
    heightYAxis.setRange(0, 1050);
    plot.setRangeAxis(heightYAxis);
    datasetMap.put("HEIGHT", dataset1);

    XYDataset dataset2 = createDataset2();
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, splinerenderer2);
    plot.getRenderer().setSeriesPaint(1, Color.BLUE);
    NumberAxis speedYAxis = new NumberAxis("Speed");
    speedYAxis.setRange(0, 50);
    plot.setRangeAxis(1, speedYAxis);
    datasetMap.put("SPEED", dataset2);

    XYDataset dataset3 = createDataset3();
    plot.setDataset(2, dataset3);
    plot.setRenderer(2, splinerenderer3);
    NumberAxis tensionYAxis = new NumberAxis("Tension");
    plot.getRenderer().setSeriesPaint(2, Color.RED);
    tensionYAxis.setRange(0, 8000);
    plot.setRangeAxis(2, tensionYAxis);
    datasetMap.put("TENSION", dataset3);

    plot.mapDatasetToRangeAxis(0, 0);//1st dataset to 1st y-axis
    plot.mapDatasetToRangeAxis(1, 1); //2nd dataset to 2nd y-axis
    plot.mapDatasetToRangeAxis(2, 2);

    //float[] dashArray = {1,1,1,0};
    //plot.addRangeMarker(new ValueMarker(maxTensionMarker, Color.YELLOW, new BasicStroke(1, 0, 0, 1, dashArray, 0)));
    //XYTextAnnotation text = new XYTextAnnotation("Max Tension", 10, maxTensionMarker);
    //text.setFont(new Font("SansSerif", Font.PLAIN, 9));
    //plot.addAnnotation(text);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);

    XYLineAndShapeRenderer renderer2 = (XYLineAndShapeRenderer) plot.getRendererForDataset(speedDataset);
    renderer2.setBaseShapesVisible(false);
    renderer2.setBaseShapesFilled(false);

    XYLineAndShapeRenderer renderer3 = (XYLineAndShapeRenderer) plot.getRendererForDataset(tensionDataset);
    renderer3.setBaseShapesVisible(false);
    renderer3.setBaseShapesFilled(false);

    return chart;
}