Example usage for org.jfree.chart.axis DateTickUnitType MONTH

List of usage examples for org.jfree.chart.axis DateTickUnitType MONTH

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateTickUnitType MONTH.

Prototype

DateTickUnitType MONTH

To view the source code for org.jfree.chart.axis DateTickUnitType MONTH.

Click Source Link

Document

Month.

Usage

From source file:org.sunzoft.sunstock.StockMain.java

protected JFreeChart createChart() {
    // 2Chart[??]
    XYDataset dataset = initChartData();
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset);

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

    //addIndexChart(xyplot);        

    ChartUtils.setAntiAlias(chart);// 
    ChartUtils.setTimeSeriesStyle(xyplot, false, true);
    ChartUtils.setLegendEmptyBorder(chart);

    // X??//  w  w  w  .j ava 2  s .  com
    DateAxis domainAxis = (DateAxis) xyplot.getDomainAxis();
    domainAxis.setAutoTickUnitSelection(false);
    domainAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());

    DateTickUnit dateTickUnit;
    if (dataset.getItemCount(0) < 30)
        dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 5, new SimpleDateFormat("yyyy-MM-dd")); // ??
    else if (dataset.getItemCount(0) < 100)
        dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 10, new SimpleDateFormat("yyyy-MM-dd")); // ??
    else if (dataset.getItemCount(0) < 200)
        dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat("yyyy/MM")); // ??
    else if (dataset.getItemCount(0) < 500)
        dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 3, new SimpleDateFormat("yyyy/MM")); // ??
    else if (dataset.getItemCount(0) < 1000)
        dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 6, new SimpleDateFormat("yyyy/MM")); // ??
    else
        dateTickUnit = new DateTickUnit(DateTickUnitType.YEAR, 1, new SimpleDateFormat("yyyy")); // ??
    // ??
    domainAxis.setTickUnit(dateTickUnit);
    return chart;
}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java

private TickUnits getUnits(CalendarFieldSplitPeriod period) {
    int field = period.getField();
    boolean good_match = false;
    for (DateTickUnitType unit : new DateTickUnitType[] { DateTickUnitType.SECOND, DateTickUnitType.MINUTE,
            DateTickUnitType.HOUR, DateTickUnitType.DAY, DateTickUnitType.MONTH, DateTickUnitType.YEAR }) {
        if (field == unit.getCalendarField()) {
            TickUnits units = new TickUnits();
            int count = period.getCount();
            int nsplit = period.getNsplit();
            if (count == 1 && nsplit == 1) {
                return null; // let jfree work it out.
            }/*from   ww w .j  av  a 2s .c o  m*/
            if (nsplit > 50) {
                return null; // period unit is too small
            }
            // include all multiples that are exact factors of count
            for (int i = 1; i <= count; i++) {
                if (count % i == 0) {
                    units.add(new DateTickUnit(unit, i));
                    if (i > 1 && (count / i) < 8) {
                        good_match = true;
                    }
                }
            }

            // now larger multiples of count that factor nsplit
            for (int i = 2; i < nsplit && i < 50; i++) {
                if (nsplit % i == 0) {
                    units.add(new DateTickUnit(unit, i * count));
                    if (i > 1 && (nsplit / i) < 8) {
                        good_match = true;
                    }
                }
            }

            if (good_match) {
                return units;
            }
            return null;
        }
    }
    return null;
}

From source file:jgnash.ui.report.compiled.RunningAccountBalanceChart.java

private JFreeChart createVerticalXYBarChart(Account a) {

    DateFormat df = new SimpleDateFormat("MM/yy");

    TimeSeriesCollection data = createTimeSeriesCollection(a);

    DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    LocalDate start = DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate());
    LocalDate end = DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate());

    dateAxis.setRange(DateUtils.asDate(start), DateUtils.asDate(end));

    NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance"));
    StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df,
            NumberFormat.getNumberInstance());

    XYBarRenderer renderer = new XYBarRenderer(0.2);
    renderer.setBaseToolTipGenerator(tooltipGenerator);

    XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);

    String title = rb.getString("Title.EndMonthBalance") + " - " + a.getPathName();

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    chart.setBackgroundPaint(null);/*from  w  ww  . j a  v a 2 s. c  o  m*/

    return chart;
}

From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeTimeChartData.java

private TickUnits getUnits() {
    TickUnits units = new TickUnits();
    units.add(new DateTickUnit(DateTickUnitType.SECOND, 1));
    units.add(new DateTickUnit(DateTickUnitType.MINUTE, 1));
    units.add(new DateTickUnit(DateTickUnitType.MINUTE, 10));
    units.add(new DateTickUnit(DateTickUnitType.MINUTE, 15));
    units.add(new DateTickUnit(DateTickUnitType.HOUR, 1));
    units.add(new DateTickUnit(DateTickUnitType.HOUR, 12));
    units.add(new DateTickUnit(DateTickUnitType.DAY, 1));
    units.add(new DateTickUnit(DateTickUnitType.DAY, 7));
    units.add(new DateTickUnit(DateTickUnitType.MONTH, 1));
    units.add(new DateTickUnit(DateTickUnitType.MONTH, 3));
    units.add(new DateTickUnit(DateTickUnitType.MONTH, 6));
    units.add(new DateTickUnit(DateTickUnitType.YEAR, 1));
    units.add(new DateTickUnit(DateTickUnitType.YEAR, 10));
    return units;
}

From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChart.java

private JFreeChart createVerticalXYBarChart(Account a) {
    DateFormat df = new SimpleDateFormat("MM/yy");
    TimeSeriesCollection data = createTimeSeriesCollection(a);

    DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    // if (a.getTransactionCount() > 0) {
    Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()));
    Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()));
    dateAxis.setRange(start, end);/* ww w .j ava 2  s.c om*/
    // }

    NumberAxis valueAxis = new NumberAxis(rb.getString("Column.Balance"));
    StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df,
            NumberFormat.getNumberInstance());
    XYBarRenderer renderer = new XYBarRenderer(0.2);
    renderer.setBaseToolTipGenerator(tooltipGenerator);

    XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
    String title = rb.getString("Title.AccountBalance") + " - " + a.getPathName();

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java

/**
 * Creates a chart of the actual view with a title.
 * @param title/*from  w w  w  . j av  a2 s  .  co  m*/
 *            The title of the chart.
 */
protected final void makeChart(final String title) {
    DateTickUnit tick = null;
    switch (actualView) {
    case DAY:
        tick = new DateTickUnit(DateTickUnitType.HOUR, 1, new SimpleDateFormat("HH"));
        break;
    case WEEK:
        tick = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat("E, dd.MM."));
        break;
    case MONTH:
        tick = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat("d."));
        break;
    case YEAR:
        tick = new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat("M"));
        break;
    default:
        break;
    }
    gui.pnlGraph.setChart(ChartFactory.createGanttChart(title, "", "", createDataset(), true, true, false));
    gui.pnlGraph.getChart().getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);
    gui.pnlGraph.getChart().getTitle().setMargin(5, 10, 5, 5);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setCategoryMargin(0.4);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setLowerMargin(0);
    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis().setUpperMargin(0);

    // chart.getCategoryPlot().getDomainAxis().getL

    gui.pnlGraph.getChart().getCategoryPlot().getDomainAxis()
            .setTickLabelFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10));

    CategoryPlot plot = gui.pnlGraph.getChart().getCategoryPlot();
    DateAxis axis = (DateAxis) plot.getRangeAxis();
    axis.setMinimumDate(actualStart.getTime());
    axis.setMaximumDate(actualEnd.getTime());
    axis.setTickUnit(tick);

    CategoryItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.green);
    renderer.setSeriesPaint(2, Color.red);
}

From source file:OAT.ui.util.UiUtil.java

public static TickUnits createSimpleTimeTickUnits() {
    TickUnits tickUnits = new TickUnits();
    SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm");
    SimpleDateFormat weekDayFormatter = new SimpleDateFormat("EEE");
    SimpleDateFormat dayFormatter = new SimpleDateFormat("dd-mm");
    SimpleDateFormat monthFormatter = new SimpleDateFormat("MMM-yy");
    SimpleDateFormat yearFormatter = new SimpleDateFormat("yyyy");

    //tickUnits.add(new DateTickUnit(DateTickUnitType.MINUTE, 30, DateTickUnitType.SECOND, 1, timeFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 1, DateTickUnitType.SECOND, 1, timeFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 2, timeFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 4, timeFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 6, timeFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.HOUR, 12, timeFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1, DateTickUnitType.HOUR, 1, weekDayFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 2, weekDayFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7, dayFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.DAY, 15, dayFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1, DateTickUnitType.DAY, 1, monthFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 3, monthFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 6, monthFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1, DateTickUnitType.MONTH, 1, yearFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 2, yearFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 5, yearFormatter));
    tickUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 10, yearFormatter));

    return tickUnits;
}

From source file:jgnash.ui.report.compiled.MonthlyAccountBalanceChartCompare.java

private JFreeChart createVerticalXYBarChart(final Account a, final Account a2) {
    DateFormat df = new SimpleDateFormat("MM/yy");
    TimeSeriesCollection data = createTimeSeriesCollection(a, a2);

    DateAxis dateAxis = new DateAxis(rb.getString("Column.Date"));
    dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MONTH, 1, df));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    // if (a.getTransactionCount() > 0) {
    Date start = DateUtils.asDate(DateUtils.getFirstDayOfTheMonth(startDateField.getLocalDate()));
    Date end = DateUtils.asDate(DateUtils.getLastDayOfTheMonth(endDateField.getLocalDate()));
    dateAxis.setRange(start, end);/*from w  ww .  ja va 2  s.  c  o  m*/
    // }

    NumberAxis valueAxis = new NumberAxis(
            rb.getString("Column.Balance") + "-" + a.getCurrencyNode().getSymbol());
    StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator("{1}, {2}", df,
            NumberFormat.getNumberInstance());
    ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer(0.2, false);
    renderer.setBaseToolTipGenerator(tooltipGenerator);

    XYPlot plot = new XYPlot(data, dateAxis, valueAxis, renderer);
    String title;
    if (jcb_compare.isSelected()) {
        title = a.getPathName() + " vs " + a2.getPathName();
    } else {
        title = rb.getString("Title.AccountBalance") + " - " + a.getPathName();
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(null);

    return chart;
}

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSource.java

/**
 * Initializes the graph.  This method generates the backing {@link JFreeChart} from the time series and graph
 * parameter data./*from w  ww  .java2  s .  co m*/
 *
 * @throws GraphException if the initialization fails
 */
public void initialize() throws GraphException {
    String title = getParam(GraphSource.GRAPH_TITLE, String.class, DEFAULT_TITLE);
    String xLabel = getParam(GraphSource.GRAPH_X_LABEL, String.class, DEFAULT_DOMAIN_LABEL);
    String yLabel = getParam(GraphSource.GRAPH_Y_LABEL, String.class, DEFAULT_RANGE_LABEL);
    Shape graphShape = getParam(GraphSource.GRAPH_SHAPE, Shape.class, DEFAULT_GRAPH_SHAPE);
    Paint graphColor = getParam(GraphSource.GRAPH_COLOR, Paint.class, DEFAULT_GRAPH_COLOR);
    boolean legend = getParam(GraphSource.GRAPH_LEGEND, Boolean.class, DEFAULT_GRAPH_LEGEND);
    boolean graphToolTip = getParam(GraphSource.GRAPH_TOOL_TIP, Boolean.class, DEFAULT_GRAPH_TOOL_TIP);
    Stroke graphStroke = getParam(GraphSource.GRAPH_STROKE, Stroke.class, DEFAULT_GRAPH_STROKE);
    Font titleFont = getParam(GraphSource.GRAPH_FONT, Font.class, DEFAULT_GRAPH_TITLE_FONT);
    boolean graphBorder = getParam(GraphSource.GRAPH_BORDER, Boolean.class, DEFAULT_GRAPH_BORDER);
    boolean legendBorder = getParam(GraphSource.LEGEND_BORDER, Boolean.class, DEFAULT_LEGEND_BORDER);
    Double offset = getParam(GraphSource.AXIS_OFFSET, Double.class, DEFAULT_AXIS_OFFSET);

    checkSeriesType(data);
    @SuppressWarnings("unchecked")
    List<? extends TimeSeriesInterface> timeData = (List<? extends TimeSeriesInterface>) data;

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    int seriesCount = 1;
    for (TimeSeriesInterface series : timeData) {
        dataset.addSeries(buildTimeSeries(series, seriesCount));
        seriesCount += 1;
    }

    // actually create the chart
    this.chart = ChartFactory.createTimeSeriesChart(title, xLabel, yLabel, dataset, false, graphToolTip, false);

    // start customizing it
    Paint backgroundColor = getParam(GraphSource.BACKGROUND_COLOR, Paint.class, DEFAULT_BACKGROUND_COLOR);
    Paint plotColor = getParam(JFreeChartTimeSeriesGraphSource.PLOT_COLOR, Paint.class, backgroundColor);
    Paint graphDomainGridlinePaint = getParam(GraphSource.GRAPH_DOMAIN_GRIDLINE_PAINT, Paint.class,
            backgroundColor);
    Paint graphRangeGridlinePaint = getParam(GraphSource.GRAPH_RANGE_GRIDLINE_PAINT, Paint.class,
            backgroundColor);

    this.chart.setBackgroundPaint(backgroundColor);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(plotColor);
    plot.setAxisOffset(new RectangleInsets(offset, offset, offset, offset));
    plot.setDomainGridlinePaint(graphDomainGridlinePaint);
    plot.setRangeGridlinePaint(graphRangeGridlinePaint);

    if (graphBorder) {

    } else {
        plot.setOutlinePaint(null);
    }

    //Use a TextTitle to change the font of the graph title
    TextTitle title1 = new TextTitle();
    title1.setText(title);
    title1.setFont(titleFont);
    chart.setTitle(title1);

    //Makes a wrapper for the legend to remove the border around it
    if (legend) {
        LegendTitle legend1 = new LegendTitle(chart.getPlot());
        BlockContainer wrapper = new BlockContainer(new BorderArrangement());
        if (legendBorder) {
            wrapper.setFrame(new BlockBorder(1, 1, 1, 1));
        } else {
            wrapper.setFrame(new BlockBorder(0, 0, 0, 0));
        }
        BlockContainer items = legend1.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend1.setWrapper(wrapper);
        legend1.setPosition(RectangleEdge.BOTTOM);
        legend1.setHorizontalAlignment(HorizontalAlignment.CENTER);

        if (params.get(GraphSource.LEGEND_FONT) instanceof Font) {
            legend1.setItemFont(((Font) params.get(GraphSource.LEGEND_FONT)));
        }

        chart.addSubtitle(legend1);
    }

    boolean include0 = getParam(GraphSource.GRAPH_RANGE_INCLUDE_0, Boolean.class, true);
    NumberAxis numAxis = (NumberAxis) plot.getRangeAxis();
    double rangeLower = getParam(GraphSource.GRAPH_RANGE_LOWER_BOUND, Double.class, numAxis.getLowerBound());
    double rangeUpper = getParam(GraphSource.GRAPH_RANGE_UPPER_BOUND, Double.class, numAxis.getUpperBound());
    boolean graphRangeIntegerTick = getParam(GraphSource.GRAPH_RANGE_INTEGER_TICK, Boolean.class, false);
    boolean graphRangeMinorTickVisible = getParam(GraphSource.GRAPH_RANGE_MINOR_TICK_VISIBLE, Boolean.class,
            true);

    if (include0) {
        rangeLower = 0;
    }

    numAxis.setRange(rangeLower, rangeUpper);

    if (graphRangeIntegerTick) {
        numAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    numAxis.setMinorTickMarksVisible(graphRangeMinorTickVisible);
    setupFont(numAxis, GraphSource.GRAPH_Y_AXIS_FONT);

    if (params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT) instanceof Font) {
        numAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_Y_AXIS_LABEL_FONT)));
    }

    TimeResolution minimumResolution = getMinimumResolution(timeData);
    DateFormat dateFormat = getParam(GraphSource.GRAPH_DATE_FORMATTER, DateFormat.class,
            new DefaultDateFormatFactory().getFormat(minimumResolution));

    if (params.get(DATE_AXIS) instanceof DateAxis) {
        DateAxis dateAxis = (DateAxis) params.get(DATE_AXIS);
        dateAxis.setLabel(xLabel);
        plot.setDomainAxis(dateAxis);
    }
    DateAxis dateAxis = ((DateAxis) plot.getDomainAxis());
    dateAxis.setDateFormatOverride(dateFormat);

    if (params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT) instanceof Font) {
        dateAxis.setLabelFont(((Font) params.get(GraphSource.GRAPH_X_AXIS_LABEL_FONT)));
    }

    int minTick = getParam(GraphSource.GRAPH_MIN_DOMAIN_TICK, Integer.class, 1);
    if (minTick <= 0) {
        minTick = 1;
    }

    dateAxis.setTickUnit(getDateTickUnit(minimumResolution, minTick), false, false);
    //dateAxis.setMinorTickMarksVisible(true);
    //dateAxis.setMinorTickCount(7);
    dateAxis.setMinorTickMarkOutsideLength(2);

    Integer minorTick = getParam(GraphSource.GRAPH_MINOR_TICKS, Integer.class, null);
    if (minorTick != null) {
        int minorVal = minorTick;
        if (minorVal > 0) {
            dateAxis.setMinorTickCount(minorVal);
        }
    }

    setupFont(dateAxis, GraphSource.GRAPH_X_AXIS_FONT);

    //double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN);
    double lowerMargin = getParam(DOMAIN_AXIS_LOWER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_LOWER_MARGIN);
    dateAxis.setLowerMargin(lowerMargin);

    //double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN);
    double upperMargin = getParam(DOMAIN_AXIS_UPPER_MARGIN, Double.class, DEFAULT_DOMAIN_AXIS_UPPER_MARGIN);
    dateAxis.setUpperMargin(upperMargin);

    Date domainLower = getParam(GraphSource.GRAPH_DOMAIN_LOWER_BOUND, Date.class, dateAxis.getMinimumDate());
    Date domainUpper = getParam(GraphSource.GRAPH_DOMAIN_UPPER_BOUND, Date.class, dateAxis.getMaximumDate());

    dateAxis.setRange(domainLower, domainUpper);

    // depending on the domain axis range, display either 1 tick per day, week, month or year
    TickUnits standardUnits = new TickUnits();
    standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 1));
    standardUnits.add(new DateTickUnit(DateTickUnitType.DAY, 7));
    standardUnits.add(new DateTickUnit(DateTickUnitType.MONTH, 1));
    standardUnits.add(new DateTickUnit(DateTickUnitType.YEAR, 1));
    dateAxis.setStandardTickUnits(standardUnits);

    TimeSeriesRenderer renderer = new TimeSeriesRenderer(dataset);
    setupRenderer(renderer, graphColor, graphShape, graphStroke);
    renderer.setBaseFillPaint(Color.BLACK);
    renderer.setSeriesOutlinePaint(0, Color.WHITE);

    //renderer.setUseOutlinePaint(true);

    plot.setRenderer(renderer);
    this.initialized = true;
}

From source file:com.freedomotic.jfrontend.extras.GraphPanel.java

private void createChart(UsageDataFrame points, String title) {
    series = new TimeSeries(title);

    for (UsageData d : points.getData()) {
        Date resultdate = d.getDateTime();
        Millisecond ms_read = new Millisecond(resultdate);
        int poweredValue = -1;
        if (d.getObjBehavior().equalsIgnoreCase("powered")) {
            poweredValue = d.getObjValue().equalsIgnoreCase("true") ? 1 : 0;
        } else if (d.getObjBehavior().equalsIgnoreCase("brigthness")) {
            try {
                poweredValue = Integer.parseInt(d.getObjValue());
            } catch (NumberFormatException ex) {
                poweredValue = -1;//  w  w  w  . j  a  va 2 s.co  m
            }
        }
        series.addOrUpdate(ms_read, poweredValue);
    }

    XYDataset xyDataset = new TimeSeriesCollection(series);

    chart = ChartFactory.createTimeSeriesChart("Chart", "TIME", "VALUE", xyDataset, true, // legend
            true, // tooltips
            false // urls
    );
    chart.setAntiAlias(true);
    // Set plot styles
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    // Set series line styles
    plot.setRenderer(new XYStepRenderer());

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setShapesVisible(true);
        renderer.setShapesFilled(true);
    }

    // Set date axis style
    DateAxis axis = (DateAxis) plot.getDomainAxis();

    String formatString = "MM-dd HH";
    DateTickUnitType dtut = DateTickUnitType.HOUR;

    if (jComboGranularity.getSelectedItem().equals("Year")) {
        formatString = "yyyy";
        dtut = DateTickUnitType.YEAR;
    } else if (jComboGranularity.getSelectedItem().equals("Month")) {
        axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM"));
        dtut = DateTickUnitType.MONTH;
    } else if (jComboGranularity.getSelectedItem().equals("Day")) {
        axis.setDateFormatOverride(new SimpleDateFormat("MM-dd"));
        dtut = DateTickUnitType.DAY;
    } else if (jComboGranularity.getSelectedItem().equals("Minute")) {
        formatString = "MM-dd HH:mm";
        dtut = DateTickUnitType.MINUTE;
    } else if (jComboGranularity.getSelectedItem().equals("Second")) {
        formatString = "HH:mm:SS";
        dtut = DateTickUnitType.SECOND;
    }

    DateFormat formatter = new SimpleDateFormat(formatString);
    DateTickUnit unit = new DateTickUnit(dtut, 1, formatter);
    axis.setTickUnit(unit);

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
    graphPanel.removeAll();
    graphPanel.add(chartPanel);

}