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:org.jfree.chart.demo.ItemLabelDemo4.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);/*from   w  ww  .  j  ava 2  s .  c om*/
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setUpperMargin(0.14999999999999999D);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    lineandshaperenderer.setBaseItemLabelsVisible(true);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Category Marker Demo 1", "Category", "Count",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setSeriesShapesVisible(0, true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryMarker categorymarker = new CategoryMarker("Category 4", Color.blue, new BasicStroke(1.0F));
    categorymarker.setDrawAsLine(true);//from w  w w  .  ja  va2  s. co m
    categorymarker.setLabel("Marker Label");
    categorymarker.setLabelFont(new Font("Dialog", 0, 11));
    categorymarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    categorymarker.setLabelOffset(new RectangleInsets(2D, 5D, 2D, 5D));
    categoryplot.addDomainMarker(categorymarker, Layer.BACKGROUND);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Category Marker Demo 2", "Category", "Count",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setSeriesShapesVisible(0, true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryMarker categorymarker = new CategoryMarker("Category 4", new Color(0, 0, 255, 25),
            new BasicStroke(1.0F));
    categorymarker.setDrawAsLine(false);
    categorymarker.setAlpha(1.0F);//from   w ww .j a va  2s.  co  m
    categorymarker.setLabel("Marker Label");
    categorymarker.setLabelFont(new Font("Dialog", 0, 11));
    categorymarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    categorymarker.setLabelOffset(new RectangleInsets(2D, 5D, 2D, 5D));
    categoryplot.addDomainMarker(categorymarker, Layer.BACKGROUND);
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Java Standard Class Library", "Release",
            "Class Count", categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.addSubtitle(new TextTitle("Number of Classes By Release"));
    TextTitle texttitle = new TextTitle(
            "Source: Java In A Nutshell (4th Edition) by David Flanagan (O'Reilly)");
    texttitle.setFont(new Font("SansSerif", 0, 10));
    texttitle.setPosition(RectangleEdge.BOTTOM);
    texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    jfreechart.addSubtitle(texttitle);/*from   w  ww . j  a v  a  2 s.c  o m*/
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryPointerAnnotation categorypointerannotation = new CategoryPointerAnnotation("Released 4-Dec-1998",
            "JDK 1.2", 1530D, -2.3561944901923448D);
    categorypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
    categoryplot.addAnnotation(categorypointerannotation);
    return jfreechart;
}

From source file:exemploJFreeChart.TelaGrafico.java

public TelaGrafico() {
    janela = new ApplicationFrame("Exemplo JFreeChart");
    janela.setDefaultCloseOperation(ApplicationFrame.EXIT_ON_CLOSE);

    JFreeChart graficoLinha = ChartFactory.createLineChart("Titulo do Grafico", "Nome do eixo X",
            "Nome do eixo Y", criarDataset(), // mtodo que cria os dados do grfico
            PlotOrientation.VERTICAL, true, true, false); // legenda, tooltips, urls

    ChartPanel painelGrafico = new ChartPanel(graficoLinha);
    painelGrafico.setPreferredSize(new Dimension(600, 400));

    janela.setContentPane(painelGrafico);
    janela.pack();/*from w  ww.  j  a va  2s.  c o m*/
    RefineryUtilities.centerFrameOnScreen(janela);
}

From source file:Diagramas.LineChart_AWT.java

public LineChart_AWT(String applicationTitle, String chartTitle) throws IOException {
    super(applicationTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Years", "Number of Schools",
            createDataset(), PlotOrientation.VERTICAL, true, true, false);

    int width = 640; /* Width of the image */
    int height = 480; /* Height of the image */
    File lineCharts = new File("LineChart.png");
    ChartUtilities.saveChartAsPNG(lineCharts, lineChart, width, height);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    setContentPane(chartPanel);//from  w w w . ja  v  a 2 s  .  c  om
}

From source file:views.StockGraph.java

public StockGraph(String FrameTitle, String chartTitle) {
    super(FrameTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Date", "Price", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 367));
    JScrollPane pane = new JScrollPane();
    pane.add(chartPanel);//from  ww w  .java  2  s .c o  m
    setContentPane(chartPanel);

}

From source file:views.SentimentGraph.java

public SentimentGraph(String applicationTitle, String chartTitle) throws ParseException {
    super(applicationTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Date", "Polarity", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 367));
    JScrollPane pane = new JScrollPane();
    pane.add(chartPanel);//from   w  ww .j av a 2  s  . c  o  m
    setContentPane(chartPanel);

}

From source file:graph.GraphCreater.java

public GraphCreater(String applicationTitle, String chartTitle, ArrayList<String> resultList,
        ArrayList<String> dateList) {
    super(applicationTitle);
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Testing date",
            "Sugar level - units(mg/dL)", createDataset(resultList, dateList), PlotOrientation.VERTICAL, true,
            true, false);//from  w w w  . j a v  a2s . co  m

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    setContentPane(chartPanel);
    final CategoryPlot plot = (CategoryPlot) lineChart.getPlot();
    CategoryAxis catAxis = plot.getDomainAxis();
    catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

}

From source file:uom.research.thalassemia.util.LineChartCreator.java

/**
 * Create a Line Chart./*from w  w  w  . j a  va  2  s  . c  o m*/
 *
 * @param dataSet data set
 * @param chartTitle chart title
 * @param subTitle sub title
 * @param xTitle x axis title
 * @param yTitle y axis title
 * @return
 */
public JPanel createPanel(final DefaultCategoryDataset dataSet, final String chartTitle, final String subTitle,
        final String xTitle, final String yTitle) {
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, xTitle, yTitle, dataSet,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    return chartPanel;
}