Example usage for org.jfree.chart.axis DateTickMarkPosition START

List of usage examples for org.jfree.chart.axis DateTickMarkPosition START

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateTickMarkPosition START.

Prototype

DateTickMarkPosition START

To view the source code for org.jfree.chart.axis DateTickMarkPosition START.

Click Source Link

Document

Start of period.

Usage

From source file:daylightchart.daylightchart.chart.DaylightChart.java

@SuppressWarnings("deprecation")
private void createMonthsAxis(final XYPlot plot) {
    final DateAxis axis = new DateAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.START);
    axis.setLowerMargin(0.0f);/*from   w  w w.  j  a  v  a2  s  .c  o  m*/
    axis.setUpperMargin(0.0f);
    axis.setTickLabelFont(ChartConfiguration.chartFont.deriveFont(Font.PLAIN, 12));
    axis.setDateFormatOverride(ChartConfiguration.monthsFormat);
    axis.setVerticalTickLabels(true);
    axis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1), true, true);
    // Fix the axis range for all the months in the year
    final int dateYear = riseSetData.getYear() - 1900;
    axis.setRange(new Date(dateYear, 0, 1), new Date(dateYear, 11, 31));
    //
    plot.setDomainAxis(axis);
}

From source file:com.xpn.xwiki.plugin.charts.params.DefaultChartParams2.java

void setAxis(String prefix) throws ParamException {
    set(prefix + AXIS_VISIBLE_SUFIX, Axis.DEFAULT_AXIS_VISIBLE);

    set(prefix + AXIS_LINE_VISIBLE_SUFFIX, Boolean.TRUE);
    set(prefix + AXIS_LINE_COLOR_SUFFIX, Axis.DEFAULT_AXIS_LINE_PAINT);
    set(prefix + AXIS_LINE_STROKE_SUFFIX, Axis.DEFAULT_AXIS_LINE_STROKE);

    set(prefix + AXIS_LABEL_SUFFIX, ""); // ?
    set(prefix + AXIS_LABEL_FONT_SUFFIX, Axis.DEFAULT_AXIS_LABEL_FONT);
    set(prefix + AXIS_LABEL_COLOR_SUFFIX, Axis.DEFAULT_AXIS_LABEL_PAINT);
    set(prefix + AXIS_LABEL_INSERTS_SUFFIX, Axis.DEFAULT_AXIS_LABEL_INSETS);

    set(prefix + AXIS_TICK_LABEL_VISIBLE_SUFFIX, new Boolean(Axis.DEFAULT_TICK_LABELS_VISIBLE));
    set(prefix + AXIS_TICK_LABEL_FONT_SUFFIX, Axis.DEFAULT_TICK_LABEL_FONT);
    set(prefix + AXIS_TICK_LABEL_COLOR_SUFFIX, Axis.DEFAULT_TICK_LABEL_PAINT);
    set(prefix + AXIS_TICK_LABEL_INSERTS_SUFFIX, Axis.DEFAULT_TICK_LABEL_INSETS);

    set(prefix + AXIS_TICK_MARK_VISIBLE_SUFFIX, new Boolean(Axis.DEFAULT_TICK_MARKS_VISIBLE));
    set(prefix + AXIS_TICK_MARK_INSIDE_LENGTH_SUFFIX, new Float(Axis.DEFAULT_TICK_MARK_INSIDE_LENGTH));
    set(prefix + AXIS_TICK_MARK_OUTSIDE_LENGTH_SUFFIX, new Float(Axis.DEFAULT_TICK_MARK_OUTSIDE_LENGTH));
    set(prefix + AXIS_TICK_MARK_COLOR_SUFFIX, Axis.DEFAULT_TICK_MARK_PAINT);
    set(prefix + AXIS_TICK_MARK_STROKE_SUFFIX, Axis.DEFAULT_TICK_MARK_STROKE);

    set(prefix + PLOTXY_AXIS_GRIDLINE_VISIBLE_SUFFIX, Boolean.TRUE);
    set(prefix + PLOTXY_AXIS_GRIDLINE_COLOR_SUFFIX, XYPlot.DEFAULT_GRIDLINE_PAINT);
    set(prefix + PLOTXY_AXIS_GRIDLINE_STROKE_SUFFIX, XYPlot.DEFAULT_GRIDLINE_STROKE);

    set(prefix + VALUE_AXIS_AUTO_RANGE_SUFFIX, new Boolean(ValueAxis.DEFAULT_AUTO_RANGE));
    set(prefix + VALUE_AXIS_AUTO_RANGE_MIN_SIZE_SUFFIX, new Double(ValueAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE));
    set(prefix + VALUE_AXIS_AUTO_TICK_UNIT_SUFFIX, new Boolean(ValueAxis.DEFAULT_AUTO_TICK_UNIT_SELECTION));
    set(prefix + VALUE_AXIS_LOWER_BOUND_SUFFIX, new Double(ValueAxis.DEFAULT_LOWER_BOUND));
    set(prefix + VALUE_AXIS_UPPER_BOUND_SUFFIX, new Double(ValueAxis.DEFAULT_UPPER_BOUND));
    set(prefix + AXIS_LOWER_MARGIN_SUFFIX, new Double(ValueAxis.DEFAULT_LOWER_MARGIN));
    set(prefix + AXIS_UPPER_MARGIN_SUFFIX, new Double(ValueAxis.DEFAULT_UPPER_MARGIN));
    set(prefix + VALUE_AXIS_VERTICAL_TICK_LABELS_SUFFIX, Boolean.FALSE);

    set(prefix + NUMBER_AXIS_AUTO_RANGE_INCLUDES_ZERO_SUFFIX,
            new Boolean(NumberAxis.DEFAULT_AUTO_RANGE_INCLUDES_ZERO));
    set(prefix + NUMBER_AXIS_AUTO_RANGE_STICKY_ZERO_SUFFIX,
            new Boolean(NumberAxis.DEFAULT_AUTO_RANGE_STICKY_ZERO));
    set(prefix + NUMBER_AXIS_RANGE_TYPE_SUFFIX, RangeType.FULL);
    set(prefix + NUMBER_AXIS_NUMBER_TICK_UNIT_SUFFIX, NumberAxis.DEFAULT_TICK_UNIT);
    set(prefix + NUMBER_AXIS_NUMBER_FORMAT_OVERRIDE_SUFFIX, (NumberFormat) null);

    set(prefix + DATE_AXIS_DATE_FORMAT_OVERRIDE_SUFFIX, (DateFormat) null);
    set(prefix + DATE_AXIS_LOWER_DATE_SUFFIX, DateAxis.DEFAULT_DATE_RANGE.getLowerDate());
    set(prefix + DATE_AXIS_UPPER_DATE_SUFFIX, DateAxis.DEFAULT_DATE_RANGE.getUpperDate());
    set(prefix + DATE_AXIS_DATE_TICK_MARK_POSITION_SUFFIX, DateTickMarkPosition.START);
    set(prefix + DATE_AXIS_DATE_TICK_UNIT_SUFFIX, DateAxis.DEFAULT_DATE_TICK_UNIT);

    set(prefix + CATEGORY_AXIS_CATEGORY_MARGIN_SUFFIX, new Double(CategoryAxis.DEFAULT_CATEGORY_MARGIN));
    set(prefix + CATEGORY_AXIS_LABEL_POSITIONS_SUFFIX, CategoryLabelPositions.STANDARD);
    set(prefix + CATEGORY_AXIS_LABEL_POSITION_OFFSET_SUFFIX, new Integer(4));
    set(prefix + CATEGORY_AXIS_MAXIMUM_LABEL_LINES_SUFFIX, new Integer(1));
    set(prefix + CATEGORY_AXIS_MAXIMUM_LABEL_WIDTH_RATIO_SUFFIX, new Float(0.0f));
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java

/**
 * Make the plot/*from   w w  w . j  a v a 2  s .co m*/
 *
 * @return The plot_
 */
public Plot doMakePlot() {

    IdvPreferenceManager pref = control.getControlContext().getIdv().getPreferenceManager();
    TimeZone timeZone = pref.getDefaultTimeZone();
    NumberAxis valueAxis = new FixedWidthNumberAxis("");
    final SimpleDateFormat sdf = new SimpleDateFormat(
            ((dateFormat != null) ? dateFormat : pref.getDefaultDateFormat()));
    sdf.setTimeZone(timeZone);
    DateAxis timeAxis = new DateAxis("Time (" + timeZone.getID() + ")", timeZone) {

        protected List xxxxxrefreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

            List ticks = super.refreshTicksHorizontal(g2, dataArea, edge);

            List<Tick> result = new java.util.ArrayList<Tick>();

            Font tickLabelFont = getTickLabelFont();
            g2.setFont(tickLabelFont);

            if (isAutoTickUnitSelection()) {
                selectAutoTickUnit(g2, dataArea, edge);
            }

            DateTickUnit unit = getTickUnit();
            Date tickDate = calculateLowestVisibleTickValue(unit);
            Date upperDate = getMaximumDate();

            Date firstDate = null;
            while (tickDate.before(upperDate)) {

                if (!isHiddenValue(tickDate.getTime())) {
                    // work out the value, label and position
                    String tickLabel;
                    DateFormat formatter = getDateFormatOverride();
                    if (firstDate == null) {
                        if (formatter != null) {
                            tickLabel = formatter.format(tickDate);
                        } else {
                            tickLabel = getTickUnit().dateToString(tickDate);
                        }
                        firstDate = tickDate;
                    } else {
                        double msdiff = tickDate.getTime() - firstDate.getTime();
                        int hours = (int) (msdiff / 1000 / 60 / 60);
                        tickLabel = hours + "H";
                    }
                    //                tickLabel = tickLabel;
                    TextAnchor anchor = null;
                    TextAnchor rotationAnchor = null;
                    double angle = 0.0;
                    if (isVerticalTickLabels()) {
                        anchor = TextAnchor.CENTER_RIGHT;
                        rotationAnchor = TextAnchor.CENTER_RIGHT;
                        if (edge == RectangleEdge.TOP) {
                            angle = Math.PI / 2.0;
                        } else {
                            angle = -Math.PI / 2.0;
                        }
                    } else {
                        if (edge == RectangleEdge.TOP) {
                            anchor = TextAnchor.BOTTOM_CENTER;
                            rotationAnchor = TextAnchor.BOTTOM_CENTER;
                        } else {
                            anchor = TextAnchor.TOP_CENTER;
                            rotationAnchor = TextAnchor.TOP_CENTER;
                        }
                    }

                    Tick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
                    result.add(tick);
                    tickDate = unit.addToDate(tickDate, getTimeZone());
                } else {
                    tickDate = unit.rollDate(tickDate, getTimeZone());

                    continue;
                }

                // could add a flag to make the following correction optional...
                switch (unit.getUnit()) {

                case (DateTickUnit.MILLISECOND):
                case (DateTickUnit.SECOND):
                case (DateTickUnit.MINUTE):
                case (DateTickUnit.HOUR):
                case (DateTickUnit.DAY):
                    break;

                case (DateTickUnit.MONTH):
                    tickDate = calculateDateForPositionX(new Month(tickDate, getTimeZone()),
                            getTickMarkPosition());

                    break;

                case (DateTickUnit.YEAR):
                    tickDate = calculateDateForPositionX(new Year(tickDate, getTimeZone()),
                            getTickMarkPosition());

                    break;

                default:
                    break;

                }

            }

            return result;

        }

        private Date calculateDateForPositionX(RegularTimePeriod period, DateTickMarkPosition position) {

            if (position == null) {
                throw new IllegalArgumentException("Null 'position' argument.");
            }
            Date result = null;
            if (position == DateTickMarkPosition.START) {
                result = new Date(period.getFirstMillisecond());
            } else if (position == DateTickMarkPosition.MIDDLE) {
                result = new Date(period.getMiddleMillisecond());
            } else if (position == DateTickMarkPosition.END) {
                result = new Date(period.getLastMillisecond());
            }

            return result;

        }

    };
    timeAxis.setDateFormatOverride(sdf);

    final XYPlot[] xyPlotHolder = { null };

    xyPlotHolder[0] = new MyXYPlot(new TimeSeriesCollection(), timeAxis, valueAxis, null) {
        public void drawBackground(Graphics2D g2, Rectangle2D area) {
            super.drawBackground(g2, area);
            drawSunriseSunset(g2, xyPlotHolder[0], area);
        }
    };

    if (animationTimeAnnotation != null) {
        xyPlotHolder[0].addAnnotation(animationTimeAnnotation);
    }

    return xyPlotHolder[0];

}

From source file:org.trade.ui.chart.CandlestickChart.java

/**
 * Method createChart./*from ww  w. j  a  v a  2s.  co m*/
 * 
 * @param strategyData
 *            StrategyData
 * @param title
 *            String
 * @return JFreeChart
 */
private JFreeChart createChart(StrategyData strategyData, String title, Tradingday tradingday) {

    DateAxis dateAxis = new DateAxis("Date");
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM hh:mm"));
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    NumberAxis priceAxis = new NumberAxis("Price");
    priceAxis.setAutoRange(true);
    priceAxis.setAutoRangeIncludesZero(false);
    XYPlot pricePlot = new XYPlot(strategyData.getCandleDataset(), dateAxis, priceAxis,
            strategyData.getCandleDataset().getRenderer());
    pricePlot.setOrientation(PlotOrientation.VERTICAL);
    pricePlot.setDomainPannable(true);
    pricePlot.setRangePannable(true);
    pricePlot.setDomainCrosshairVisible(true);
    pricePlot.setDomainCrosshairLockedOnData(true);
    pricePlot.setRangeCrosshairVisible(true);
    pricePlot.setRangeCrosshairLockedOnData(true);
    pricePlot.setRangeGridlinePaint(new Color(204, 204, 204));
    pricePlot.setDomainGridlinePaint(new Color(204, 204, 204));
    pricePlot.setBackgroundPaint(Color.white);

    /*
     * Calculate the number of 15min segments in this trading day. i.e.
     * 6.5hrs/15min = 26 and there are a total of 96 = one day
     */

    int segments15min = (int) (tradingday.getClose().getTime() - tradingday.getOpen().getTime())
            / (1000 * 60 * 15);

    SegmentedTimeline segmentedTimeline = new SegmentedTimeline(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE,
            segments15min, (96 - segments15min));

    Date startDate = tradingday.getOpen();
    Date endDate = tradingday.getClose();

    if (!strategyData.getCandleDataset().getSeries(0).isEmpty()) {
        startDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0).getDataItem(0)).getPeriod()
                .getStart();
        startDate = TradingCalendar.getSpecificTime(tradingday.getOpen(), startDate);
        endDate = ((CandleItem) strategyData.getCandleDataset().getSeries(0)
                .getDataItem(strategyData.getCandleDataset().getSeries(0).getItemCount() - 1)).getPeriod()
                        .getStart();
        endDate = TradingCalendar.getSpecificTime(tradingday.getClose(), endDate);
    }

    segmentedTimeline.setStartTime(startDate.getTime());
    segmentedTimeline.addExceptions(getNonTradingPeriods(startDate, endDate, tradingday.getOpen(),
            tradingday.getClose(), segmentedTimeline));
    dateAxis.setTimeline(segmentedTimeline);

    // Build Combined Plot
    CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(dateAxis);
    mainPlot.add(pricePlot, 4);

    int axixIndex = 0;
    int datasetIndex = 0;

    /*
     * Change the List of indicators so that the candle dataset is the first
     * one in the list. The main chart must be plotted first.
     */
    List<IndicatorDataset> indicators = new ArrayList<IndicatorDataset>(0);
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (IndicatorDataset item : strategyData.getIndicators()) {
        if (!IndicatorSeries.CandleSeries.equals(item.getType(0))) {
            indicators.add(item);
        }
    }
    for (int i = 0; i < indicators.size(); i++) {
        IndicatorDataset indicator = indicators.get(i);
        if (indicator.getDisplaySeries(0)) {

            if (indicator.getSubChart(0)) {
                String axisName = "Price";
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    axisName = ((CandleSeries) indicator.getSeries(0)).getSymbol();
                } else {
                    org.trade.dictionary.valuetype.IndicatorSeries code = org.trade.dictionary.valuetype.IndicatorSeries
                            .newInstance(indicator.getType(0));
                    axisName = code.getDisplayName();
                }
                NumberAxis subPlotAxis = new NumberAxis(axisName);
                subPlotAxis.setAutoRange(true);
                subPlotAxis.setAutoRangeIncludesZero(false);

                XYPlot subPlot = new XYPlot((XYDataset) indicator, dateAxis, subPlotAxis,
                        indicator.getRenderer());

                subPlot.setOrientation(PlotOrientation.VERTICAL);
                subPlot.setDomainPannable(true);
                subPlot.setRangePannable(true);
                subPlot.setDomainCrosshairVisible(true);
                subPlot.setDomainCrosshairLockedOnData(true);
                subPlot.setRangeCrosshairVisible(true);
                subPlot.setRangeCrosshairLockedOnData(true);
                subPlot.setRangeGridlinePaint(new Color(204, 204, 204));
                subPlot.setDomainGridlinePaint(new Color(204, 204, 204));
                subPlot.setBackgroundPaint(Color.white);
                XYItemRenderer renderer = subPlot.getRendererForDataset((XYDataset) indicator);
                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
                mainPlot.add(subPlot, 1);

            } else {
                datasetIndex++;
                pricePlot.setDataset(datasetIndex, (XYDataset) indicator);
                if (IndicatorSeries.CandleSeries.equals(indicator.getType(0))) {
                    // add secondary axis
                    axixIndex++;

                    final NumberAxis axis2 = new NumberAxis(
                            ((CandleSeries) indicator.getSeries(0)).getSymbol());
                    axis2.setAutoRange(true);
                    axis2.setAutoRangeIncludesZero(false);
                    pricePlot.setRangeAxis(datasetIndex, axis2);
                    pricePlot.setRangeAxisLocation(i + 1, AxisLocation.BOTTOM_OR_RIGHT);
                    pricePlot.mapDatasetToRangeAxis(datasetIndex, axixIndex);
                    pricePlot.setRenderer(datasetIndex, new StandardXYItemRenderer());
                } else {
                    pricePlot.setRenderer(datasetIndex, indicator.getRenderer());
                }
                XYItemRenderer renderer = pricePlot.getRendererForDataset((XYDataset) indicator);

                for (int seriesIndex = 0; seriesIndex < ((XYDataset) indicator)
                        .getSeriesCount(); seriesIndex++) {
                    renderer.setSeriesPaint(seriesIndex, indicator.getSeriesColor(seriesIndex));
                }
            }
        }
    }
    JFreeChart jfreechart = new JFreeChart(title, null, mainPlot, true);
    jfreechart.setAntiAlias(false);
    return jfreechart;
}

From source file:ch.ksfx.web.services.chart.ObservationChartGenerator.java

public void setRange(JFreeChart jFreeChart, List<Observation> observations) {
    //This has to be sorted by value!!
    List<Observation> sortedObservations = new ArrayList<Observation>(observations);
    Collections.sort(sortedObservations, new ObservationDoubleValueComparator());

    XYPlot xyp = jFreeChart.getXYPlot();

    //xyp.addAnnotation(new XYTextAnnotation("Fummel", dataset.getX(0,10).doubleValue(), dataset.getY(0, 10).doubleValue()));

    NumberAxis axis = (NumberAxis) xyp.getRangeAxis();

    Double width = Double.parseDouble(sortedObservations.get(sortedObservations.size() - 1).getScalarValue())
            - Double.parseDouble(sortedObservations.get(0).getScalarValue());

    axis.setRange(Double.parseDouble(sortedObservations.get(0).getScalarValue()) - width / 4,
            Double.parseDouble(sortedObservations.get(sortedObservations.size() - 1).getScalarValue())
                    + width / 4);//from w ww.j  a  va 2 s . c o  m

    DateAxis daxis = new DateAxis("Time Axis");

    daxis.setVerticalTickLabels(true);

    daxis.setTickMarkPosition(DateTickMarkPosition.START);
    daxis.setAutoRange(true);
    daxis.setDateFormatOverride(new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"));
    xyp.setDomainAxis(daxis);

}

From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java

/**
 * Set up the PhyloDataAxis for our dates.
 * <P>/*from w  ww . j a  va2s.  c  o  m*/
 * If the leaf nodes change then <code>fetchLeafNodes</code> needs to be called before
 * this.
 *
 * TODO: UI fixes for rounding up and down the date so that they fall on the next unit
 */
private void calculateDateAxis() {
    // TODO: senstive to changes in the document
    if (fTopLeafDate == null || fBottomLeafDate == null)
        return;
    // TODO: throw exception

    // calculate our tickUnit and dateFormatOverride
    Date upperDate = this.fLeafDates.get(this.fTopLeafDate).getTime();
    Date lowerDate = this.fLeafDates.get(this.fBottomLeafDate).getTime();

    long dateDiff = upperDate.getTime() - lowerDate.getTime();
    DateTickUnit dtu;
    SimpleDateFormat sdf;
    if (dateDiff > ONE_MS_YEAR * 2) {
        // TODO adjust tickUnitCount for very big year distances
        dtu = new DateTickUnit(DateTickUnit.YEAR, this.fTickUnitCount);
        sdf = new SimpleDateFormat("yyyy");
    } else if (dateDiff <= ONE_MS_YEAR * 2 || dateDiff > ONE_MS_MONTH) {
        if (dateDiff > ONE_MS_YEAR) {
            dtu = new DateTickUnit(DateTickUnit.MONTH, this.fTickUnitCount * 2);
        } else {
            dtu = new DateTickUnit(DateTickUnit.MONTH, this.fTickUnitCount);
        }
        sdf = new SimpleDateFormat("MM/yyyy");
    } else {
        dtu = new DateTickUnit(DateTickUnit.DAY, this.fTickUnitCount);
        sdf = new SimpleDateFormat("MM/dd/yyyy");
    }

    fDateAxis.setTickUnit(dtu);
    fDateAxis.setDateFormatOverride(sdf);

    // TODO: tickMarkPosition
    fDateAxis.setTickMarkPosition(DateTickMarkPosition.START);

    // set the range
    fDateAxis.setRange(lowerDate, upperDate);

}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] createMonthlyLoginChart(int width, int height) {
    IntervalXYDataset dataset1 = getMonthlyLoginsDataSet();
    IntervalXYDataset dataset3 = getMonthlySiteUserDataSet();

    if ((dataset1 == null) || (dataset3 == null)) {
        return generateNoDataChart(width, height);
    }//ww  w  .  j  a v a 2 s  .c  o  m

    // create plot ...
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.RED);

    DateAxis domainAxis = new DateAxis("");
    domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("yyyy-MM")));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.START);
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);

    NumberAxis axis1 = new NumberAxis("Total Logins");
    axis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis1.setLabelPaint(Color.RED);
    axis1.setTickLabelPaint(Color.RED);

    XYPlot plot1 = new XYPlot(dataset1, null, axis1, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // AXIS 2
    /*
    NumberAxis axis2 = new NumberAxis("Total Unique Users");
    axis2.setStandardTickUnits (NumberAxis.createIntegerTickUnits ());
    axis2.setLabelPaint(Color.BLUE);
    axis2.setTickLabelPaint(Color.BLUE);
    plot1.setRangeAxis(1, axis2);
            
    plot1.setDataset(1, dataset2);
    plot1.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f, 
        BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer2.setSeriesPaint (0, Color.BLUE);
    plot1.setRenderer(1, renderer2);
    */

    // add a third dataset and renderer...
    XYItemRenderer renderer3 = new XYLineAndShapeRenderer(true, false);
    renderer3.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer3.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer3.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer3.setSeriesPaint(0, Color.GREEN);
    renderer3.setSeriesPaint(1, Color.BLACK);
    renderer3.setSeriesPaint(2, Color.CYAN);

    axis1 = new NumberAxis("count");
    axis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYPlot plot2 = new XYPlot(dataset3, null, axis1, renderer3);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] createWeeklyLoginChart(int width, int height) {
    IntervalXYDataset dataset1 = getWeeklyLoginsDataSet();
    IntervalXYDataset dataset2 = getWeeklySiteUserDataSet();

    if ((dataset1 == null) || (dataset2 == null)) {
        return generateNoDataChart(width, height);
    }//  w w w .j av  a 2s . co  m

    // create plot ...
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.RED);
    renderer1.setSeriesPaint(0, Color.BLUE);

    DateAxis domainAxis = new DateAxis("");
    domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("yyyy-MM-dd")));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.START);
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);

    NumberAxis rangeAxis = new NumberAxis("count");
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer2.setSeriesPaint(0, Color.GREEN);
    renderer2.setSeriesPaint(1, Color.BLACK);
    renderer2.setSeriesPaint(2, Color.CYAN);

    rangeAxis = new NumberAxis("count");
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] createDailyLoginChart(int width, int height) {
    IntervalXYDataset dataset1 = getDailyLoginsDataSet();
    IntervalXYDataset dataset2 = getDailySiteUserDataSet();

    if ((dataset1 == null) || (dataset2 == null)) {
        return generateNoDataChart(width, height);
    }//ww  w.  j  a v a  2s . com

    // create plot ...
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setSeriesPaint(0, Color.RED);
    renderer1.setSeriesPaint(1, Color.BLUE);
    renderer1.setSeriesPaint(2, Color.RED);
    renderer1.setSeriesPaint(3, Color.BLUE);
    renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    BasicStroke dashLineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0,
            new float[] { 4 }, 0);
    renderer1.setSeriesStroke(2, dashLineStroke);
    renderer1.setSeriesStroke(3, dashLineStroke);

    DateAxis domainAxis = new DateAxis("");
    domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("yyyy-MM-dd")));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.START);
    domainAxis.setVerticalTickLabels(true);
    domainAxis.setLowerMargin(0.01);
    domainAxis.setUpperMargin(0.01);

    NumberAxis rangeAxis = new NumberAxis("count");
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer2.setSeriesPaint(0, Color.GREEN);
    renderer2.setSeriesPaint(1, Color.BLACK);
    renderer2.setSeriesPaint(2, Color.CYAN);

    rangeAxis = new NumberAxis("count");
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}