Example usage for org.jfree.chart.axis DateAxis setTickMarksVisible

List of usage examples for org.jfree.chart.axis DateAxis setTickMarksVisible

Introduction

In this page you can find the example usage for org.jfree.chart.axis DateAxis setTickMarksVisible.

Prototype

public void setTickMarksVisible(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the tick marks are showing and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:scrum.server.common.BurndownChart.java

private static JFreeChart createSprintBurndownChart(List<BurndownSnapshot> snapshots, Date firstDay,
        Date lastDay, Date originallyLastDay, WeekdaySelector freeDays, int dateMarkTickUnit,
        float widthPerDay) {
    DefaultXYDataset data = createSprintBurndownChartDataset(snapshots, firstDay, lastDay, originallyLastDay,
            freeDays);/* w  w  w.j a va2s. c  o  m*/

    double tick = 1.0;
    double max = BurndownChart.getMaximum(data);

    while (max / tick > 25) {
        tick *= 2;
        if (max / tick <= 25)
            break;
        tick *= 2.5;
        if (max / tick <= 25)
            break;
        tick *= 2;
    }
    double valueLabelTickUnit = tick;
    double upperBoundary = Math.min(max * 1.1f, max + 3);

    if (!Sys.isHeadless())
        LOG.warn("GraphicsEnvironment is not headless");
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", data, PlotOrientation.VERTICAL, false, true,
            false);

    chart.setBackgroundPaint(Color.WHITE);

    XYPlot plot = chart.getXYPlot();
    // plot.setInsets(new RectangleInsets(0, 0, 0, 0));
    plot.setAxisOffset(RectangleInsets.ZERO_INSETS);
    // plot.setOutlineVisible(false);

    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.lightGray);
    // plot.setRangeCrosshairPaint(Color.lightGray);
    // plot.setRangeMinorGridlinePaint(Color.lightGray);
    // plot.setDomainCrosshairPaint(Color.blue);
    // plot.setDomainMinorGridlinePaint(Color.green);
    // plot.setDomainTickBandPaint(Color.green);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2f));

    renderer.setSeriesPaint(0, COLOR_PAST_LINE);
    renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesPaint(1, COLOR_PROJECTION_LINE);
    renderer.setSeriesStroke(1,
            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { 3f }, 0));
    renderer.setSeriesPaint(2, COLOR_OPTIMUM_LINE);
    renderer.setSeriesStroke(2, new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));

    DateAxis domainAxis1 = new DateAxis();
    String dateFormat = "d.";
    widthPerDay -= 5;
    if (widthPerDay > 40) {
        dateFormat = "EE " + dateFormat;
    }
    if (widthPerDay > 10) {
        float spaces = widthPerDay / 2.7f;
        dateFormat = Str.multiply(" ", (int) spaces) + dateFormat;
    }
    domainAxis1.setDateFormatOverride(new SimpleDateFormat(dateFormat, Locale.US));
    domainAxis1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, dateMarkTickUnit));
    domainAxis1.setAxisLineVisible(false);
    Range range = new Range(firstDay.toMillis(), lastDay.nextDay().toMillis());
    domainAxis1.setRange(range);

    DateAxis domainAxis2 = new DateAxis();
    domainAxis2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
    domainAxis2.setTickMarksVisible(false);
    domainAxis2.setTickLabelsVisible(false);
    domainAxis2.setRange(range);

    plot.setDomainAxis(0, domainAxis2);
    plot.setDomainAxis(1, domainAxis1);
    plot.setDomainAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setNumberFormatOverride(NumberFormat.getIntegerInstance());
    rangeAxis.setTickUnit(new NumberTickUnit(valueLabelTickUnit));

    rangeAxis.setLowerBound(0);
    rangeAxis.setUpperBound(upperBoundary);

    plot.setRangeAxis(rangeAxis);

    return chart;
}

From source file:msec.org.Tools.java

public static String generateFullDayChart(String filename, OneDayValue[] data, String title) {
    if (data[0].getValues().length != 1440) {
        return "data size invalid";
    }/*from w w w. j a va2  s.c  om*/
    if (data.length > 1) {
        if (data[1].getValues() == null || data[1].getValues().length != 1440) {
            return "data 1 invalid";
        }
    }

    XYDataset xydataset = createDataset(data);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);

    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();

        //
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        GregorianCalendar endgc = (GregorianCalendar) gc.clone();
        endgc.add(GregorianCalendar.DATE, 1);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 2));
        dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");

        //
        ValueAxis rangeAxis = xyplot.getRangeAxis();//?
        rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setLabelPaint(ChartColor.gray);
        rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setTickLabelPaint(ChartColor.gray);
        rangeAxis.setLowerBound(0);

        //
        jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.gray);
        jfreechart.getLegend().setBorder(0, 0, 0, 0);//

        //
        jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));//
        jfreechart.getTitle().setPaint(ChartColor.gray);

        //?
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setOutlinePaint(null);//

        int w = 500;
        int h = 300;

        // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h);

        return "success";

    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:msec.org.Tools.java

public static String generateDaysChart(String filename, ArrayList<OneDayValue> data, OneAttrDaysChart chart,
        String title, int duration) {
    if (data.size() == 0) {
        return "data size invalid";
    }//  w  ww  .  ja  va2 s  . co  m

    int date = Integer.parseInt(data.get(0).getDate());
    GregorianCalendar startgc = new GregorianCalendar(date / 10000, date % 10000 / 100 - 1, date % 100);

    XYDataset xydataset = createDaysDataset(data, startgc, chart);
    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title, "time", "", xydataset, true, true, true);

    try {
        XYPlot xyplot = (XYPlot) jfreechart.getPlot();

        //
        DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
        dateaxis.setDateFormatOverride(new SimpleDateFormat("MM/dd"));
        dateaxis.setLabelFont(new Font("", Font.PLAIN, 16)); //
        dateaxis.setLabelPaint(ChartColor.gray);
        dateaxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        dateaxis.setTickLabelPaint(ChartColor.GRAY);

        dateaxis.setMinimumDate(startgc.getTime());
        GregorianCalendar endgc = (GregorianCalendar) startgc.clone();
        endgc.add(GregorianCalendar.DATE, duration);
        dateaxis.setMaximumDate(endgc.getTime());

        dateaxis.setTickMarksVisible(true);
        dateaxis.setTickMarkInsideLength(5);
        dateaxis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1));
        dateaxis.setVerticalTickLabels(true);
        dateaxis.setLabel("");

        //
        ValueAxis rangeAxis = xyplot.getRangeAxis();//?
        rangeAxis.setLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setLabelPaint(ChartColor.gray);
        rangeAxis.setTickLabelFont(new Font("", Font.PLAIN, 16));
        rangeAxis.setTickLabelPaint(ChartColor.gray);
        rangeAxis.setLowerBound(0);

        //
        jfreechart.getLegend().setItemFont(new Font("", Font.PLAIN, 12));
        jfreechart.getLegend().setItemPaint(ChartColor.gray);
        jfreechart.getLegend().setBorder(0, 0, 0, 0);//

        //
        jfreechart.getTitle().setFont(new Font("", Font.PLAIN, 18));//
        jfreechart.getTitle().setPaint(ChartColor.gray);

        //?
        xyplot.setRangeGridlinePaint(ChartColor.GRAY);
        xyplot.setBackgroundPaint(ChartColor.WHITE);
        xyplot.setOutlinePaint(null);//

        int w = 500;
        int h = 300;

        // ChartUtilities.saveChartAsPNG(new File(filename), jfreechart, w, h);
        ChartUtilities.saveChartAsJPEG(new File(filename), 0.8f, jfreechart, w, h);

        return "success";

    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createXYAreaSparkline(XYDataset dataset) {
    JFreeChart jfreechart = ChartFactory.createXYAreaChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            false, false, false);/*from  w w w .j  av  a 2s .com*/
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(true);
    xyplot.setBackgroundPaint(null);
    xyplot.setOutlinePaint(null);
    xyplot.setForegroundAlpha(0.8F);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setDomainCrosshairVisible(false);
    xyplot.setRangeGridlinesVisible(false);
    xyplot.setRangeCrosshairVisible(false);

    DateAxis dateaxis = new DateAxis("");
    dateaxis.setTickLabelsVisible(false);
    dateaxis.setTickMarksVisible(false);
    dateaxis.setAxisLineVisible(false);
    dateaxis.setNegativeArrowVisible(false);
    dateaxis.setPositiveArrowVisible(false);
    dateaxis.setVisible(false);
    xyplot.setDomainAxis(dateaxis);

    ValueAxis rangeAxis = xyplot.getRangeAxis();
    rangeAxis.setTickLabelsVisible(false);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setAxisLineVisible(false);
    rangeAxis.setNegativeArrowVisible(false);
    rangeAxis.setPositiveArrowVisible(false);
    rangeAxis.setVisible(false);

    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setSeriesPaint(1, UIConstants.INTEL_DARK_GRAY);
    xyitemrenderer.setSeriesPaint(0, NodeTypeViz.SWITCH.getColor());
    return jfreechart;
}

From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java

/**
 * The resulting chart consists a TimeSeries for each FeatureOfInterest contained in the
 * observationCollection./*from   w  w  w .  ja va 2s  .  c  om*/
 * 
 * @param foiIdArray
 *        the IDs of the FeaturesOfInterest whose Observations shall be rendered
 * @param observationCollection
 * @return
 */
protected XYPlot drawChart4FOI(String foiID, Map<ITimePosition, ObservedValueTuple> timeMap) {

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    TimeSeries timeSeries = new TimeSeries(foiID, Second.class);

    for (ITimePosition timePos : timeMap.keySet()) {
        Number value = (Number) timeMap.get(timePos).getValue(0);
        timeSeries.add(
                new Second(new Float(timePos.getSecond()).intValue(), timePos.getMinute(), timePos.getHour(),
                        timePos.getDay(), timePos.getMonth(), new Long(timePos.getYear()).intValue()),
                value);
    }

    dataset.addSeries(timeSeries);
    dataset.setDomainIsPointsInTime(true);

    //
    // create Plot:
    //

    XYPlot plot = new XYPlot();

    plot.setDataset(dataset);
    plot.setBackgroundPaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(false);
    plot.setRenderer(renderer);

    DateAxis dateAxis = new DateAxis();
    dateAxis.setTickMarkPosition(DateTickMarkPosition.START);
    dateAxis.setTickMarksVisible(true);
    dateAxis.setVerticalTickLabels(true);
    dateAxis.setDateFormatOverride(new SimpleDateFormat("dd'.'MM'.'"));
    plot.setDomainAxis(dateAxis);

    plot.setRangeAxis(new NumberAxis());

    return plot;
}

From source file:greenapi.ui.charts.ChartPanelSupport.java

/**
 * Clean the value of the chart.//from  ww w  .j av  a  2 s  .co  m
 * 
 * @see #createChart()
 */
public void cleanChart() {
    this.chart.removeLegend();
    this.chartPanel.setBorder(null);

    cleanLabels();

    DateAxis localDateAxis = (DateAxis) ((XYPlot) this.chart.getPlot()).getDomainAxis();
    localDateAxis.setTickLabelsVisible(false);
    localDateAxis.setTickMarksVisible(false);
    localDateAxis.setAxisLineVisible(false);

    ValueAxis localValueAxis = ((XYPlot) this.chart.getPlot()).getRangeAxis();
    localValueAxis.setTickLabelsVisible(false);
    localValueAxis.setTickMarksVisible(false);
    localValueAxis.setAxisLineVisible(false);

    XYPlot localXYPlot = (XYPlot) this.chart.getPlot();
    localXYPlot.setDomainGridlineStroke(this.defaultLineStroke);
    localXYPlot.setDomainGridlinesVisible(true);
    localXYPlot.setRangeGridlineStroke(this.defaultLineStroke);
    localXYPlot.setRangeGridlinesVisible(true);

    localXYPlot.setAxisOffset(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D));
    localXYPlot.setInsets(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D), true);
}

From source file:wattsup.jsdk.ui.ChartPanelSupport.java

/**
 * Clean the values of the chart.// w w w .jav  a2  s.  c o  m
 * 
 * @see #createChart()
 */
public void cleanChart() {
    this.chart_.removeLegend();
    this.chartPanel_.setBorder(null);

    cleanLabels();

    DateAxis localDateAxis = (DateAxis) ((XYPlot) this.chart_.getPlot()).getDomainAxis();
    localDateAxis.setTickLabelsVisible(false);
    localDateAxis.setTickMarksVisible(false);
    localDateAxis.setAxisLineVisible(false);

    ValueAxis localValueAxis = ((XYPlot) this.chart_.getPlot()).getRangeAxis();
    localValueAxis.setTickLabelsVisible(false);
    localValueAxis.setTickMarksVisible(false);
    localValueAxis.setAxisLineVisible(false);

    XYPlot localXYPlot = (XYPlot) this.chart_.getPlot();
    localXYPlot.setDomainGridlineStroke(this.defaultLineStroke_);
    localXYPlot.setDomainGridlinesVisible(true);
    localXYPlot.setRangeGridlineStroke(this.defaultLineStroke_);
    localXYPlot.setRangeGridlinesVisible(true);

    localXYPlot.setAxisOffset(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D));
    localXYPlot.setInsets(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D), true);
}

From source file:net.sourceforge.processdash.ui.web.psp.TimeLogPhaseWaterfallChart.java

private JFreeChart createChart(IntervalXYDataset dataset, ProcessUtil process, List<String> phases,
        GapSkipTracker gaps) {// w ww.ja v  a 2 s.c om
    JFreeChart result = ChartFactory.createXYBarChart(null, null, true, null, dataset, PlotOrientation.VERTICAL,
            false, true, false);

    XYPlot xyplot = (XYPlot) result.getPlot();
    DateAxis dateAxis = new DateAxis(null);
    dateAxis.setTickMarksVisible(false);
    dateAxis.setTickLabelsVisible(false);
    dateAxis.setLowerMargin(0.01);
    dateAxis.setUpperMargin(0.01);
    setupGaps(gaps, dateAxis, xyplot);
    xyplot.setDomainAxis(dateAxis);

    String[] phaseNameList = new String[phases.size()];
    for (int i = 0; i < phaseNameList.length; i++)
        phaseNameList[i] = Translator.translate(phases.get(i));
    SymbolAxis symbolaxis = new SymbolAxis(null, phaseNameList);
    symbolaxis.setGridBandsVisible(false);
    xyplot.setRangeAxis(symbolaxis);

    final XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer();
    renderer.setUseYInterval(true);
    renderer.setDrawBarOutline(true);
    renderer.setBaseOutlinePaint(Color.black);

    new PhaseChartColorer(process, phases) {
        public void setItemColor(Object key, int pos, Color c) {
            renderer.setSeriesPaint(pos, c);
        }
    }.run();

    int exceptionSeries = dataset.getSeriesCount() - 1;
    renderer.setSeriesPaint(exceptionSeries, EXCEPTION_PAINT);
    renderer.setSeriesFillPaint(exceptionSeries, EXCEPTION_PAINT);
    renderer.setSeriesOutlinePaint(exceptionSeries, EXCEPTION_PAINT);

    renderer.setBaseToolTipGenerator(new TooltipGenerator());

    xyplot.setBackgroundPaint(Color.white);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());

    result.setAntiAlias(false);
    result.setTextAntiAlias(true);

    parameters.put("title", resources.getString("Title"));

    return result;
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a simple Time Axis.//from  w  w  w.  j a v  a  2 s.c o m
 *
 * @return the generated Time Axis.
 */
private DateAxis generateTimeAxis() {
    DateAxis xAxis = new DateAxis("");
    xAxis.setLowerMargin(0.05);
    xAxis.setUpperMargin(0.02);
    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);

    xAxis.setAxisLineVisible(true);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(true);
    xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    Locale locale = JiveGlobals.getLocale();
    // If the tick units have not yet been setup or the locale has changed
    if (tickUnits == null || !locale.equals(oldLocale)) {
        tickUnits = createTickUnits(locale, JiveGlobals.getTimeZone());
        oldLocale = locale;
    }
    xAxis.setStandardTickUnits(tickUnits);

    return xAxis;
}

From source file:beproject.MainGUI.java

void liveTweetAnalysis() {
    new DataGenerator(1000).start();
    rate = new TimeSeries("Total count", Second.class);
    rate.setMaximumItemAge(15);/* w w w  .j  av  a2s  .  c  om*/
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(rate);
    DateAxis domain = new DateAxis("Time");
    NumberAxis range = new NumberAxis("Tweet Count");
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setSeriesPaint(1, Color.BLUE);
    renderer.setSeriesStroke(0, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    renderer.setSeriesStroke(1, new BasicStroke(3f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    XYPlot plot = new XYPlot(dataset, domain, range, renderer);
    domain.setAutoRange(true);
    domain.setLowerMargin(0.0);
    domain.setUpperMargin(0.0);
    domain.setTickLabelsVisible(true);
    range.setTickLabelsVisible(true);

    plot.setDomainGridlinesVisible(false);
    range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelsVisible(true);

    JFreeChart liveTweetAnalysisChart = new JFreeChart("Tweets Per Second", new Font("Tahoma", Font.BOLD, 24),
            plot, true);
    liveTweetAnalysisChart.setBorderVisible(false);
    liveTweetAnalysisChart.setBorderPaint(null);

    ChartUtilities.applyCurrentTheme(liveTweetAnalysisChart);

    domain.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    range.setTickMarksVisible(false);
    range.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
    domain.setTickMarksVisible(false);
    liveTweetAnalysisChart.setPadding(RectangleInsets.ZERO_INSETS);

    ChartPanel liveTweetAnalysisChartPanel = new ChartPanel(liveTweetAnalysisChart, true);
    liveTweetAnalysisChartPanel.setBorder(null);

    liveTweetsAnalysisPanel.add(liveTweetAnalysisChartPanel, BorderLayout.CENTER);
    liveTweetsAnalysisPanel.validate();
}