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:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotFrame.java

public IntensityPlotFrame(ParameterSet parameters) {

    PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue()[0];

    String title = "Intensity plot [" + peakList + "]";
    String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString();
    String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString();

    // create dataset
    dataset = new IntensityPlotDataset(parameters);

    // create new JFreeChart
    logger.finest("Creating new chart instance");
    Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue();
    boolean isCombo = (xAxisValueSource instanceof ParameterWrapper)
            && (((ParameterWrapper) xAxisValueSource).getParameter() instanceof ComboParameter);
    if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) {

        chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);//from   w  w  w .java  2 s.  c  om

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

        // set renderer
        StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true);
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

        CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    } else {

        chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);

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

        XYErrorRenderer renderer = new XYErrorRenderer();
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

    }

    chart.setBackgroundPaint(Color.white);

    // create chart JPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);

    IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this);
    add(toolBar, BorderLayout.EAST);

    // disable maximum size (we don't want scaling)
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    // set title properties
    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    LegendTitle legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setBorder(0, 0, 0, 0);

    Plot plot = chart.getPlot();

    // set shape provider
    IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier();
    plot.setDrawingSupplier(shapeSupplier);

    // set y axis properties
    NumberAxis yAxis;
    if (plot instanceof CategoryPlot)
        yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis();
    else
        yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis();
    NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat();
    if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT)
        yAxisFormat = MZmineCore.getConfiguration().getRTFormat();
    yAxis.setNumberFormatOverride(yAxisFormat);

    setTitle(title);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBackground(Color.white);
    pack();

}

From source file:org.gephi.statistics.plugin.dynamic.DynamicNbEdges.java

public String getReport() {
    //Transform to Map
    Map<Double, Integer> map = new HashMap<Double, Integer>();
    for (Interval<Integer> interval : counts.getIntervals()) {
        map.put(interval.getLow(), interval.getValue());
    }/*  www  .  ja va 2  s.c  om*/

    //Time series
    XYSeries dSeries = ChartUtils.createXYSeries(map, "Nb Edges Time Series");

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("# Edges Time Series", "Time", "# Edges", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, false);
    String imageFile = ChartUtils.renderChart(chart, "nb-edges-ts.png");

    NumberFormat f = new DecimalFormat("#0.000");

    String report = "<HTML> <BODY> <h1>Dynamic Number of Edges Report </h1> " + "<hr>" + "<br> Bounds: from "
            + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window
            + "<br> Tick: " + tick + "<br><br><h2> Number of edges over time: </h2>" + "<br /><br />"
            + imageFile;

    /*for (Interval<Integer> count : counts) {
    report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
    }*/
    report += "<br /><br /></BODY></HTML>";
    return report;
}

From source file:com.artnaseef.jmeter.report.HitsPerSecondReport.java

protected void createChart() {
    // create the chart...
    this.chart = ChartFactory.createXYLineChart("Hits per Second", // chart title
            "Second", // x axis label
            "Hits", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from  ww  w.j a  v  a  2s.  co  m*/
}

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
    );// w w  w. j  a  v a 2s.c  om

    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:org.xapagy.ui.tempdyn.GraphEvolution.java

/**
 * Generates the graph which plots the three choice scores (independent,
 * dependent and mood) for the evolution of a choice in time.
 * /*from  w ww .  j  ava2 s  . c  o  m*/
 * @param tdc
 *            - encompasses the selected choice
 * @param database
 *            - the database of values collected
 * @param agent
 * @param index
 *            - a list of time points which will be plotted on the x axis
 * @param choiceRange
 *            - the y axis will be [0, choiceRange]
 */
public static void graphChoiceEvolution(tdComponent tdc, tdDataBase database, Agent agent, List<Double> index,
        double choiceRange) {
    String label = PpChoice.ppConcise(tdc.getChoice(), agent);

    // create a general purpose xy collection for jfreechart
    XYSeriesCollection xysc = new XYSeriesCollection();
    // focus and memory
    xysc.addSeries(new XYSeries("ChoiceScoreIndependent"));
    xysc.addSeries(new XYSeries("ChoiceScoreDependent"));
    xysc.addSeries(new XYSeries("ChoiceScoreMood"));
    // Fill in the values
    for (Double time : index) {
        double dtime = time;
        double valueChoiceScoreIndependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time);
        xysc.getSeries("ChoiceScoreIndependent").add(dtime, valueChoiceScoreIndependent);
        double valueChoiceScoreDependent = database.getChoiceScoreDependent(tdc.getIdentifier(), time);
        xysc.getSeries("ChoiceScoreDependent").add(dtime, valueChoiceScoreDependent);
        double valueChoiceScoreMood = database.getChoiceScoreDependent(tdc.getIdentifier(), time);
        xysc.getSeries("ChoiceScoreMood").add(dtime, valueChoiceScoreMood);
    }
    //
    // ok, now let us create a graph
    //
    JPanel panel = new JPanel();
    // create a layout
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateGaps(true);
    layout.setAutoCreateContainerGaps(true);
    SequentialGroup sgv = layout.createSequentialGroup();
    layout.setVerticalGroup(sgv);
    ParallelGroup pgh = layout.createParallelGroup();
    layout.setHorizontalGroup(pgh);
    //
    // the graph with the focus and the memory
    //
    XYSeriesCollection xysFM = new XYSeriesCollection();
    xysFM.addSeries(xysc.getSeries("ChoiceScoreIndependent"));
    xysFM.addSeries(xysc.getSeries("ChoiceScoreDependent"));
    xysFM.addSeries(xysc.getSeries("ChoiceScoreMood"));
    JFreeChart chart = ChartFactory.createXYLineChart(label + " - Choice", "Time", "Value", xysFM,
            PlotOrientation.VERTICAL, true, false, false);
    GraphEvolution.setChartProperties(chart, GraphEvolution.lineStylesColorful);
    ChartPanel cp = new ChartPanel(chart);
    sgv.addComponent(cp);
    pgh.addComponent(cp);
    JFrame frame = new JFrame();
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

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

/**
 * Creates a chart./*from  w ww .j  av  a  2s. c  o m*/
 * 
 * @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
    );

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

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

    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    //  renderer.setSeriesShape(0, java.awt.Shape.round);
    renderer.setBaseShapesVisible(false);
    renderer.setBaseShapesFilled(false);
    renderer.setBaseLinesVisible(true);

    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0.05);
    rangeAxis.setLowerMargin(0.05);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    //  domainAxis.setTickLabelsVisible(false);
    // domainAxis.setTickMarksVisible(false);      
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setYSummary(dataset);

    return chart;
}

From source file:se.lnu.cs.doris.metrics.SLOC.java

private void generateImage(ImageType type) throws Exception {
    if (this.m_mainDir == null) {
        throw new Exception("Base directory not set.");
    }//w w w.j ava  2 s  .co m

    XYSeries linesOfCodeTotal = new XYSeries("Total lines");
    XYSeries linesOfCode = new XYSeries("Lines of code");
    XYSeries linesOfComments = new XYSeries("Lines of comments");
    XYSeries baseLine = new XYSeries("index 100");

    for (File f : this.m_mainDir.listFiles()) {
        if (f.isDirectory() && !f.getName().contains(this.m_avoid)) {

            int commitNumber = Utilities.parseInt(f.getName());
            int slocd = 0;
            int slocmt = 0;
            int sloct = 0;

            for (File sd : f.listFiles()) {
                if (!sd.getName().toLowerCase().contains(this.m_avoid)) {
                    slocd += this.countLines(sd, false);
                    slocmt += this.countLines(sd, true);
                    sloct += slocd + slocmt;
                }
            }

            if (this.m_baseValueTotal < 0) {
                this.m_baseValueTotal = sloct;
                this.m_baseValueComments = slocmt;
                this.m_baseValueCode = slocd;

                sloct = 100;
                slocmt = 100;
                slocd = 100;
            } else {
                sloct = (int) ((double) sloct / (double) this.m_baseValueTotal * 100);
                slocmt = (int) ((double) slocmt / (double) this.m_baseValueComments * 100);
                slocd = (int) ((double) slocd / (double) this.m_baseValueCode * 100);
            }

            linesOfCodeTotal.add(commitNumber, sloct);
            linesOfCode.add(commitNumber, slocd);
            linesOfComments.add(commitNumber, slocmt);
            baseLine.add(commitNumber, 100);

        }
    }

    XYSeriesCollection collection = new XYSeriesCollection();

    collection.addSeries(linesOfCodeTotal);
    collection.addSeries(linesOfCode);
    collection.addSeries(linesOfComments);
    collection.addSeries(baseLine);

    JFreeChart chart = ChartFactory.createXYLineChart(
            "Source lines of code change for " + this.m_projectName + " \nBase value code: "
                    + this.m_baseValueCode + "\nBase value comments: " + this.m_baseValueComments,
            "Commit", "SLOC change %", collection, PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();

    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setTickUnit(new NumberTickUnit(2));

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setTickUnit(new NumberTickUnit(10));

    switch (type) {
    case JPEG:
        ChartUtilities.saveChartAsJPEG(new File(this.m_mainDir.getAbsolutePath(), "sloc_chart.jpg"), chart,
                1000, 720);
        break;
    case PNG:
        ChartUtilities.saveChartAsPNG(new File(this.m_mainDir.getAbsolutePath(), "sloc_chart.png"), chart, 1000,
                720);
        break;
    default:
        break;
    }
}

From source file:fungus.PeerRatioChartFrame.java

public PeerRatioChartFrame(String prefix) {
    simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES);
    this.setTitle("MycoNet Statistics Chart");
    graph = JungGraphObserver.getGraph();

    //data.add(-1,0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.setAutoWidth(false);//from   w  ww .j  a va  2s  .  c om
    dataset.setIntervalWidth(simulationCycles);

    //averageUtilizationData = new XYSeries("Average Utilization");
    //dataset.addSeries(averageUtilizationData);
    //averageStableUtilizationData = new XYSeries("Avg Stable Util");
    //dataset.addSeries(averageStableUtilizationData);
    bulwarkRatioData = new XYSeries("Bulwark Ratio");
    dataset.addSeries(bulwarkRatioData);
    biomassRatioData = new XYSeries("Biomass Ratio");
    dataset.addSeries(biomassRatioData);
    hyphaRatioData = new XYSeries("Hypha Ratio");
    dataset.addSeries(hyphaRatioData);
    // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio");
    // dataset.addSeries(stableHyphaRatioData);

    //XYSeriesCollection dataset;

    JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart);

    XYPlot xyplot = peerRatioChart.getXYPlot();

    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setRange(0, 1);

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

    //        BufferedImage chartImage = chart.createBufferedImage(500,300);
    //        chartLabel = new JLabel();
    //chartLabel.setIcon(new ImageIcon(chartImage));

    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    JPanel labelPane = new JPanel();
    labelPane.setLayout(new GridLayout(1, 1));
    //chartPane.setPreferredSize(new java.awt.Dimension(500, 300));
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

    ////contentPane.add(labelPane,BorderLayout.PAGE_START);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    contentPane.add(peerRatioChartPanel, BorderLayout.CENTER);
    //contentPane.add(Box.createRigidArea(new Dimension(0,5)));
    ////contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //data = node.getHyphaData();
    //link = node.getHyphaLink();
    //mycocast = node.getMycoCast();

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    //chartPanel.add(chartLabel);

    /*JButton updateButton = new JButton("Refresh");
      ActionListener updater = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      refreshData();
      }
      };
      updateButton.addActionListener(updater);
            
      JButton closeButton = new JButton("Close");
      ActionListener closer = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      closeFrame();
      }
      };
      closeButton.addActionListener(closer);
            
      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(updateButton);
      buttonPane.add(Box.createRigidArea(new Dimension(5,0)));
      buttonPane.add(closeButton);
      refreshData();
    */

    //JungGraphObserver.addChangeListener(this);

    this.pack();
    this.setVisible(true);
}

From source file:biz.ixnay.pivot.charts.skin.jfree.LineChartViewSkin.java

@Override
protected JFreeChart createChart() {
    LineChartView chartView = (LineChartView) getComponent();

    String title = chartView.getTitle();
    String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
    String verticalAxisLabel = chartView.getVerticalAxisLabel();
    boolean showLegend = chartView.getShowLegend();

    String seriesNameKey = chartView.getSeriesNameKey();
    List<?> chartData = chartView.getChartData();

    JFreeChart chart;//from w w  w  .  j  av  a2  s .  c  o  m
    ChartView.CategorySequence categories = chartView.getCategories();
    if (categories.getLength() > 0) {
        CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

        if (threeDimensional) {
            chart = ChartFactory.createLineChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else {
            chart = ChartFactory.createLineChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        }

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        CategoryLabelPositions categoryLabelPositions = CategoryLabelPositions
                .createUpRotationLabelPositions(categoryLabelRotation);
        domainAxis.setCategoryLabelPositions(categoryLabelPositions);

        if (rangeAxisRange != null) {
            ValueAxis rangeAxis = plot.getRangeAxis();
            rangeAxis.setRange(rangeAxisRange);
        }
    } else {
        chart = ChartFactory.createXYLineChart(title, horizontalAxisLabel, verticalAxisLabel,
                new XYSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend, false,
                false);

        if (rangeAxisRange != null) {
            XYPlot plot = (XYPlot) chart.getPlot();
            ValueAxis rangeAxis = plot.getRangeAxis();
            rangeAxis.setRange(rangeAxisRange);
        }
    }

    return chart;
}

From source file:playground.artemc.socialCost.MeanTravelTimeWriter.java

/**
 * @return a graphic showing the number of agents in the evacuated area
 *//*from   w  w  w  .  ja  v a2s  .co m*/
private JFreeChart getGraphic(String[] modeNames, double data[][]) {

    final XYSeriesCollection xyData = new XYSeriesCollection();

    for (int j = 0; j < modeNames.length; j++) {
        String modeName = modeNames[j];
        double[] d = data[j];

        XYSeries dataSerie = new XYSeries(modeName, false, true);

        for (int i = 0; i < d.length; i++) {
            dataSerie.add(i, d[i]);
        }

        xyData.addSeries(dataSerie);
    }

    //      final JFreeChart chart = ChartFactory.createXYStepChart(
    final JFreeChart chart = ChartFactory.createXYLineChart("mean trip travel time, all transport modes modes",
            "iteration", "travel time", xyData, PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

    final CategoryAxis axis1 = new CategoryAxis("hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(new NumberAxis("time"));
    return chart;
}