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

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

Introduction

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

Prototype

public void setVisible(boolean flag) 

Source Link

Document

Sets a flag that controls whether or not the axis is visible and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.jfree.chart.demo.CompareToPreviousYearDemo.java

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);/*ww w.ja  v a 2  s . c o  m*/
    xyplot.setRangePannable(true);
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java

private static JFreeChart createChart(final SecurityNode node) {
    Objects.requireNonNull(node);

    final List<SecurityHistoryNode> hNodes = node.getHistoryNodes();
    final Date max = DateUtils.asDate(hNodes.get(hNodes.size() - 1).getLocalDate());
    final Date min = DateUtils.asDate(hNodes.get(0).getLocalDate());

    final DateAxis timeAxis = new DateAxis(null);
    timeAxis.setVisible(false);
    timeAxis.setAutoRange(false);// ww w  .j a v a  2  s  .co m
    timeAxis.setRange(min, max);

    final NumberAxis valueAxis = new NumberAxis(null);
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setVisible(false);

    final XYAreaRenderer renderer = new XYAreaRenderer();
    renderer.setBaseToolTipGenerator(new SecurityItemLabelGenerator(node));
    renderer.setOutline(true);
    renderer.setSeriesPaint(0, new Color(225, 247, 223));

    final XYPlot plot = new XYPlot(null, timeAxis, valueAxis, renderer);

    final List<List<SecurityHistoryNode>> groups = node.getHistoryNodeGroupsBySplits();

    for (int i = 0; i < groups.size(); i++) {
        int size = groups.get(i).size();

        Date[] date = new Date[size];
        double[] high = new double[size];
        double[] low = new double[size];
        double[] open = new double[size];
        double[] close = new double[size];
        double[] volume = new double[size];

        for (int j = 0; j < size; j++) {
            final SecurityHistoryNode hNode = groups.get(i).get(j);

            date[j] = DateUtils.asDate(hNode.getLocalDate());
            high[j] = hNode.getAdjustedHigh().doubleValue();
            low[j] = hNode.getAdjustedLow().doubleValue();
            open[j] = hNode.getAdjustedPrice().doubleValue();
            close[j] = hNode.getAdjustedPrice().doubleValue();
            volume[j] = hNode.getVolume();
        }

        final AbstractXYDataset data = new DefaultHighLowDataset(node.getDescription() + i, date, high, low,
                open, close, volume);
        plot.setDataset(i, data);
    }

    plot.setInsets(new RectangleInsets(1, 1, 1, 1));

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

    return chart;
}

From source file:org.projectforge.statistics.TimesheetDisciplineChartBuilder.java

private JFreeChart create(final TimeSeries series1, final TimeSeries series2, final Shape shape,
        final Stroke stroke, final boolean showAxisValues, final String valueAxisUnitKey) {
    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series1);//w  ww .j  a  v a  2s . c  o  m
    dataset.addSeries(series2);
    final JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL,
            true, true, false);

    final XYDifferenceRenderer renderer = new XYDifferenceRenderer(new Color(238, 176, 176),
            new Color(135, 206, 112), true);
    renderer.setSeriesPaint(0, new Color(222, 23, 33));
    renderer.setSeriesPaint(1, new Color(64, 169, 59));
    if (shape != null) {
        renderer.setSeriesShape(0, shape);
        renderer.setSeriesShape(1, shape);
    } else {
        final Shape none = new Rectangle();
        renderer.setSeriesShape(0, none);
        renderer.setSeriesShape(1, none);
    }
    renderer.setSeriesStroke(0, stroke);
    renderer.setSeriesStroke(1, stroke);
    renderer.setSeriesVisibleInLegend(0, false);
    renderer.setSeriesVisibleInLegend(1, false);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    final DateAxis xAxis = new DateAxis();
    xAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setVisible(showAxisValues);
    plot.setDomainAxis(xAxis);
    final NumberAxis yAxis;
    if (showAxisValues == true) {
        yAxis = new NumberAxis(PFUserContext.getLocalizedString(valueAxisUnitKey));
    } else {
        yAxis = new NumberAxis();
    }
    yAxis.setVisible(showAxisValues);
    plot.setRangeAxis(yAxis);
    plot.setOutlineVisible(false);
    return chart;
}

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);//  ww  w .  j a  v a2 s  .  c  o  m
    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.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a simple Time Axis./*from w ww . 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;
}