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:jfreechart.ViewGirlsBoysAvgChart.java

public static void viweGirlsAvgChart(List<String> testId, ArrayList<Double> totAvg, ArrayList<Double> girlsAvg,
        ArrayList<Double> boysAvg) throws SQLException, ClassNotFoundException {
    try {// w ww . ja  va  2s .c om
        UIManager.setLookAndFeel(new McWinLookAndFeel());
    } catch (UnsupportedLookAndFeelException ex) {
        Logger.getLogger(ViewEachStudentChart.class.getName()).log(Level.SEVERE, null, ex);
    }
    DefaultCategoryDataset objDataset = new DefaultCategoryDataset();

    for (Double marks : totAvg) {
        //Double mark = tstId;
        //String tetId = tstId.split(",")[3];
        objDataset.addValue(marks, "Line1", marks);

    }
    for (Double marks : girlsAvg) {
        //Double mark = tstId;
        //String tetId = tstId.split(",")[3];
        objDataset.addValue(marks, "Line2", marks);

    }
    //        for (Double testMark : bAvgList) {
    //            Double mark = testMark;
    //            //String tstId = testId.split(",")[3];
    //            objDataset.setValue(mark, "", mark);
    //            
    //            
    //        }
    JFreeChart objChart = ChartFactory.createLineChart("Marks Chart", //Chart title
            "Test", //Domain axis label
            "Marks", //Range axis label
            objDataset, //Chart Data 
            PlotOrientation.VERTICAL, // orientation
            true, // include legend?
            true, // include tooltips?
            false // include URLs?
    );

    ChartFrame frame = new ChartFrame("Dakma Higher Education Center", objChart);
    frame.setLocationRelativeTo(frame);
    frame.pack();
    frame.setVisible(true);
}

From source file:estimatePressure.CreateGraph.java

public CreateGraph(String applicationTitle, String chartTitle, Matrix errData, int sensorNum) {
    super(applicationTitle);
    this.errorData = errData;
    this.sensorNumber = sensorNum;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Time", "Error", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);
    //lineChart.setBackgroundPaint(Color.red);
    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);//w  w w . ja  v  a2 s.co m

    File fileLineChart = new File("Error values" + this.sensorNumber + ".jpeg");
    try {
        ChartUtilities.saveChartAsJPEG(fileLineChart, lineChart, 1200, 500);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:vista.montecarlo.GraficoEvolutivo.java

public GraficoEvolutivo(String applicationTitle, String chartTitle, double[][] costos) {
    super(applicationTitle);
    costosPromedio = costos;/*from   w w w. ja va 2 s.  c o m*/
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, TITL_EJE_X, TITL_EJE_Y, createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1300, 733));
    setContentPane(chartPanel);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}

From source file:model.Grafico.java

public void geraGrafico(List<Moeda> listamoedas) {
    DefaultCategoryDataset ds = new DefaultCategoryDataset();
    if (listamoedas == null) {
        return;/*from   ww w  . ja  v  a  2s .  c  o m*/
    }
    for (int i = 0; i < listamoedas.size(); i++) {
        ds.addValue(listamoedas.get(i).getPrecocompra(), "Preo de Compra", listamoedas.get(i).DatatoString());
        ds.addValue(listamoedas.get(i).getPrecovenda(), "Preo de Venda", listamoedas.get(i).DatatoString());

    }
    JFreeChart grafico = ChartFactory.createLineChart("Variaes da Moeda", "Dia", "Valor", ds,
            PlotOrientation.VERTICAL, true, true, false);
    //XYPlot plot = grafico.getXYPlot();    
    //ValueAxis yAxis = plot.getRangeAxis();
    //yAxis.setRange(3, 3.5);
    try {
        OutputStream arquivo = new FileOutputStream("grafico.png");
        ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400);
        arquivo.close();
    } catch (Exception e) {
        System.out.println("ERRO");
    }
}

From source file:com.thecoderscorner.groovychart.chart.LineChart.java

public JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createLineChart(getTitle(), this.getCategoryAxisLabel(),
            this.getValueAxisLabel(), (CategoryDataset) getDataset(), getOrientation(), isLegend(),
            isTooltips(), isUrls());/*from w  ww .j a  v a 2s.c  om*/
    return setExtraProperties(chart);

}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Statistical Bar Chart Demo 1", "Type", "Value",
            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());
    numberaxis.setAutoRangeIncludesZero(false);
    StatisticalBarRenderer statisticalbarrenderer = new StatisticalBarRenderer();
    statisticalbarrenderer.setErrorIndicatorPaint(Color.black);
    statisticalbarrenderer.setIncludeBaseInRange(false);
    categoryplot.setRenderer(statisticalbarrenderer);
    statisticalbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    statisticalbarrenderer.setBaseItemLabelsVisible(true);
    statisticalbarrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));
    return jfreechart;
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Statistical Line Chart Demo 1", "Type", "Value",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    CategoryAxis categoryaxis = categoryplot.getDomainAxis();
    categoryaxis.setUpperMargin(0.0D);//from   w  ww .  j a v  a 2s. co m
    categoryaxis.setLowerMargin(0.0D);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(true);
    StatisticalLineAndShapeRenderer statisticallineandshaperenderer = new StatisticalLineAndShapeRenderer(true,
            false);
    categoryplot.setRenderer(statisticallineandshaperenderer);
    return jfreechart;
}

From source file:com.ouc.cpss.view.ProfitChartBuilder.java

public static JFreeChart createJFreeChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createLineChart("?", "", "?",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    // ?//  www  .j  a va  2  s.co m
    LegendTitle legendTitle = chart.getLegend(0);
    // 
    legendTitle.setItemFont(new Font("", Font.BOLD, 18));
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    // ?
    org.jfree.chart.axis.CategoryAxis categoryAxis = plot.getDomainAxis();
    // 
    categoryAxis.setLabelFont(new Font("", Font.BOLD, 18));

    // 
    categoryAxis.setTickLabelFont(new Font("", Font.BOLD, 12));
    // ?
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    // 
    numberAxis.setLabelFont(new Font("", Font.BOLD, 14));

    numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//

    CategoryItemRenderer xylineandshaperenderer = plot.getRenderer();
    xylineandshaperenderer.setBaseItemLabelsVisible(true);
    xylineandshaperenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE2, TextAnchor.BASELINE_RIGHT));
    xylineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    return chart;
}

From source file:presentationLayer.PredictionGraph.java

public PredictionGraph(String applicationTitle, String chartTitle, double y, int i) {
    super(applicationTitle);
    y1 = y;//w w  w. jav a2  s .c  om
    id = i;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Order", "Rs.", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    setContentPane(chartPanel);
}

From source file:overSession.CreateGraph.java

public CreateGraph(String applicationTitle, String chartTitle, LinkedList<LinkedList<String>> pData,
        int sensorNum) {
    super(applicationTitle);
    this.pressureData = pData;
    this.sensorNumber = sensorNum;
    JFreeChart lineChart = ChartFactory.createLineChart(chartTitle, "Session",
            "Average Pressure Value (per session)", createDataset(), PlotOrientation.VERTICAL, true, true,
            false);/*www. j av  a 2 s  .c  om*/
    //lineChart.setBackgroundPaint(Color.red);
    ChartPanel chartPanel = new ChartPanel(lineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1200, 500));
    setContentPane(chartPanel);

    File fileLineChart = new File("LineChart" + this.sensorNumber + ".jpeg");
    try {
        ChartUtilities.saveChartAsJPEG(fileLineChart, lineChart, 1200, 500);
    } catch (IOException e) {
        e.printStackTrace();
    }

}