Example usage for org.jfree.chart JFreeChart JFreeChart

List of usage examples for org.jfree.chart JFreeChart JFreeChart

Introduction

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

Prototype

public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend) 

Source Link

Document

Creates a new chart with the given title and plot.

Usage

From source file:ec.nbdemetra.sa.revisionanalysis.RevisionAnalysisChart.java

private JFreeChart createChart() {
    XYPlot plot = new XYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setAutoPopulateSeriesStroke(false);
    renderer.setBaseStroke(TsCharts.getStrongStroke(ITsChart.LinesThickness.Thin));
    plot.setRenderer(renderer);/*from  www  .  j  a  va2  s .c o  m*/

    JFreeChart result = new JFreeChart("", TsCharts.CHART_TITLE_FONT, plot, true);
    result.setPadding(TsCharts.CHART_PADDING);
    result.setTitle("Standard deviations");

    return result;
}

From source file:ec.nbdemetra.chainlinking.outlineview.ChainLinkingChart.java

private JFreeChart createChart() {
    XYPlot plot = new XYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setAutoPopulateSeriesPaint(false);
    renderer.setAutoPopulateSeriesStroke(false);
    renderer.setBaseStroke(TsCharts.getStrongStroke(ITsChart.LinesThickness.Thin));
    plot.setRenderer(renderer);/*from   w ww.  ja v  a2  s  .  c o m*/

    JFreeChart r = new JFreeChart("", TsCharts.CHART_TITLE_FONT, plot, true);
    r.setPadding(TsCharts.CHART_PADDING);
    r.setTitle("Chain Linking");

    return r;
}

From source file:com.charts.ThreeMonthChart.java

public ThreeMonthChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setDrawVolume(false);/*from   w  w w  .j  a va  2  s . c o  m*/
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(600, 300));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);
    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    Date now = new Date();
    SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline();
    Calendar[][] holidays = DayRange.getHolidayDates();
    int len = holidays.length;

    for (int i = 0; i < holidays[0].length; i++) {
        Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST"));
        day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR));
        day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH));
        day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH));
        day.set(Calendar.HOUR_OF_DAY, 9);
        segmentedTimeline.addException(day.getTime());

    }

    xAxis.setTimeline(segmentedTimeline);
    //xAxis.setVerticalTickLabels(true);
    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);

    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:com.charts.SixMonthChart.java

public SixMonthChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setDrawVolume(false);//from  w w w.j  av  a  2s  . c  om
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(600, 300));

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

    LegendTitle legend = new LegendTitle(plot);

    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    Date now = new Date();
    SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline();
    Calendar[][] holidays = DayRange.getHolidayDates();
    int len = holidays.length;

    for (int i = 0; i < holidays[0].length; i++) {
        Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST"));
        day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR));
        day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH));
        day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH));
        day.set(Calendar.HOUR_OF_DAY, 9);
        segmentedTimeline.addException(day.getTime());

    }

    xAxis.setTimeline(segmentedTimeline);
    //xAxis.setVerticalTickLabels(true);
    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);

    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:com.charts.OneMonthChart.java

public OneMonthChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setDrawVolume(false);//  w  w  w . java  2 s.c o  m
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setVerticalTickLabels(true);
    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(600, 300));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    Date now = new Date();
    SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline();
    Calendar[][] holidays = DayRange.getHolidayDates();
    int len = holidays.length;

    for (int i = 0; i < holidays[0].length; i++) {
        Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST"));
        day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR));
        day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH));
        day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH));
        day.set(Calendar.HOUR_OF_DAY, 9);
        segmentedTimeline.addException(day.getTime());

    }

    xAxis.setTimeline(segmentedTimeline);
    //xAxis.setVerticalTickLabels(true);
    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM-dd"));
    xAxis.setAutoTickUnitSelection(false);
    xAxis.setAutoRange(false);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);

    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:scheduler.benchmarker.manager.CreateSimpleSplineChart.java

public ChartPanel createChartPanel() {
    XYDataset dataset = createDataset();
    NumberAxis numberaxis = new NumberAxis("EMAILS");
    numberaxis.setAutoRangeIncludesZero(true);
    numberaxis.setRange(0, dataset.getItemCount(1));
    numberaxis.setVisible(false);// w  ww  .ja va  2s .c o  m
    NumberAxis numberaxis1 = new NumberAxis("TIME CONSUMED");
    numberaxis1.setAutoRangeIncludesZero(false);
    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    XYPlot xyplot = new XYPlot(dataset, numberaxis, numberaxis1, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    //xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart("PLAN VALUES FOR '" + sName + "' SCHEDULER",
            new Font(Font.SANS_SERIF, Font.PLAIN, 11), xyplot, true);
    chartPanel = new ChartPanel(jfreechart, true);

    //Creating listener
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent e) {
            ChartEntity entity = e.getEntity();
            if (entity != null && (entity instanceof XYItemEntity)) {
                XYItemEntity item = (XYItemEntity) entity;
                String chartTitle = "RULE ARRANGEMENT INFORMATION FOR EMAIL \""
                        + dataSource.get(item.getItem()).getEmailName() + "\"";
                createSubChart(
                        new CreateStackedBarChart3D(dataSource.get(item.getItem()), pluginColor, chartTitle)
                                .createChartPanel());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent e) {
            //DO NOTHING
        }

    });
    return chartPanel;
}

From source file:sernet.gs.ui.rcp.main.bsi.views.chart.LebenszyklusBarChart.java

protected JFreeChart createSpiderChart(Object dataset) {
    final int startAngle = 54;
    final double interiorGap = 0.4d;
    SpiderWebPlot plot = new SpiderWebPlot((CategoryDataset) dataset);
    plot.setStartAngle(startAngle);/*from  w ww  . j a  v  a 2  s  . c om*/
    plot.setInteriorGap(interiorGap);
    plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    JFreeChart chart = new JFreeChart(Messages.LebenszyklusBarChart_1, TextTitle.DEFAULT_FONT, plot, false);
    LegendTitle legend = new LegendTitle(plot);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legend);
    return chart;
}

From source file:org.usfirst.frc.team2084.smartdashboard.extensions.BetterCompass.java

@Override
public void init() {
    // needleType.add("Arrow", 0);
    // needleType.add("Line", 1);
    // needleType.add("Long", 2);
    // needleType.add("Pin", 3);
    // needleType.add("Plum", 4);
    // needleType.add("Pointer", 5);
    // needleType.add("Ship", 6);
    // needleType.add("Wind", 7);
    // needleType.add("Arrow Line", 8);
    // needleType.add("Middle Pin", 9);
    // needleType.setDefault("Arrow Line");

    SwingUtilities.invokeLater(() -> {
        setLayout(new BorderLayout());

        compass = new CompassPlot(getDataset());
        compass.setSeriesNeedle(8);/* www.j  a v a  2 s.  co  m*/
        // propertyChanged(needleType);
        compass.setSeriesPaint(0, Color.RED);
        compass.setSeriesOutlinePaint(0, Color.RED);

        JFreeChart chart = new JFreeChart(getFieldName(), JFreeChart.DEFAULT_TITLE_FONT, compass, false);
        chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(250, 150));

        propertyChanged(circumference);
        propertyChanged(ringColor);

        add(chartPanel, BorderLayout.CENTER);

        revalidate();
        repaint();
    });
}

From source file:gui.Plotter1D.java

private ChartPanel createChartPanel1(String grapheName) {

    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    ValueAxis valueAxis = new NumberAxis("X");
    valueAxis.setRange(0.0, 1.0);//from www . ja  va 2  s. co m
    ValueAxis valueAxisy = new NumberAxis("Y");
    valueAxis.setRange(0.0, 1.0);
    XYPlot xyplot;
    xyplot = new XYPlot(xyseriescollection, valueAxis, valueAxisy, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart(grapheName, JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
    jfreechart.setBackgroundPaint(Color.white);
    ChartPanel chartpanel = new ChartPanel(jfreechart, false);
    return chartpanel;
}

From source file:sernet.gs.ui.rcp.main.bsi.views.chart.MaturitySpiderChart.java

protected JFreeChart createSpiderChart(Object dataset) {
    SpiderWebPlot plot = new SpiderWebPlot((CategoryDataset) dataset);
    plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    plot.setSeriesPaint(0, new Color(0.0f, 1f, 0f, 1f)); // green
    plot.setSeriesPaint(1, new Color(1f, 1f, 0f, 1f)); // yellow
    plot.setSeriesPaint(2, new Color(1f, 0f, 0f, 1f)); // red
    plot.setSeriesPaint(3, new Color(0f, 0f, 0f, 1f)); // grey

    plot.setWebFilled(true);//  w  w  w. jav  a 2  s  .  c  o  m
    JFreeChart chart = new JFreeChart(Messages.MaturitySpiderChart_0, TextTitle.DEFAULT_FONT, plot, false);

    LegendTitle legend = new LegendTitle(plot);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(legend);

    return chart;
}