Example usage for org.jfree.chart ChartFactory createTimeSeriesChart

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

Introduction

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

Prototype

public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel,
        XYDataset dataset, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates and returns a time series chart.

Usage

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected JFreeChart createTimeSeriesChart() throws JRException {
    String timeAxisLabel = (String) evaluateExpression(
            ((JRTimeSeriesPlot) getPlot()).getTimeAxisLabelExpression());
    String valueAxisLabel = (String) evaluateExpression(
            ((JRTimeSeriesPlot) getPlot()).getValueAxisLabelExpression());

    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createTimeSeriesChart(
            (String) evaluateExpression(getChart().getTitleExpression()), timeAxisLabel, valueAxisLabel,
            (TimeSeriesCollection) getDataset(), isShowLegend(), true, false);

    configureChart(jfreeChart, getPlot());

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    JRTimeSeriesPlot timeSeriesPlot = (JRTimeSeriesPlot) getPlot();

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();

    boolean isShowShapes = timeSeriesPlot.getShowShapes() == null ? true
            : timeSeriesPlot.getShowShapes().booleanValue();
    boolean isShowLines = timeSeriesPlot.getShowLines() == null ? true
            : timeSeriesPlot.getShowLines().booleanValue();
    lineRenderer.setBaseLinesVisible(isShowLines);
    lineRenderer.setBaseShapesVisible(isShowShapes);

    // Handle the axis formating for the category axis
    configureAxis(xyPlot.getDomainAxis(), timeSeriesPlot.getTimeAxisLabelFont(),
            timeSeriesPlot.getTimeAxisLabelColor(), timeSeriesPlot.getTimeAxisTickLabelFont(),
            timeSeriesPlot.getTimeAxisTickLabelColor(), timeSeriesPlot.getTimeAxisTickLabelMask(),
            timeSeriesPlot.getTimeAxisVerticalTickLabels(), timeSeriesPlot.getOwnTimeAxisLineColor(),
            getDomainAxisSettings(), DateTickUnit.DAY,
            (Comparable) evaluateExpression(timeSeriesPlot.getDomainAxisMinValueExpression()),
            (Comparable) evaluateExpression(timeSeriesPlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(xyPlot.getRangeAxis(), timeSeriesPlot.getValueAxisLabelFont(),
            timeSeriesPlot.getValueAxisLabelColor(), timeSeriesPlot.getValueAxisTickLabelFont(),
            timeSeriesPlot.getValueAxisTickLabelColor(), timeSeriesPlot.getValueAxisTickLabelMask(),
            timeSeriesPlot.getValueAxisVerticalTickLabels(), timeSeriesPlot.getOwnValueAxisLineColor(),
            getRangeAxisSettings(), DateTickUnit.DAY,
            (Comparable) evaluateExpression(timeSeriesPlot.getRangeAxisMinValueExpression()),
            (Comparable) evaluateExpression(timeSeriesPlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:skoa.helpers.Graficos.java

private void difAbs() {
    //Aplicarle la frmula a los valores de las dos direcciones, obteniendo un slo fichero.
    aplicarFormula(2); //Se le aplica con porcentajes.
    String tipo = unidad.substring(0, unidad.indexOf("\t"));
    if (tipo.contentEquals("ABS"))
        tipo = "DIF";
    unidad = unidad.substring(unidad.indexOf("\t") + 1);
    if (unidad.indexOf("C") >= 0)
        unidad = "C";
    TimeSeries serie = obtenerSerieEvolucion2(); //Reutilizamos este cdigo.
    TimeSeriesCollection dataset = new TimeSeriesCollection(serie); //Slo se obtiene una curva.
    JFreeChart grafica = ChartFactory.createTimeSeriesChart("Valores medidos de las direcciones de grupo", //titulo
            "Fechas", //titulo eje x
            "Mediciones en " + tipo + " " + "(" + unidad + ")", //titulo eje y
            dataset, //dataset
            true, //leyenda
            true, //tooltips
            false); //configure chart to generate URLs?
    //Dar color a cada categoria
    grafica.setBackgroundPaint(Color.WHITE); //Color del fondo del grafico
    if (fechaInicial.equals("") & fechaFinal.equals("")) { //Si estan vacas es porque no hay resultados para ese intervalo.
        fechaInicial = " ? ";
        fechaFinal = " ? ";
    }// w ww  .j  a  va 2s.co m
    TextTitle t = new TextTitle("desde " + fechaInicial + " hasta " + fechaFinal,
            new Font("SanSerif", Font.ITALIC, 12));
    grafica.addSubtitle(t);
    try {
        ChartUtilities.saveChartAsJPEG(new File(ruta + "DiferenciasSmall.jpg"), grafica, 400, 300);
        ChartUtilities.saveChartAsJPEG(new File(ruta + "DiferenciasBig.jpg"), grafica, 900, 600);
    } catch (IOException e1) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createXYDifferenceChart(String title, String xLabel, String yLabel, XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, true, // legend
            true, // tool tips
            false // URLs
    );/*w  w w .  ja v a 2s.  c  om*/
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(new XYDifferenceRenderer(Color.green, Color.red, false));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    XYItemRenderer renderer = plot.getRenderer();
    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());
    setDateAxis(plot);

    /*   ValueAxis domainAxis = new DateAxis("Time");
       domainAxis.setLowerMargin(0.0);
       domainAxis.setUpperMargin(0.0);
       plot.setDomainAxis(domainAxis);
       plot.setForegroundAlpha(0.5f);  */

    //setXSummary(dataset) X is time;
    return chart;
}

From source file:fmiquerytest.Coordinates.java

static String drawTempRainChart(List<stepWeather> stepDataBase, Map routeWeather) {
    //First, fetch the real data
    List<Double> times = new ArrayList<>();
    List<Double> temps = new ArrayList<>();
    List<Double> rains = new ArrayList<>();
    List<Double> lights = new ArrayList<>();
    for (int i = 0; i < stepDataBase.size(); ++i) {
        stepWeather step = stepDataBase.get(i);
        stepWeather nextstep = step;//  w  ww.  java  2s . com
        if (i < stepDataBase.size() - 1) {
            nextstep = stepDataBase.get(i + 1);
        }
        times.add(step.timeAsDouble);
        temps.add(getParameterAverage(routeWeather, step, nextstep, "Temperature"));
        rains.add(getParameterAverage(routeWeather, step, nextstep, "Precipitation1h"));
        lights.add(Math.pow(Math.abs(step.timeAsDouble % 24 - ((step.sunRise + step.sunSet) / 2))
                / ((step.sunSet - step.sunRise) / 2), 5));
    }

    double zeroPoint = times.get(0);
    // Make first dataset
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    final TimeSeries s1 = new TimeSeries("Temperature C", Minute.class);
    // Make second dataset
    final TimeSeriesCollection dataset2 = new TimeSeriesCollection();
    final TimeSeries s2 = new TimeSeries("Rain (mm)", Minute.class);
    // Make third dataset
    //final TimeSeriesCollection dataset3 = new TimeSeriesCollection();
    final TimeSeries s3 = new TimeSeries("Darkness", Minute.class);
    // Show data per minute
    RegularTimePeriod start = new Minute(new Date(FmiQueryTest.startTimeMillis));
    for (int i = 0; i < times.size() - 1; ++i) {
        double time = times.get(i);
        double nexttime = times.get(i + 1);
        int firstMinute = intValue((time - zeroPoint) * 60);
        int currentMinute = firstMinute;
        int lastMinute = intValue((nexttime - zeroPoint) * 60);
        while (currentMinute < lastMinute) {
            s1.add(start, temps.get(i) + ((double) currentMinute - firstMinute) / (lastMinute - firstMinute)
                    * (temps.get(i + 1) - temps.get(i)));
            s2.add(start, (rains.get(i) + rains.get(i + 1)) / 2);
            //+((double)currentMinute-firstMinute)/(lastMinute-firstMinute)*(rains.get(i+1)-rains.get(i)));
            s3.add(start, lights.get(i) + ((double) currentMinute - firstMinute) / (lastMinute - firstMinute)
                    * (lights.get(i + 1) - lights.get(i)));
            ++currentMinute;
            start = start.next();
        }
    }
    dataset.addSeries(s1);
    dataset2.addSeries(s3);
    dataset2.addSeries(s2);

    // Initialize chart
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Temperature and rain", "Time",
            "Temperature C", dataset, true, // legend? 
            true, // tooltips? 
            false // URLs? 
    );
    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // configure the range axis to display first dataset...
    final ValueAxis rangeAxis = (ValueAxis) plot.getRangeAxis();
    rangeAxis.setRange(-30, 30);
    final TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(10.0));
    units.add(new NumberTickUnit(1.0));
    units.add(new NumberTickUnit(0.1));
    rangeAxis.setStandardTickUnits(units);
    //rangeAxis.setTickLabelFont(new Font("SansSerif", Font.BOLD, 16));

    // add the secondary dataset/renderer/axis
    plot.setRangeAxis(rangeAxis);
    final XYItemRenderer renderer2 = new XYAreaRenderer();
    final ValueAxis axis2 = new NumberAxis("Rain (mm) ");
    axis2.setRange(0, 2);
    axis2.setStandardTickUnits(units);
    //axis2.setTickLabelFont(new Font("SansSerif", Font.BOLD, 16));
    renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128));
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, axis2);
    plot.mapDatasetToRangeAxis(1, 1);
    final XYItemRenderer renderer3 = new XYAreaRenderer();
    renderer3.setSeriesPaint(0, new Color(0, 0, 0, 64));
    //plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer3);
    plot.setRangeAxis(1, axis2);
    plot.mapDatasetToRangeAxis(1, 1);

    chart.setBackgroundPaint(Color.white);
    //plot.setBackgroundPaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    //        final TextTitle subtitle = new TextTitle("An area chart demonstration.  We use this "
    //            + "subtitle as an example of what happens when you get a really long title or "
    //            + "subtitle.");
    //        subtitle.setFont(new Font("SansSerif", Font.PLAIN, 12));
    //        subtitle.setPosition(RectangleEdge.TOP);
    ////        subtitle.setSpacer(new Spacer(Spacer.RELATIVE, 0.05, 0.05, 0.05, 0.05));
    //        subtitle.setVerticalAlignment(VerticalAlignment.BOTTOM);
    //        chart.addSubtitle(subtitle);

    // Produce chart
    //        ChartFrame frame = new ChartFrame("Tamperature and rain", chart);
    //        frame.pack();
    //        RefineryUtilities.centerFrameOnScreen(frame);
    //        frame.setVisible(true);
    ByteArrayOutputStream bas = new ByteArrayOutputStream();
    try {
        ChartUtilities.writeChartAsPNG(bas, chart, 600, 400);
    } catch (IOException ex) {
        Logger.getLogger(WeatherTools.class.getName()).log(Level.SEVERE, null, ex);
    }
    byte[] byteArray = bas.toByteArray();
    String baseCode = Base64.encode(byteArray);
    return "<img width=\"480\" alt=\"Temperature and rain\" src=\"data:image/png;base64," + baseCode.trim()
            + "\" />";
}

From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java

protected JFreeChart createTimeSeriesChart() throws JRException {
    String timeAxisLabel = evaluateTextExpression(((JRTimeSeriesPlot) getPlot()).getTimeAxisLabelExpression());
    String valueAxisLabel = evaluateTextExpression(
            ((JRTimeSeriesPlot) getPlot()).getValueAxisLabelExpression());

    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createTimeSeriesChart(
            evaluateTextExpression(getChart().getTitleExpression()), timeAxisLabel, valueAxisLabel,
            (TimeSeriesCollection) getDataset(), isShowLegend(), true, false);

    configureChart(jfreeChart, getPlot());

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    JRTimeSeriesPlot timeSeriesPlot = (JRTimeSeriesPlot) getPlot();

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();

    boolean isShowShapes = timeSeriesPlot.getShowShapes() == null ? true : timeSeriesPlot.getShowShapes();
    boolean isShowLines = timeSeriesPlot.getShowLines() == null ? true : timeSeriesPlot.getShowLines();
    lineRenderer.setBaseLinesVisible(isShowLines);
    lineRenderer.setBaseShapesVisible(isShowShapes);

    // Handle the axis formating for the category axis
    configureAxis(xyPlot.getDomainAxis(), timeSeriesPlot.getTimeAxisLabelFont(),
            timeSeriesPlot.getTimeAxisLabelColor(), timeSeriesPlot.getTimeAxisTickLabelFont(),
            timeSeriesPlot.getTimeAxisTickLabelColor(), timeSeriesPlot.getTimeAxisTickLabelMask(),
            timeSeriesPlot.getTimeAxisVerticalTickLabels(), timeSeriesPlot.getOwnTimeAxisLineColor(), false,
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getDomainAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(xyPlot.getRangeAxis(), timeSeriesPlot.getValueAxisLabelFont(),
            timeSeriesPlot.getValueAxisLabelColor(), timeSeriesPlot.getValueAxisTickLabelFont(),
            timeSeriesPlot.getValueAxisTickLabelColor(), timeSeriesPlot.getValueAxisTickLabelMask(),
            timeSeriesPlot.getValueAxisVerticalTickLabels(), timeSeriesPlot.getOwnValueAxisLineColor(), true,
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getRangeAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:net.sf.jasperreports.chartthemes.simple.SimpleChartTheme.java

protected JFreeChart createTimeSeriesChart() throws JRException {
    String timeAxisLabel = evaluateTextExpression(((JRTimeSeriesPlot) getPlot()).getTimeAxisLabelExpression());
    String valueAxisLabel = evaluateTextExpression(
            ((JRTimeSeriesPlot) getPlot()).getValueAxisLabelExpression());

    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createTimeSeriesChart(
            evaluateTextExpression(getChart().getTitleExpression()), timeAxisLabel, valueAxisLabel,
            (TimeSeriesCollection) getDataset(), isShowLegend(), true, false);

    configureChart(jfreeChart, getPlot());

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    JRTimeSeriesPlot timeSeriesPlot = (JRTimeSeriesPlot) getPlot();

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();

    boolean isShowShapes = timeSeriesPlot.getShowShapes() == null ? true : timeSeriesPlot.getShowShapes();
    boolean isShowLines = timeSeriesPlot.getShowLines() == null ? true : timeSeriesPlot.getShowLines();
    lineRenderer.setBaseLinesVisible(isShowLines);
    lineRenderer.setBaseShapesVisible(isShowShapes);

    // Handle the axis formating for the category axis
    configureAxis(xyPlot.getDomainAxis(), timeSeriesPlot.getTimeAxisLabelFont(),
            timeSeriesPlot.getTimeAxisLabelColor(), timeSeriesPlot.getTimeAxisTickLabelFont(),
            timeSeriesPlot.getTimeAxisTickLabelColor(), timeSeriesPlot.getTimeAxisTickLabelMask(),
            timeSeriesPlot.getTimeAxisVerticalTickLabels(), timeSeriesPlot.getOwnTimeAxisLineColor(),
            getDomainAxisSettings(), DateTickUnitType.DAY,
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getDomainAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(xyPlot.getRangeAxis(), timeSeriesPlot.getValueAxisLabelFont(),
            timeSeriesPlot.getValueAxisLabelColor(), timeSeriesPlot.getValueAxisTickLabelFont(),
            timeSeriesPlot.getValueAxisTickLabelColor(), timeSeriesPlot.getValueAxisTickLabelMask(),
            timeSeriesPlot.getValueAxisVerticalTickLabels(), timeSeriesPlot.getOwnValueAxisLineColor(),
            getRangeAxisSettings(), DateTickUnitType.DAY,
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getRangeAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getRangeAxisMaxValueExpression()));

    return jfreeChart;
}

From source file:net.sf.jasperreports.engine.fill.DefaultChartTheme.java

protected JFreeChart createTimeSeriesChart() throws JRException {
    String timeAxisLabel = evaluateTextExpression(((JRTimeSeriesPlot) getPlot()).getTimeAxisLabelExpression());
    String valueAxisLabel = evaluateTextExpression(
            ((JRTimeSeriesPlot) getPlot()).getValueAxisLabelExpression());

    ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
    JFreeChart jfreeChart = ChartFactory.createTimeSeriesChart(
            evaluateTextExpression(getChart().getTitleExpression()), timeAxisLabel, valueAxisLabel,
            (TimeSeriesCollection) getDataset(), isShowLegend(), true, false);

    configureChart(jfreeChart);/*from w w  w  .  java 2 s . c  o m*/

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    JRTimeSeriesPlot timeSeriesPlot = (JRTimeSeriesPlot) getPlot();

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();

    boolean isShowShapes = timeSeriesPlot.getShowShapes() == null ? true : timeSeriesPlot.getShowShapes();
    boolean isShowLines = timeSeriesPlot.getShowLines() == null ? true : timeSeriesPlot.getShowLines();
    lineRenderer.setBaseLinesVisible(isShowLines);
    lineRenderer.setBaseShapesVisible(isShowShapes);

    // Handle the axis formating for the category axis
    configureAxis(xyPlot.getDomainAxis(), timeSeriesPlot.getTimeAxisLabelFont(),
            timeSeriesPlot.getTimeAxisLabelColor(), timeSeriesPlot.getTimeAxisTickLabelFont(),
            timeSeriesPlot.getTimeAxisTickLabelColor(), timeSeriesPlot.getTimeAxisTickLabelMask(),
            timeSeriesPlot.getTimeAxisVerticalTickLabels(), timeSeriesPlot.getTimeAxisLineColor(), false,
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getDomainAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getDomainAxisMaxValueExpression()));

    // Handle the axis formating for the value axis
    configureAxis(xyPlot.getRangeAxis(), timeSeriesPlot.getValueAxisLabelFont(),
            timeSeriesPlot.getValueAxisLabelColor(), timeSeriesPlot.getValueAxisTickLabelFont(),
            timeSeriesPlot.getValueAxisTickLabelColor(), timeSeriesPlot.getValueAxisTickLabelMask(),
            timeSeriesPlot.getValueAxisVerticalTickLabels(), timeSeriesPlot.getValueAxisLineColor(), true,
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getRangeAxisMinValueExpression()),
            (Comparable<?>) evaluateExpression(timeSeriesPlot.getRangeAxisMaxValueExpression()));
    return jfreeChart;
}

From source file:com.farouk.projectapp.FirstGUI.java

private JFreeChart createChart(final XYDataset dataset) {
    return ChartFactory.createTimeSeriesChart("History of changes", "Time", "Total", dataset, false, false,
            false);// ww w.  j av a  2 s  .  c  o  m
}

From source file:org.ramadda.geodata.cdmdata.CdmDataOutputHandler.java

/**
 * Create the chart//from w  ww .j a v a 2  s .c om
 *
 *
 * @param request  the request
 * @param entry    the entry
 * @param dataset  the dataset
 *
 * @return the chart
 */
private static JFreeChart createChart(Request request, Entry entry, XYDataset dataset) {
    LatLonPointImpl llp = new LatLonPointImpl(request.getLatOrLonValue(ARG_LOCATION + ".latitude", 0),
            request.getLatOrLonValue(ARG_LOCATION + ".longitude", 0));
    String title = entry.getName() + " at " + llp.toString();

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
            //entry.getName(),  // title
            title, // title
            "Date", // x-axis label
            "", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);
    ValueAxis rangeAxis = new NumberAxis("");
    rangeAxis.setVisible(false);
    XYPlot plot = (XYPlot) chart.getPlot();
    if (request.get("gray", false)) {
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
    } else {
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.lightGray);
        plot.setRangeGridlinePaint(Color.lightGray);
    }
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeAxis(0, rangeAxis, false);

    XYItemRenderer r = plot.getRenderer();
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    //axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}

From source file:gov.llnl.lustre.lwatch.PlotFrame2.java

/**
 * Define the JFreeChart chart./*w w w  .j  a v  a  2s.  co m*/
 *
 * @param dataset dataset to be plotted in the chart.
 */

public JFreeChart createChart(XYDataset dataset) {

    // Load data for settings from last "Refresh" time
    String[] selectedRows = lastRefreshPlotParams.getCategories();
    String[] selectedVars = lastRefreshPlotParams.getVariables();
    String[] selectedCurves = lastRefreshPlotParams.getCurves();

    int savedGranularity = granularity;
    granularity = lastRefreshPlotParams.getGranularity();

    boolean showLegend = true;
    //if (((isAnAggPlot) && (nColsSelected * nCurvesSelected > 8)) ||
    //(nRowsSelected * nColsSelected * nCurvesSelected > 8))
    //showLegend = false;
    if (((isAnAggPlot) && (selectedVars.length * selectedCurves.length > 8))
            || (selectedRows.length * selectedVars.length * selectedCurves.length > 8))
        showLegend = false;

    //if (fromRefresh && (nRowsSelected > 0 && nColsSelected > 0 && nCurvesSelected > 0) &&
    //(!noVarSelected)) {
    if (fromRefresh && (selectedRows.length > 0 && selectedVars.length > 0 && selectedCurves.length > 0)
            && (!noVarSelected)) {
        //Debug.out("nRowsSelected = " + nRowsSelected +
        //"   nColsSelected = " + nColsSelected +
        //"   nCurvesSelected = " + nCurvesSelected);

        pD = new PlotDescriptor();
    }

    chart = ChartFactory.createTimeSeriesChart(fsName + " - " + type + " data", // title
            "Date", // x-axis label
            yAxisLabel, // y-axis label
            dataset, // data
            showLegend, // create legend
            false, // generate tooltips
            false // generate URLs
    );

    chart.setBackgroundPaint(Color.black); //white);  // Border color
    chart.setBorderVisible(true);
    TextTitle tTitle = chart.getTitle();
    tTitle.setPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.black); //lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    // Check need for logorihmic axis
    if (useLogRangeAxis) {
        LogarithmicAxis rangeAxis2 = new LogarithmicAxis(yAxisLabel);
        plot.setRangeAxis(0, rangeAxis2);
    }

    // Default axis annotation is in black. So if the chart background
    // Paint was set to black above, we need to set axis labels, 
    // tick labels and tick marks to be a contrasting color.
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setTickMarkPaint(Color.white);
    plot.getRangeAxis().setLabelPaint(Color.white);
    plot.getRangeAxis().setTickLabelPaint(Color.white);
    plot.getRangeAxis().setTickMarkPaint(Color.white);

    // Grab the colors from the legend.
    //int nCurves = nRowsSelected * nColsSelected * nCurvesSelected;
    int nCurves = selectedRows.length * selectedVars.length * selectedCurves.length;
    if (localDebug) {
        Debug.out("selectedRows.length, selectedVars.length, selectedCurves.length = " + selectedRows.length
                + ", " + selectedVars.length + ", " + selectedCurves.length);
        Debug.out("Dimension legendColors to size = " + nCurves);
    }
    legendColors = new Color[nCurves];
    LegendItemCollection lic = plot.getLegendItems();
    for (int i = 0; i < lic.getItemCount(); i++) {
        LegendItem li = lic.get(i);
        legendColors[i] = (Color) li.getLinePaint();
        //if (localDebug)
        //Debug.out("Line Paint for legend " + i + " = " +
        //legendColors[i]);
    }

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(showIcons); // Controls icons at data pts.
        renderer.setBaseShapesFilled(false);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    if (granularity == Database.HOUR)
        axis.setDateFormatOverride(new SimpleDateFormat("MM/dd HH")); //("dd-MMM-yy"));
    else if (granularity == Database.DAY)
        axis.setDateFormatOverride(new SimpleDateFormat("MM/dd/yy")); //("dd-MMM-yy"));
    else if (granularity == Database.WEEK)
        axis.setDateFormatOverride(new SimpleDateFormat("MM/dd/yy")); //("dd-MMM-yy"));
    else if (granularity == Database.MONTH)
        axis.setDateFormatOverride(new SimpleDateFormat("MM/yy")); //("dd-MMM-yy"));
    else if (granularity == Database.YEAR)
        axis.setDateFormatOverride(new SimpleDateFormat("yyyy HH:mm")); //("dd-MMM-yy"));
    else // granualrity == Database.RAW or HEARTBEAT
        axis.setDateFormatOverride(new SimpleDateFormat("MM/dd HH:mm:ss")); //("dd-MMM-yy"));

    // Reset granularity;
    granularity = savedGranularity;

    return chart;

}