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:chart.DualAxis.java

/**
 * Creates a new demo instance./*from w  w w  .  ja  v a 2 s .c  om*/
 *
 * @param title  the frame title.
 */

public DualAxis(final String title, double[] xData, double[] YDataAnalitic, double[] YDataNumerical) {

    super(title);

    final CategoryDataset dataset1 = createDataset1(xData, YDataAnalitic);

    // create the chart...
    final JFreeChart chart = ChartFactory.createLineChart("", // chart title
            "x", // domain axis label
            "y", // range axis label
            dataset1, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );

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

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    final CategoryDataset dataset2 = createDataset2(xData, YDataNumerical);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    //final ValueAxis axis2 = new NumberAxis("");
    final ValueAxis axis2 = new NumberAxis(" ");
    plot.setRangeAxis(1, axis2);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
    //  panel.removeAll();
    //   panel.add(chartPanel);
    //   panel.validate();

}

From source file:com.awesheet.models.charts.LineChart.java

@Override
public boolean generateImageData() {
    // Create the dataset.
    DefaultCategoryDataset dataset = createDataset();

    if (dataset == null) {
        return false;
    }/*  w  ww .j av a2  s . com*/

    // Create the chart.
    JFreeChart lineChart = ChartFactory.createLineChart(title, nameX, nameY, dataset, PlotOrientation.VERTICAL,
            true, true, false);

    //final CategoryPlot plot = lineChart.getCategoryPlot();
    //((BarRenderer) plot.getRenderer()).setBarPainter(new StandardBarPainter());

    // Generate the image.
    try {
        imageData = ChartUtilities.encodeAsPNG(lineChart.createBufferedImage(720, 480));
    } catch (IOException e) {
        return false;
    }

    return true;
}

From source file:com.etest.view.tq.charts.SubjectTestLineChart.java

public static JFreeChart difficultIndex(int tqCoverageId) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (CellItem ci : CellItemDAO.getItemAnalysisResult(tqCoverageId)) {
        dataset.setValue((int) (ci.getDifficultIndex() * 100), "Difficulty Index",
                String.valueOf(ci.getItemNo()));
    }/*from  ww  w .  jav a  2 s.  c o  m*/

    JFreeChart chart = ChartFactory.createLineChart("Item Analysis Report", "Item No.", "Difficulty Index (%)",
            dataset, PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

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

    // customise the renderer...
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setFillPaint(Color.white);

    return chart;
}

From source file:org.cerberus.refactor.LineChart.java

public BufferedImage bi(CategoryDataset categorydataset, String name, int count) {

    BufferedImage bi = null;//from w w  w  . ja va  2  s .  c om

    JFreeChart jfreechart = ChartFactory.createLineChart(name, "Category", "Count", categorydataset,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    Shape point = ShapeUtilities.createDiagonalCross(1, 1);
    //TODO check this - seriesColors never used
    //        String[] seriesColors = {"#FF0000", "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01"};
    //        String[] seriesColors2 = {"#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01"};

    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setBaseShapesFilled(true);
    for (int a = 0; a < count; a++) {
        lineandshaperenderer.setSeriesShapesVisible(a, true);
        lineandshaperenderer.setSeriesLinesVisible(a, true);
        lineandshaperenderer.setSeriesStroke(a, new BasicStroke(1.0F));
        lineandshaperenderer.setSeriesShape(a, point);
    }

    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);

    //DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
    //dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));

    bi = jfreechart.createBufferedImage(500, 270);

    return bi;

}

From source file:peakmlviewer.dialog.peakinformation.Graph.java

public Graph(Composite parent) {
    super(parent, SWT.EMBEDDED);

    setLayout(new FillLayout());

    // create the chart
    linechart = ChartFactory.createLineChart(null, "", "Abundance", dataset_intensity, PlotOrientation.VERTICAL,
            false, // legend
            false, // tooltips
            false // urls
    );/*from  w w w . j  a va 2  s .  c o m*/

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

    // make the labels for the xaxis 45 degrees
    CategoryAxis xaxis = (CategoryAxis) plot.getDomainAxis();
    xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    // add the mass accuracy yaxis
    NumberAxis yaxis_massacc = new NumberAxis("Mass accuracy (ppm)");
    plot.setRangeAxis(1, yaxis_massacc);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    // create the mass accuracy dataset
    dataset_ppm = new DefaultCategoryDataset();
    plot.setDataset(1, dataset_ppm);
    plot.mapDatasetToRangeAxis(1, 1);

    // create the renderer for the mass accuracy dataset
    LineAndShapeRenderer renderer_ppm = new LineAndShapeRenderer();
    renderer_ppm.setBaseShapesFilled(true);
    renderer_ppm.setBaseShapesVisible(true);
    renderer_ppm.setBaseStroke(
            new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { 5, 5 }, 0));
    plot.setRenderer(1, renderer_ppm);

    // setup the renderer for the intensity dataset
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesFilled(true);
    renderer.setBaseShapesVisible(true);

    // general properties
    linechart.setBackgroundPaint(Color.WHITE);
    linechart.setBorderVisible(false);
    linechart.setAntiAlias(true);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    // add the components
    // --------------------------------------------------------------------------------
    // This uses the SWT-trick for embedding awt-controls in an SWT-Composit.
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
        ;
    }

    java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(this);

    // create a new ChartPanel, without the popup-menu (5x false)
    frame.add(new ChartPanel(linechart, false, false, false, false, false));
    // --------------------------------------------------------------------------------
}

From source file:cheuk.licenseheaderchecker.resource.DataGraph.java

/**
* Creates a trend graph/*  w  w  w .  j a  v a2s .c  om*/
*
* @return the JFreeChart graph object
*/
protected JFreeChart createGraph() {

    final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    //final LegendTitle legend = chart.getLegend();
    //legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    //        rangeAxis.setAutoRange(true);

    final StackedAreaRenderer renderer = new StackedAreaRenderer2();
    plot.setRenderer(renderer);
    //renderer.setBaseStroke(new BasicStroke(2.0f));
    //ColorPalette.apply(renderer);
    plot.setRenderer(renderer);
    renderer.setSeriesPaint(2, RED);
    renderer.setSeriesPaint(1, GRAY);
    renderer.setSeriesPaint(0, YELLOW);

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    return chart;
}

From source file:jasmine.imaging.core.util.Histogram.java

public Histogram(Hashtable<Integer, Integer> count) {

    super("Histogram");

    DefaultCategoryDataset series = new DefaultCategoryDataset();

    StatisticsSolver solver = new StatisticsSolver(1000);

    for (int i = 0; i < 256; i++) {
        Integer value = count.get(i);
        if (value == null)
            value = 1;//from   w  w  w. j  a v  a 2s .c  o  m
        for (int j = 0; j < value; j++) {
            solver.addData(i);
        }
        series.addValue(value, "row1", String.valueOf(i));
    }

    setTitle("Histogram: v=" + solver.getStandardDeviation());

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

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

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

    //updateChart();

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

}

From source file:filtros.histograma.Histograma.java

public static void Apply(BufferedImage image, String savePath) {
    //Chamada do metodo que gera os dados do histograma
    GetData(image);//from w ww .  ja v  a  2s  .c o  m

    //Dataset que gera o grafico
    DefaultCategoryDataset ds = new DefaultCategoryDataset();

    //Loop que percorre o array de dados do histograma
    for (int k = 0; k < data.length; k++) {
        //Adiciona o valor ao dataset
        ds.setValue(data[k], "Imagem", Integer.toString(data[k]));
    }

    //Gera o grafico
    JFreeChart grafico = ChartFactory.createLineChart("Histograma", "Tons de cinza", "Valor", ds,
            PlotOrientation.VERTICAL, true, true, false);

    //Salva o grafico em um arquivo de png
    try {
        OutputStream arquivo = new FileOutputStream(savePath);
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400);
        arquivo.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:peakmlviewer.dialog.timeseries.EditableChart.java

public EditableChart(Composite parent, int style) {
    super(parent, SWT.EMBEDDED | style);

    setLayout(new FillLayout());

    // create the components
    linechart = ChartFactory.createLineChart(null, "", "Intensity", dataset, PlotOrientation.VERTICAL, false, // legend
            false, // tooltips
            false // urls
    );/*from www  .  j  a  v  a  2s .c o  m*/

    CategoryPlot plot = (CategoryPlot) linechart.getPlot();
    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setRange(0, 1);
    CategoryAxis xaxis = (CategoryAxis) plot.getDomainAxis();
    xaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();

    renderer.setSeriesShapesFilled(0, true);
    renderer.setSeriesShapesVisible(0, true);

    linechart.setBackgroundPaint(Color.WHITE);
    linechart.setBorderVisible(false);
    linechart.setAntiAlias(true);

    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);

    // add the components
    // --------------------------------------------------------------------------------
    // This uses the SWT-trick for embedding awt-controls in an SWT-Composit.
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
        ;
    }

    java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(this);

    // create a few ChartPanel, without the popup-menu (5x false)
    panel = new ChartPanel(linechart, false, false, false, false, false);

    panel.addMouseListener(this);
    panel.addMouseMotionListener(this);
    panel.setRangeZoomable(false);
    panel.setDomainZoomable(false);

    frame.add(panel);
    // --------------------------------------------------------------------------------
}

From source file:org.mt4jx.components.visibleComponents.widgets.jfreechart.examples.MTJFreeChartExampleScene.java

public MTJFreeChartExampleScene(MTApplication mtApplication, String name) {
    super(mtApplication, name);
    this.setClearColor(new MTColor(0, 0, 96, 255));
    //Show touches
    this.registerGlobalInputProcessor(new CursorTracer(mtApplication, this));

    // Create Example Data
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < 10; i++) {
        dataset.addValue(10 * Math.random(), "MySeries", "T" + i);
    }//  w  w  w  .j a  va 2s  .c om
    // Create a JFreeChart
    JFreeChart chart1 = ChartFactory.createLineChart("Line Chart", "x axis", "y axis", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    // Put the JFreeChart into a MTJFreeChart wrapper
    MTJFreeChart mtChart1 = new MTJFreeChart(800, 600, mtApplication, chart1);

    // Create another chart
    DefaultPieDataset pds = new DefaultPieDataset();

    pds.setValue("Java", new Double(17.773));
    pds.setValue("C", new Double(15.822));
    pds.setValue("C++", new Double(8.783));
    pds.setValue("PHP", new Double(7.835));
    pds.setValue("Python", new Double(6.265));
    pds.setValue("C#", new Double(6.226));
    pds.setValue("(Visual) Basic", new Double(5.867));
    pds.setValue("Objective-C", new Double(3.011));
    pds.setValue("Perl", new Double(2.857));

    JFreeChart chart2 = ChartFactory.createPieChart3D(
            "Top 10: TIOBE Programming Community Index\nfor January 2011 (www.tiobe.com)", pds, true, true,
            Locale.GERMANY);
    PiePlot3D plot = (PiePlot3D) chart2.getPlot();
    plot.setStartAngle(290);

    MTJFreeChart mtChart2 = new MTJFreeChart(800, 600, mtApplication, chart2);
    // enable redraw of the chart when it's scaled by the user
    mtChart2.setRedrawWhenScaled(true);
    this.getCanvas().addChild(mtChart1);
    this.getCanvas().addChild(mtChart2);
    mtChart1.setPositionGlobal(new Vector3D(mtApplication.width / 2f, mtApplication.height / 2f));
    mtChart2.setPositionGlobal(new Vector3D(150 + mtApplication.width / 2f, 150 + mtApplication.height / 2f));
}