Example usage for org.jfree.chart ChartFactory createLineChart

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

Introduction

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

Prototype

public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a line chart with default settings.

Usage

From source file:com.church.tools.ChartTools.java

/**
 * Generate line chart./*  w w  w.  j  av  a2  s. co  m*/
 * 
 * @param title the title
 * @param values the values
 * @param captions the captions
 * @param width the width
 * @param height the height
 * @param color the color
 * 
 * @return the buffered image
 */
public static BufferedImage GenerateLineChart(String title, double[] values, String[] captions, int width,
        int height, Color color) {
    BufferedImage bufferedImage = null;
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < values.length; i++) {
        dataset.addValue(values[i], "Balance Timeline", String.valueOf(i + 1));
    }
    JFreeChart chart = ChartFactory.createLineChart(title, "Balance Timeline", "Amount", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(color);
    bufferedImage = chart.createBufferedImage(width, height);
    return bufferedImage;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartLineGraphSource.java

@Override
public JFreeChart createChart(String title, String xLabel, String yLabel, CategoryDataset dataset,
        boolean legend, boolean graphToolTip) {
    PlotOrientation orientation = getParam(PLOT_ORIENTATION, PlotOrientation.class, DEFAULT_PLOT_ORIENTATION);

    JFreeChart result = ChartFactory.createLineChart(title, xLabel, yLabel, dataset, orientation, legend,
            graphToolTip, false);//from  ww w .j  av a2  s . c o  m

    CategoryLineGraphRenderer r = new CategoryLineGraphRenderer(data);

    Shape graphShape = getParam(GraphSource.GRAPH_SHAPE, Shape.class, DEFAULT_GRAPH_SHAPE);
    Paint graphColor = getParam(GraphSource.GRAPH_COLOR, Paint.class, DEFAULT_GRAPH_COLOR);
    Stroke graphStroke = getParam(GraphSource.GRAPH_STROKE, Stroke.class, new BasicStroke());

    setupRenderer(r, graphColor, graphShape, graphStroke);
    result.getCategoryPlot().setRenderer(r);

    return result;
}

From source file:org.evosuite.jenkins.plot.Plot.java

@Override
protected JFreeChart createGraph() {
    final JFreeChart chart = ChartFactory.createLineChart(null, "Build Number #", this.yLabel, this.dataset,
            PlotOrientation.VERTICAL, true, true, true);
    chart.setBackgroundPaint(Color.WHITE);

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

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);/*from   www  .  ja va 2 s .  com*/
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    plot.setDomainAxis(domainAxis);
    plot.setBackgroundPaint(Color.WHITE);

    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    //yAxis.setRange(0.0, 100.0);

    URLAndTooltipRenderer urlRenderer = new URLAndTooltipRenderer(this.project.getProject());
    ColorPalette.apply(urlRenderer);
    plot.setRenderer(urlRenderer);

    return chart;
}

From source file:se.backede.jeconomix.forms.report.TransactionsTotalReport.java

public void addLineChart(Map<String, List<TransactionReportDto>> reports) {
    JFreeChart lineChart = ChartFactory.createLineChart("Total", "Month", "Kronor",
            ReportUtils.createDataset(reports, Boolean.FALSE), PlotOrientation.VERTICAL, true, true, true);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(lineChartPanel.getWidth(), lineChartPanel.getHeight()));
    lineChartPanel.setLayout(new BorderLayout());
    lineChartPanel.add(chartPanel, BorderLayout.NORTH);
}

From source file:spec.reporter.Utils.java

public static void createBmResultGraph(BenchmarkRecord record) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String iterName = "";
    double max = 0;
    double min = Long.MAX_VALUE;
    for (int i = 0; i < record.iterRecords.size(); i++) {
        BenchmarkRecord.IterationRecord iterRecord = (BenchmarkRecord.IterationRecord) record.iterRecords
                .get(i);// w ww  .  j  a va  2 s . c o  m
        String shortName = iterRecord.iterName.replaceFirst("ation", "");
        if (iterRecord.score > max) {
            max = iterRecord.score;
            iterName = shortName;
        }

        if (iterRecord.score < min) {
            min = iterRecord.score;
        }

        dataset.addValue(iterRecord.score, " ", shortName);
    }

    JFreeChart chart = ChartFactory.createLineChart("  ", "iterations", Constants.WORKLOAD_METRIC, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(201, 222, 254));
    plot.setRangeGridlinePaint(Color.WHITE);
    if (record.isValidRun() && min != Long.MAX_VALUE) {
        plot.getRangeAxis().setRange(min - 10, max + 10);
    } else {
        plot.getRangeAxis().setRange(0, max + 10);
    }
    ValueMarker vm = new ValueMarker(record.maxScore);
    vm.setLabel(Utils.df.format(record.maxScore));
    vm.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    vm.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT);

    plot.addRangeMarker(vm);
    CategoryMarker marker = new CategoryMarker(iterName);
    marker.setDrawAsLine(true);
    marker.setPaint(vm.getPaint());
    plot.addDomainMarker(marker);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setFillPaint(Color.WHITE);
    renderer.setSeriesPaint(0, Color.BLUE.darker());

    try {
        ChartUtilities.saveChartAsJPEG(new File(Utils.getFullImageName(record.name + "_results")), chart, 300,
                200);
    } catch (Exception e) {
        System.out.println("Problems...");
    }
}

From source file:com.orsonpdf.demo.PDFBarChartDemo1.java

/**
 * Creates a sample chart.// w  ww . j  a v a  2s  .c  om
 *
 * @param dataset  a dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value", dataset,
            PlotOrientation.VERTICAL, true, false, false);

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

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);

    // customise the renderer...
    StatisticalBarRenderer renderer = new StatisticalBarRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setErrorIndicatorPaint(Color.black);
    renderer.setIncludeBaseInRange(false);
    plot.setRenderer(renderer);

    // ensure the current theme is applied to the renderer just added
    ChartUtilities.applyCurrentTheme(chart);

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelPaint(Color.yellow);
    renderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    return chart;
}

From source file:bbank.QuantityTimeGraphWindow.java

public QuantityTimeGraphWindow() {
    initComponents();//from   ww w.j  a va  2  s. co m

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    BloodStock.collectGraphData(SelectedItem);
    String title = "Quantity vs Time Graph";
    switch (SelectedItem) {
    case 0:
        title = "Quantity vs Time Graph for Blood type A";
        for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) {
            dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "",
                    "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/"
                            + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1));
        }
        break;
    case 1:
        title = "Quantity vs Time Graph for Blood type B";
        for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) {
            dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "",
                    "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/"
                            + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1));
        }
        break;
    case 2:
        title = "Quantity vs Time Graph for Blood type O";
        for (int i = 0; i < BloodStock.QuantityGraph.size(); i++) {
            dataset.addValue(((double) BloodStock.QuantityGraph.get(i)), "",
                    "" + ((Date) BloodStock.DateGraph.get(i)).getDate() + "/"
                            + (((Date) BloodStock.DateGraph.get(i)).getMonth() + 1));
        }
        break;
    }

    JFreeChart chart = ChartFactory.createLineChart(title, "Date", "Amount (litres)", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    CategoryPlot catPlot = chart.getCategoryPlot();
    catPlot.setRangeGridlinePaint(Color.BLACK);

    ChartPanel chartpanel = new ChartPanel(chart);
    jPanel1.removeAll();
    jPanel1.add(chartpanel);
    jPanel1.validate();
}

From source file:org.openmrs.module.laboratorymanagement.web.chart.EvolutionOfClientRegisteredPerDay.java

/**
 * @see org.openmrs.module.vcttrac.web.view.chart.AbstractChartView#createChart(java.util.Map,
 *      javax.servlet.http.HttpServletRequest)
 *///from   w w  w.  j ava 2s .  c o  m
@Override
protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request, String patientIdstr,
        String locationIdstr, int conceptId, Date startDate, Date endDate) {

    String categoryAxisLabel = " Year";
    String valueAxisLabel = "Number of Lab tests";

    String title = "EVolution of labotory test:"
            + Context.getConceptService().getConcept(conceptId).getDisplayString();

    JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel,
            createDataset(patientIdstr, locationIdstr, conceptId, startDate, endDate), // data
            PlotOrientation.VERTICAL, true, false, false);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // customise the range axis...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setUpperMargin(0.15);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelsVisible(true);

    return chart;
}

From source file:com.js.quickestquail.ui.stats.YearStat.java

private JFreeChart generateChart() {
    JFreeChart lineChart = ChartFactory.createLineChart(
            java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.year.title"),
            java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.year.xaxis"),
            java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.year.yaxis"), generateDataset(),
            PlotOrientation.VERTICAL, true, true, false);
    lineChart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xFF, 0));
    lineChart.getPlot().setBackgroundPaint(Color.WHITE);
    return lineChart;
}

From source file:jasmine.imaging.shapes.RadiusChart.java

public RadiusChart(double[] values) {

    super();//from w  w  w. ja  v a  2  s .c  o m

    DefaultCategoryDataset series = new DefaultCategoryDataset();

    for (int i = 0; i < values.length; i++) {
        series.addValue(values[i], "row1", String.valueOf(i));
    }

    setTitle("Radius Change");

    chart = new JLabel();
    getContentPane().add(chart);

    setSize(320, 240);
    setVisible(true);

    myChart = ChartFactory.createLineChart(null, null, null, series, PlotOrientation.VERTICAL, false, false,
            false);

    addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            if (myChart != null)
                updateChart();
        }
    });

}