Example usage for org.jfree.chart.axis TickUnits add

List of usage examples for org.jfree.chart.axis TickUnits add

Introduction

In this page you can find the example usage for org.jfree.chart.axis TickUnits add.

Prototype

public void add(TickUnit unit) 

Source Link

Document

Adds a tick unit to the collection.

Usage

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

/**
 * Creates a sample chart.//from w  w w  .j a  v a  2  s . c  om
 * 
 * @return a sample chart.
 */
private JFreeChart createChart() {
    final XYDataset direction = createDirectionDataset(600);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true,
            true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // configure the range axis to display directions...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    final TickUnits units = new TickUnits();
    units.add(new NumberTickUnit(180.0, new CompassFormat()));
    units.add(new NumberTickUnit(90.0, new CompassFormat()));
    units.add(new NumberTickUnit(45.0, new CompassFormat()));
    units.add(new NumberTickUnit(22.5, new CompassFormat()));
    rangeAxis.setStandardTickUnits(units);

    // add the wind force with a secondary dataset/renderer/axis
    plot.setRangeAxis(rangeAxis);
    final XYItemRenderer renderer2 = new XYAreaRenderer();
    final ValueAxis axis2 = new NumberAxis("Force");
    axis2.setRange(0.0, 12.0);
    renderer2.setSeriesPaint(0, new Color(0, 0, 255, 128));
    plot.setDataset(1, createForceDataset(600));
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, axis2);
    plot.mapDatasetToRangeAxis(1, 1);

    return chart;
}

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

/**
 * Returns the chart.//w w w  .j  a va 2  s .co  m
 * 
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createWaterfallChart("Product Cost Breakdown", "Expense Category",
            "Cost Per Unit", dataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final ValueAxis rangeAxis = plot.getRangeAxis();

    // create a custom tick unit collection...
    final DecimalFormat formatter = new DecimalFormat("##,###");
    formatter.setNegativePrefix("(");
    formatter.setNegativeSuffix(")");
    final TickUnits standardUnits = new TickUnits();
    standardUnits.add(new NumberTickUnit(5, formatter));
    standardUnits.add(new NumberTickUnit(10, formatter));
    standardUnits.add(new NumberTickUnit(20, formatter));
    standardUnits.add(new NumberTickUnit(50, formatter));
    standardUnits.add(new NumberTickUnit(100, formatter));
    standardUnits.add(new NumberTickUnit(200, formatter));
    standardUnits.add(new NumberTickUnit(500, formatter));
    standardUnits.add(new NumberTickUnit(1000, formatter));
    standardUnits.add(new NumberTickUnit(2000, formatter));
    standardUnits.add(new NumberTickUnit(5000, formatter));
    rangeAxis.setStandardTickUnits(standardUnits);

    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    final DecimalFormat labelFormatter = new DecimalFormat("$##,###.00");
    labelFormatter.setNegativePrefix("(");
    labelFormatter.setNegativeSuffix(")");
    //        renderer.setLabelGenerator(
    //          new StandardCategoryLabelGenerator("{2}", labelFormatter)
    //    );
    renderer.setItemLabelsVisible(true);

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.demo.WaterfallChartDemo1.java

/**
 * Returns the chart.//w ww . j  ava2s  .  c o m
 * 
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createWaterfallChart(chartTitle, domainLabel, rangeLabel, dataset,
            PlotOrientation.VERTICAL, !legendPanelOn, true, false);
    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    ValueAxis rangeAxis = plot.getRangeAxis();

    // create a custom tick unit collection...
    DecimalFormat formatter = new DecimalFormat("##,###");
    formatter.setNegativePrefix("(");
    formatter.setNegativeSuffix(")");
    TickUnits standardUnits = new TickUnits();
    standardUnits.add(new NumberTickUnit(5, formatter));
    standardUnits.add(new NumberTickUnit(10, formatter));
    standardUnits.add(new NumberTickUnit(20, formatter));
    standardUnits.add(new NumberTickUnit(50, formatter));
    standardUnits.add(new NumberTickUnit(100, formatter));
    standardUnits.add(new NumberTickUnit(200, formatter));
    standardUnits.add(new NumberTickUnit(500, formatter));
    standardUnits.add(new NumberTickUnit(1000, formatter));
    standardUnits.add(new NumberTickUnit(2000, formatter));
    standardUnits.add(new NumberTickUnit(5000, formatter));
    rangeAxis.setStandardTickUnits(standardUnits);

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    DecimalFormat labelFormatter = new DecimalFormat("$##,###.00");
    labelFormatter.setNegativePrefix("(");
    labelFormatter.setNegativeSuffix(")");
    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", labelFormatter));
    renderer.setBaseItemLabelsVisible(true);

    setCategorySummary(dataset);
    return chart;
}

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

/**
 * Creates a chart.//from w w w .  ja va  2  s  . c o  m
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Weekly Data", "Date", "Value", dataset, true,
            true, false);

    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend sl = (StandardLegend) chart.getLegend();
    //      sl.setDisplaySeriesShapes(true);

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final XYItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof StandardXYItemRenderer) {
        final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
        rr.setPlotShapes(true);
        rr.setShapesFilled(true);
    }

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    final TickUnits standardUnits = new TickUnits();
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 1, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("MMM dd ''yy")));
    standardUnits.add(new DateTickUnit(DateTickUnit.MONTH, 1, new SimpleDateFormat("MMM ''yy")));
    axis.setStandardTickUnits(standardUnits);

    return chart;

}

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

/**
 * A demonstration application showing a high-low-open-close chart using a
 * segmented or non-segmented axis./*w  w  w .  j  a v a2 s.  c  o m*/
 *
 * @param title  the frame title.
 * @param useSegmentedAxis use a segmented axis for this demo?
 * @param timelineType Type of timeline to use: 1=Monday through Friday, 2=Intraday
 */
public SegmentedHighLowChartDemo(final String title, final boolean useSegmentedAxis, final int timelineType) {

    super(title);

    System.out.println("\nMaking SegmentedHighLowChartDemo(" + title + ")");

    // create a Calendar object with today's date at midnight
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    // create a timeline for the demo
    SegmentedTimeline timeline = null;
    switch (timelineType) {
    case 1:
        timeline = SegmentedTimeline.newMondayThroughFridayTimeline();
        break;

    case 2:
        timeline = SegmentedTimeline.newFifteenMinuteTimeline();

        final Calendar cal2 = (Calendar) cal.clone();
        cal2.add(Calendar.YEAR, 1);

        // add 1 year of baseTimeline's excluded segments (Saturdays and Sundays) as
        // exceptions of the intraday timeline
        timeline.addBaseTimelineExclusions(cal.getTime().getTime(), cal2.getTime().getTime());
        break;

    default:
        System.out.println("Invalid timelineType.");
        System.exit(1);
    }

    // create a data set that has data for trading days (Monday through Friday).
    final DefaultHighLowDataset dataset = DemoDatasetFactory.createSegmentedHighLowDataset(timeline,
            cal.getTime());

    final JFreeChart chart;
    if (useSegmentedAxis) {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, timeline, true);
    } else {
        chart = ChartFactory.createHighLowChart(title, "Time", "Value", dataset, true);
    }

    final DateAxis axis = (DateAxis) chart.getXYPlot().getDomainAxis();
    axis.setAutoRange(true);
    final TickUnits units = new TickUnits();
    units.add(new DateTickUnit(DateTickUnit.DAY, 1, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 2, DateTickUnit.HOUR, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 7, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 15, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    units.add(new DateTickUnit(DateTickUnit.DAY, 30, DateTickUnit.DAY, 1, new SimpleDateFormat("d-MMM")));
    axis.setStandardTickUnits(units);

    final NumberAxis vaxis = (NumberAxis) chart.getXYPlot().getRangeAxis();
    vaxis.setAutoRangeIncludesZero(false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    setContentPane(chartPanel);

}

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

/**
 * Returns the chart./*  ww  w .  jav a  2s  .  com*/
 *
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    final CategoryAxis xAxis = new CategoryAxis("Category");
    final NumberAxis yAxis = new NumberAxis("$ in Thousands");
    yAxis.setLowerMargin(0.10);
    yAxis.setUpperMargin(0.10);

    // create a custom tick unit collection...
    final DecimalFormat formatter = new DecimalFormat("##,###");
    formatter.setNegativePrefix("(");
    formatter.setNegativeSuffix(")");
    final TickUnits standardUnits = new TickUnits();
    standardUnits.add(new NumberTickUnit(200, formatter));
    standardUnits.add(new NumberTickUnit(500, formatter));
    standardUnits.add(new NumberTickUnit(1000, formatter));
    standardUnits.add(new NumberTickUnit(2000, formatter));
    standardUnits.add(new NumberTickUnit(5000, formatter));

    yAxis.setStandardTickUnits(standardUnits);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    final DecimalFormat labelFormatter = new DecimalFormat("##,###");
    labelFormatter.setNegativePrefix("(");
    labelFormatter.setNegativeSuffix(")");

    final WaterfallBarRenderer renderer = new WaterfallBarRenderer();
    //        renderer.setLabelGenerator(
    //          new StandardCategoryLabelGenerator("{2}", labelFormatter)
    //    );
    renderer.setItemLabelsVisible(Boolean.TRUE);

    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    final ValueMarker baseline = new ValueMarker(0.0);
    baseline.setPaint(Color.blue);
    baseline.setStroke(new BasicStroke(1.1f));
    plot.addRangeMarker(baseline, Layer.FOREGROUND);

    final JFreeChart chart = new JFreeChart("OM WaterFall Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:com.xilinx.virtex7.PowerChart.java

private void makeChart() {
    dataset = new DefaultCategoryDataset();
    chart = ChartFactory.createBarChart("", "Time Interval", "", dataset, PlotOrientation.HORIZONTAL, true,
            true, false);/*from  ww  w . j av a 2 s .  c  om*/

    TextTitle ttitle = new TextTitle(title, new Font(title, Font.BOLD, 15));
    ttitle.setPaint(Color.WHITE);
    chart.setTitle(ttitle);
    chart.setBackgroundPaint(bg);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    ValueAxis axis = plot.getRangeAxis();
    axis.setUpperBound(10.0);
    TickUnits tickUnits = new TickUnits();
    tickUnits.add(new NumberTickUnit(2));
    axis.setStandardTickUnits(tickUnits);
    axis.setLowerBound(0.0);
    axis.setTickLabelPaint(new Color(185, 185, 185));

    CategoryAxis caxis = plot.getDomainAxis();
    caxis.setTickLabelPaint(new Color(185, 185, 185));
    caxis.setLabelPaint(new Color(185, 185, 185));

    renderer.setItemMargin(0);
    renderer.setSeriesPaint(0, new Color(0x17, 0x7b, 0x7c));
    renderer.setSeriesPaint(1, new Color(0xa2, 0x45, 0x73));
    renderer.setSeriesPaint(2, new Color(0xff, 0x80, 0x40));
    renderer.setSeriesPaint(3, new Color(0x6f, 0x2c, 0x85));
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator("{0}:{2}", new DecimalFormat("0.000")));
    addDummy();
}

From source file:de.perdian.apps.dashboard.mvc.modules.jira.JiraController.java

@RequestMapping(value = "/jira/burndown/")
@ResponseBody//w w  w  .jav  a2s . com
JiraControllerResponse doBurndown(@ModelAttribute JiraControllerRequest controllerRequest) {

    BurndownDto burndownDto = this.getJiraService().loadBurndown(controllerRequest.getRapidViewId(),
            controllerRequest.getBurndownBasis(), controllerRequest.getStoryPointFieldName());

    // We want to have twenty lines at maximum, so let's adjust the steps
    // accordingly
    double maxSteps = 20;
    double incrementPerStep = burndownDto.getStoryPointsTotal() / maxSteps;
    int increment = (int) Math.max(1, Math.ceil(incrementPerStep));
    TickUnits rangeTickUnits = new TickUnits();
    for (int i = 0; i < burndownDto.getStoryPointsTotal(); i += increment) {
        rangeTickUnits.add(new NumberTickUnit(i + 1));
    }

    TickUnits domainTickUnits = new TickUnits();
    domainTickUnits.add(new NumberTickUnit(burndownDto.getDays().size() + 1));

    ChartCreator chartCreator = new ChartCreator(controllerRequest);
    chartCreator.setTitle(controllerRequest.getTitle());
    chartCreator.setDomainTickUnits(domainTickUnits);
    chartCreator.setRangeTickUnits(rangeTickUnits);
    chartCreator
            .addStrokeDefinition(new ChartStrokeDefinition(new BasicStroke(7f), chartCreator.getColor(), null));
    chartCreator.addStrokeDefinition(new ChartStrokeDefinition(null, null, false));
    chartCreator.addStrokeDefinition(new ChartStrokeDefinition(new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f), chartCreator.getColor(), null));
    chartCreator.setRangeAxisLabel(
            "worklog".equalsIgnoreCase(controllerRequest.getBurndownBasis()) ? "Worklog (Hours)"
                    : "Storypoints");

    JiraControllerResponse controllerResponse = new JiraControllerResponse();
    controllerResponse.setBurndown(burndownDto);
    controllerResponse.setImageContent(chartCreator.createChartAsImageContent(burndownDto.toDataset()));
    return controllerResponse;

}

From source file:com.xilinx.ultrascale.gui.BarCharts.java

License:asdf

public void upperBounds(int topVal) {
    CategoryPlot plot = chart.getCategoryPlot();
    //        BarRenderer renderer = (BarRenderer)plot.getRenderer();
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);/*ww  w .  j av  a 2  s  . com*/
    ValueAxis axis = plot.getRangeAxis();
    axis.setUpperBound(topVal);
    axis.setLowerBound(0.0);
    if (topVal == 32) {
        TickUnits tu = new TickUnits();
        tu.add(new NumberTickUnit(4));
        axis.setStandardTickUnits(tu);
    }

    //        axis.setAutoRangeMinimumSize(1.0);
    //        axis.setAutoRange(true);
    ////        axis.setLowerMargin(0);
    //        axis.setLowerMargin(0);
    //        axis.setUpperMargin(0.40);
    //        axis.setAutoRangeMinimumSize(1.0);
    //        axis.setDefaultAutoRange(new Range(0, 1000));
}

From source file:org.spf4j.perf.impl.chart.QuantizedXYZDatasetImpl.java

public TickUnits createYTickUnits() {
    TickUnits tu = new TickUnits();
    final List<ComparablePair<Quanta, Integer>> lquantas = this.getQuantas();
    tu.add(new QuantizedNumberTickUnit(1, lquantas));
    return tu;//  w w w  . j a  v a  2 s. c  o  m
}