Example usage for org.jfree.chart.axis NumberTickUnit NumberTickUnit

List of usage examples for org.jfree.chart.axis NumberTickUnit NumberTickUnit

Introduction

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

Prototype

public NumberTickUnit(double size) 

Source Link

Document

Creates a new number tick unit.

Usage

From source file:mrmc.chart.ROCCurvePlot.java

/**
 * Sole constructor. Creates a line plot display ROC curves
 * //from   w  ww  .  j  a  va 2s.  c om
 * @param title Title of the chart
 * @param xaxis x-axis label
 * @param yaxis y-axis label
 * @param treeMap Mapping of readers to a set of points defining an ROC curve
 */
public ROCCurvePlot(final String title, String xaxis, String yaxis, TreeMap<String, TreeSet<XYPair>> treeMap) {
    super(title);

    createDataset(treeMap);
    final JFreeChart chart = ChartFactory.createScatterPlot(title, xaxis, yaxis, seriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) chart.getPlot();
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    NumberAxis domain = (NumberAxis) xyplot.getDomainAxis();
    domain.setRange(0.00, 1.00);
    domain.setTickUnit(new NumberTickUnit(0.1));
    NumberAxis range = (NumberAxis) xyplot.getRangeAxis();
    range.setRange(0.00, 1.00);
    range.setTickUnit(new NumberTickUnit(0.1));
    renderer = new XYLineAndShapeRenderer();
    chart.getXYPlot().setRenderer(renderer);
    ChartPanel chartPanel = new ChartPanel(chart);

    JPanel readerSelect = new JPanel(new WrapLayout());
    readerSeriesBoxes = new ArrayList<JCheckBox>();

    for (String r : treeMap.keySet()) {
        JCheckBox aBox = new JCheckBox("" + r);
        aBox.setSelected(false);
        aBox.addItemListener(new SeriesSelectListener());
        hideSeries("" + r);
        readerSeriesBoxes.add(aBox);
        readerSelect.add(aBox);
    }

    renderer.setSeriesShapesVisible(seriesCollection.getSeriesIndex("Vertical Average"), false);
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Vertical Average"), new java.awt.BasicStroke(3f));
    renderer.setSeriesShapesVisible(seriesCollection.getSeriesIndex("Horizontal Average"), false);
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Horizontal Average"),
            new java.awt.BasicStroke(3f));
    renderer.setSeriesShapesVisible(seriesCollection.getSeriesIndex("Diagonal Average"), false);
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Diagonal Average"), new java.awt.BasicStroke(3f));
    renderer.setSeriesStroke(seriesCollection.getSeriesIndex("Pooled Average"), new java.awt.BasicStroke(3f));

    vert = new JCheckBox("Vertical Average");
    vert.setSelected(true);
    vert.addItemListener(new SeriesSelectListener());
    readerSelect.add(vert);
    horiz = new JCheckBox("Horizontal Average");
    horiz.setSelected(true);
    horiz.addItemListener(new SeriesSelectListener());
    readerSelect.add(horiz);
    diag = new JCheckBox("Diagonal Average");
    diag.setSelected(true);
    diag.addItemListener(new SeriesSelectListener());
    readerSelect.add(diag);
    pooled = new JCheckBox("Pooled Average");
    pooled.setSelected(true);
    pooled.addItemListener(new SeriesSelectListener());
    readerSelect.add(pooled);

    JCheckBox allReaders = new JCheckBox("Show Readers");
    allReaders.setSelected(false);
    allReaders.addItemListener(new ReadersSelectListener());
    readerSelect.add(allReaders);
    JCheckBox allAverages = new JCheckBox("Show Averages");
    allAverages.setSelected(true);
    allAverages.addItemListener(new AverageSelectListener());
    readerSelect.add(allAverages);

    chartPanel.setPreferredSize(new java.awt.Dimension(700, 700));
    this.add(chartPanel);
    this.add(readerSelect, BorderLayout.PAGE_END);

}

From source file:asl.util.PlotMaker2.java

public void writePlot(String fileName) {
    //System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle, fileName);

    File outputFile = new File(fileName);

    // Check that we will be able to output the file without problems and if not --> return
    if (!checkFileOut(outputFile)) {
        System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it "
                + " --> skip plot\n", fileName);
        return;/*from w w  w . j a  v a 2 s . c o  m*/
    }

    NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x = domain

    if (fileName.contains("nlnm") || fileName.contains("coher") || fileName.contains("stn")) { // NLNM or StationDeviation 
        horizontalAxis = new LogarithmicAxis("Period (sec)");
        horizontalAxis.setRange(new Range(1, 11000));
        horizontalAxis.setTickUnit(new NumberTickUnit(5.0));
    } else { // EventCompareSynthetics/StrongMotion
        horizontalAxis = new NumberAxis("Time (s)");
        double x[] = panels.get(0).getTraces().get(0).getxData();
        horizontalAxis.setRange(new Range(x[0], x[x.length - 1]));
    }

    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.setGap(15.);

    // Loop over (3) panels for this plot:

    for (Panel panel : panels) {

        NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y = range

        if (fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM or StationDeviation 
            verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB");
            verticalAxis.setRange(new Range(-190, -95));
            verticalAxis.setTickUnit(new NumberTickUnit(5.0));
        } else if (fileName.contains("coher")) { // Coherence
            verticalAxis = new NumberAxis("Coherence, Gamma");
            verticalAxis.setRange(new Range(0, 1.2));
            verticalAxis.setTickUnit(new NumberTickUnit(0.1));
        } else { // EventCompareSynthetics/StrongMotion
            verticalAxis = new NumberAxis("Displacement (m)");
        }

        Font fontPlain = new Font("Verdana", Font.PLAIN, 14);
        Font fontBold = new Font("Verdana", Font.BOLD, 18);
        verticalAxis.setLabelFont(fontBold);
        verticalAxis.setTickLabelFont(fontPlain);
        horizontalAxis.setLabelFont(fontBold);
        horizontalAxis.setTickLabelFont(fontPlain);

        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, verticalAxis, renderer);
        xyplot.setDomainGridlinesVisible(true);
        xyplot.setRangeGridlinesVisible(true);
        xyplot.setRangeGridlinePaint(Color.black);
        xyplot.setDomainGridlinePaint(Color.black);

        // Plot each trace on this panel:
        int iTrace = 0;
        for (Trace trace : panel.getTraces()) {

            XYSeries series = new XYSeries(trace.getName());

            double xdata[] = trace.getxData();
            double ydata[] = trace.getyData();
            for (int k = 0; k < xdata.length; k++) {
                series.add(xdata[k], ydata[k]);
            }

            renderer.setSeriesPaint(iTrace, trace.getColor());
            renderer.setSeriesStroke(iTrace, trace.getStroke());
            renderer.setSeriesLinesVisible(iTrace, true);
            renderer.setSeriesShapesVisible(iTrace, false);

            seriesCollection.addSeries(series);

            iTrace++;
        }

        // Add Annotations for each trace - This is done in a separate loop so that
        //                      the upper/lower limits for this panel will be known
        double xmin = horizontalAxis.getRange().getLowerBound();
        double xmax = horizontalAxis.getRange().getUpperBound();
        double ymin = verticalAxis.getRange().getLowerBound();
        double ymax = verticalAxis.getRange().getUpperBound();
        double delX = Math.abs(xmax - xmin);
        double delY = Math.abs(ymax - ymin);

        // Annotation (x,y) in normalized units - where upper-right corner = (1,1)
        double xAnn = 0.97; // Right center coords of the trace name (e.g., "00-LHZ")
        double yAnn = 0.95;

        double yOff = 0.05; // Vertical distance between different trace legends

        iTrace = 0;
        for (Trace trace : panel.getTraces()) {
            if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM")) {
                // x1 > x2 > x3, e.g.:
                //  o-------o   00-LHZ
                //  x3     x2       x1

                double scale = .01; // Controls distance between trace label and line segment
                double xL = .04; // Length of trace line segment in legend

                double xAnn2 = xAnn - scale * trace.getName().length();
                double xAnn3 = xAnn - scale * trace.getName().length() - xL;

                double x1 = xAnn * delX + xmin; // Right hand x-coord of text in range units
                double x2 = xAnn2 * delX + xmin; // x-coord of line segment end in range units
                double x3 = xAnn3 * delX + xmin; // x-coord of line segment end in range units

                double y = (yAnn - (iTrace * yOff)) * delY + ymin;

                if (horizontalAxis instanceof LogarithmicAxis) {
                    double logMin = Math.log10(xmin);
                    double logMax = Math.log10(xmax);
                    delX = logMax - logMin;
                    x1 = Math.pow(10, xAnn * delX + logMin);
                    x2 = Math.pow(10, xAnn2 * delX + logMin);
                    x3 = Math.pow(10, xAnn3 * delX + logMin);
                }
                xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor()));
                XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y);
                xyText.setFont(new Font("Verdana", Font.BOLD, 18));
                xyText.setTextAnchor(TextAnchor.CENTER_RIGHT);
                xyplot.addAnnotation(xyText);
            }
            iTrace++;
        }

        combinedPlot.add(xyplot, 1);

    } // panel

    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18)));
    chart.removeLegend();

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");

    }

}

From source file:com.sixrr.metrics.ui.charts.HistogramDialog.java

private JFreeChart createChart(IntervalXYDataset dataset, boolean isIntegral) {
    final String title = getTitle();
    final NumberAxis xAxis = new NumberAxis();
    if (isIntegral) {
        xAxis.setTickUnit(new NumberTickUnit(1.0));
    }//from   w  w w  .  j a va 2  s.  co  m
    if (metricType == MetricType.Ratio || metricType == MetricType.RecursiveRatio) {
        xAxis.setNumberFormatOverride(new PercentFormatter());
    }

    final XYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator();

    final XYItemRenderer renderer = new XYBarRenderer();
    renderer.setToolTipGenerator(tooltipGenerator);
    renderer.setURLGenerator(null);

    final ValueAxis yAxis = new NumberAxis();
    final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    plot.setRenderer(renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);

    return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true);
}

From source file:no.met.jtimeseries.marinogram.MarinogramPressurePlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotPressure) {
    ChartPlotter plotter = null;//from ww w  .  j av  a  2  s.com
    if (plotPressure) {
        plotter = new ChartPlotter();
        // default setting
        plotter.setHeight(this.getHeight());
        plotter.setWidth(this.getWidth());
        plotter.setPlotDefaultProperties("", "");
        NumberPhenomenon pressure = getLocationForecastDataModel()
                .getPhenomenen(PhenomenonName.Pressure.toString(), NumberPhenomenon.class);
        List<Date> shortTermTime = pressure.getTime();
        Color pressureColor = new Color(11, 164, 42);

        PlotStyle.Builder pressureStyleBuilder = new PlotStyle.Builder(
                messages.getString("parameter.pressure") + " (hPa)");
        PlotStyle plotStyle = pressureStyleBuilder.spline(SplineStyle.HYBRID).ticks(4).difference(50.0d)
                .seriesColor(pressureColor).labelColor(pressureColor).build();
        plotter.addLineChart(TimeBase.SECOND, pressure, plotStyle);
        //plotter.formalizeRangeAxisWithMargins(plotter.getRangeAxisIndex() - 1, 950, 1050);

        double tick = (pressure.getMaxValue() - pressure.getMinValue()) / 2;
        tick = Math.ceil(tick / 10) * 10;
        double lowBound = Math.floor(pressure.getMinValue() / (tick)) * (tick);
        lowBound = lowBound - tick / 2;
        double upperBound = lowBound + tick * 4;

        //replicate the range axis 
        NumberAxis referenceAxis = (NumberAxis) plotter.getPlot().getRangeAxis();
        referenceAxis.setTickUnit(new NumberTickUnit(tick));
        referenceAxis.setLowerBound(lowBound);
        referenceAxis.setUpperBound(upperBound);
        NumberAxis numberAxis = new NumberAxis();
        numberAxis.setLabelPaint(pressureColor);
        numberAxis.setTickLabelPaint(referenceAxis.getTickLabelPaint());
        //numberAxis.setLowerMargin(ChartPlotter.LOWER_PLOT_MARGIN);
        numberAxis.setRange(referenceAxis.getLowerBound(), referenceAxis.getUpperBound());
        numberAxis.setTickUnit(referenceAxis.getTickUnit());
        //numberAxis.setRangeWithMargins(950, 1050);
        plotter.getPlot().setRangeAxis(1, numberAxis);

        //first set domain date format and then add hour based domain grid lines
        //TODO: wrap this inside the addHourBasedDomainGridLines for simplicity
        Date minDate = shortTermTime.get(0);
        Date maxDate = shortTermTime.get(shortTermTime.size() >= 48 ? 48 : shortTermTime.size() - 1);
        plotter.setDomainRange(minDate, maxDate);
        plotter.setDomainDateFormat(timezone, "HH");
        plotter.getPlot().setOutlineVisible(true);
        //set domain range after (must) plot all the data
        plotter.addHourBasedDomainGridLines();
        //invisible domain axis
        plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);
        // add markers
        plotter.addDomainMarkers(shortTermTime, timezone, locale);

    }

    return plotter.getPlot();

}

From source file:asl.plotmaker.PlotMaker2.java

public void writePlot(String fileName) {
    // System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle,
    // fileName);

    File outputFile = new File(fileName);

    // Check that we will be able to output the file without problems and if
    // not --> return
    if (!checkFileOut(outputFile)) {
        // System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it "
        // + " --> skip plot\n", fileName );
        logger.warn("== Request to output plot=[{}] but we are unable to create it " + " --> skip plot\n",
                fileName);/*from   w ww . j  a  v a 2  s .  com*/
        return;
    }

    NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x =
    // domain

    if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("coher")
            || fileName.contains("stn")) { // NLNM or StationDeviation
        horizontalAxis = new LogarithmicAxis("Period (sec)");
        horizontalAxis.setRange(new Range(1, 11000));
        horizontalAxis.setTickUnit(new NumberTickUnit(5.0));
    } else { // EventCompareSynthetics/StrongMotion
        horizontalAxis = new NumberAxis("Time (s)");
        double x[] = panels.get(0).getTraces().get(0).getxData();
        horizontalAxis.setRange(new Range(x[0], x[x.length - 1]));
    }

    CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis);
    combinedPlot.setGap(15.);

    // Loop over (3) panels for this plot:

    for (Panel panel : panels) {

        NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y =
        // range

        if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM
            // or
            // StationDeviation
            verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB");
            verticalAxis.setRange(new Range(-190, -80));
            verticalAxis.setTickUnit(new NumberTickUnit(5.0));
        } else if (fileName.contains("coher")) { // Coherence
            verticalAxis = new NumberAxis("Coherence, Gamma");
            verticalAxis.setRange(new Range(0, 1.2));
            verticalAxis.setTickUnit(new NumberTickUnit(0.1));
        } else { // EventCompareSynthetics/StrongMotion
            verticalAxis = new NumberAxis("Displacement (m)");
        }

        Font fontPlain = new Font("Verdana", Font.PLAIN, 14);
        Font fontBold = new Font("Verdana", Font.BOLD, 18);
        verticalAxis.setLabelFont(fontBold);
        verticalAxis.setTickLabelFont(fontPlain);
        horizontalAxis.setLabelFont(fontBold);
        horizontalAxis.setTickLabelFont(fontPlain);

        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYDotRenderer renderer = new XYDotRenderer();
        XYPlot xyplot = new XYPlot(seriesCollection, horizontalAxis, verticalAxis, renderer);
        xyplot.setDomainGridlinesVisible(true);
        xyplot.setRangeGridlinesVisible(true);
        xyplot.setRangeGridlinePaint(Color.black);
        xyplot.setDomainGridlinePaint(Color.black);

        // Plot each trace on this panel:
        int iTrace = 0;
        for (Trace trace : panel.getTraces()) {

            XYSeries series = new XYSeries(trace.getName());

            double xdata[] = trace.getxData();
            double ydata[] = trace.getyData();
            for (int k = 0; k < xdata.length; k++) {
                series.add(xdata[k], ydata[k]);
            }

            renderer.setSeriesPaint(iTrace, trace.getColor());
            renderer.setSeriesStroke(iTrace, trace.getStroke());

            seriesCollection.addSeries(series);

            iTrace++;
        }

        // Add Annotations for each trace - This is done in a separate loop
        // so that
        // the upper/lower limits for this panel will be known
        double xmin = horizontalAxis.getRange().getLowerBound();
        double xmax = horizontalAxis.getRange().getUpperBound();
        double ymin = verticalAxis.getRange().getLowerBound();
        double ymax = verticalAxis.getRange().getUpperBound();
        double delX = Math.abs(xmax - xmin);
        double delY = Math.abs(ymax - ymin);

        // Annotation (x,y) in normalized units - where upper-right corner =
        // (1,1)
        double xAnn = 0.97; // Right center coords of the trace name (e.g.,
        // "00-LHZ")
        double yAnn = 0.95;

        double yOff = 0.05; // Vertical distance between different trace
        // legends

        iTrace = 0;
        for (Trace trace : panel.getTraces()) {
            if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM")
                    && !trace.getName().contains("ALNM")) {
                // x1 > x2 > x3, e.g.:
                // o-------o 00-LHZ
                // x3 x2 x1

                double scale = .01; // Controls distance between trace label
                // and line segment
                double xL = .04; // Length of trace line segment in legend

                double xAnn2 = xAnn - scale * trace.getName().length();
                double xAnn3 = xAnn - scale * trace.getName().length() - xL;

                double x1 = xAnn * delX + xmin; // Right hand x-coord of
                // text in range units
                double x2 = xAnn2 * delX + xmin; // x-coord of line segment
                // end in range units
                double x3 = xAnn3 * delX + xmin; // x-coord of line segment
                // end in range units

                double y = (yAnn - (iTrace * yOff)) * delY + ymin;

                if (horizontalAxis instanceof LogarithmicAxis) {
                    double logMin = Math.log10(xmin);
                    double logMax = Math.log10(xmax);
                    delX = logMax - logMin;
                    x1 = Math.pow(10, xAnn * delX + logMin);
                    x2 = Math.pow(10, xAnn2 * delX + logMin);
                    x3 = Math.pow(10, xAnn3 * delX + logMin);
                }
                xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor()));
                XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y);
                xyText.setFont(new Font("Verdana", Font.BOLD, 18));
                xyText.setTextAnchor(TextAnchor.CENTER_RIGHT);
                xyplot.addAnnotation(xyText);
            }
            iTrace++;
        }

        combinedPlot.add(xyplot, 1);

    } // panel

    final JFreeChart chart = new JFreeChart(combinedPlot);
    chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18)));
    chart.removeLegend();

    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400);
    } catch (IOException e) {
        // System.err.println("Problem occurred creating chart.");
        logger.error("IOException:", e);
    }

}

From source file:CargarEntrenamiento.grafica2.java

private void configurarRangeAxis(NumberAxis rangeAxis) {
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setTickUnit(new NumberTickUnit(2));
    rangeAxis.setRange(0, 100);//  w  w w.j a  v  a 2 s  .  c  om
}

From source file:org.jfree.experimental.chart.axis.LogAxis.java

/**
 * Creates a new <code>LogAxis</code> with the given label.
 * /* w  ww .  j a  v a  2  s . com*/
 * @param label  the axis label (<code>null</code> permitted).
 */
public LogAxis(String label) {
    super(label, NumberAxis.createIntegerTickUnits());
    setDefaultAutoRange(new Range(0.01, 1.0));
    this.tickUnit = new NumberTickUnit(1.0);
    this.minorTickCount = 10;
    this.setTickMarksVisible(false);
}

From source file:adapters.AxisAdapter.java

/**
 * Create a new <TT>AxisAdapter</TT> instance from an existing <TT>NumberAxis</TT>
 *    instance with vertical (<SPAN CLASS="MATH"><I>y</I></SPAN>-axis) or horizontal (<SPAN CLASS="MATH"><I>x</I></SPAN>-axis) orientation.
 *
 * @param inAxis NumberAxis instance associated to the new variable.
 *
 *    @param orientation axis direction, horizontal or vertical
 *
 *//*from  ww  w  .  j  a  va 2 s. co  m*/
public AxisAdapter(NumberAxis inAxis, boolean orientation) {
    this.axis = inAxis;
    this.orientation = orientation;
    this.labelsFlag = false;
    this.labelsValue = null;
    this.labelsName = null;
    inAxis.setAutoRangeIncludesZero(false);
    inAxis.setLowerMargin(0);
    inAxis.setUpperMargin(0);
    axis.setTickUnit(new NumberTickUnit(computeAutoTickValue()));
}

From source file:org.mwc.asset.netasset2.sensor2.VSensor.java

/**
 * Create the composite./* w  ww .  j a  v  a 2 s  .  c o  m*/
 * 
 * @param parent
 * @param style
 */
public VSensor(final Composite parent, final int style) {
    super(parent, style);
    setLayout(new BorderLayout(0, 0));

    final ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(BorderLayout.NORTH);

    // ToolItem testBtn = new ToolItem(toolBar, SWT.NONE);
    // testBtn.setText("Test 1");
    // testBtn.addSelectionListener(new SelectionAdapter()
    // {
    //
    // @Override
    // public void widgetSelected(SelectionEvent e)
    // {
    // doTest();
    // }
    // });

    final ToolItem tltmDropdownItem = new ToolItem(toolBar, SWT.DROP_DOWN);
    tltmDropdownItem.setText("Visible period");
    final DropdownSelectionListener drops = new DropdownSelectionListener(tltmDropdownItem);
    drops.add("5 Mins", 5 * 60);
    drops.add("15 Mins", 15 * 60);
    drops.add("60 Mins", 60 * 60);
    drops.add("All data", 0);
    tltmDropdownItem.addSelectionListener(drops);

    final Composite sashForm = new Composite(this, SWT.EMBEDDED);

    // now we need a Swing object to put our chart into
    final Frame _plotControl = SWT_AWT.new_Frame(sashForm);

    // the y axis is common to hi & lo res. Format it here
    final NumberAxis yAxis = new NumberAxis("Degs");
    //   yAxis.setRange(0, 360);
    yAxis.setAutoRange(true);
    yAxis.setTickUnit(new NumberTickUnit(45));

    // create a date-formatting axis
    _dateAxis = new RelativeDateAxis();
    _dateAxis.setStandardTickUnits(DateAxisEditor.createStandardDateTickUnitsAsTickUnits());
    _dateAxis.setAutoRange(true);

    final XYItemRenderer theRenderer = new XYShapeRenderer();

    _thePlot = new XYPlot(null, _dateAxis, yAxis, theRenderer);
    _thePlot.setOrientation(PlotOrientation.HORIZONTAL);
    _thePlot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    _thePlot.setBackgroundPaint(Color.BLACK);
    theRenderer.setPlot(_thePlot);

    _dateAxis.setLabelPaint(Color.GREEN);
    _dateAxis.setTickLabelPaint(Color.GREEN);
    _dateAxis.setAxisLinePaint(Color.GREEN);

    yAxis.setLabelPaint(Color.GREEN);
    yAxis.setTickLabelPaint(Color.GREEN);

    _thePlotArea = new JFreeChart(null, _thePlot);
    _thePlotArea.setBackgroundPaint(Color.BLACK);
    _thePlotArea.setBorderPaint(Color.BLACK);

    // set the color of the area surrounding the plot
    // - naah, don't bother. leave it in the application background color.

    // ////////////////////////////////////////////////
    // put the holder into one of our special items
    // ////////////////////////////////////////////////
    _chartInPanel = new ChartPanel(_thePlotArea, true);

    _plotControl.add(_chartInPanel);

}

From source file:com.stableapps.anglewraparounddemo.AngleWrapDemoMain.java

/**
 * Creates a sample chart.//  w w  w .j  a v  a  2  s.  com
 *
 * @return a sample chart.
 */
private JFreeChart createChart() {
    final XYDataset direction = createAngleDataset(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 provide a fix set of TickUnits depending on size of chart
    NumberAxis rangeAxis = new NumberAxis() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public NumberTickUnit getTickUnit() {
            NumberTickUnit tickUnit = super.getTickUnit();
            if (tickUnit.getSize() < 15) {
                return tickUnit;
            } else if (tickUnit.getSize() < 45) {
                return new NumberTickUnit(45);
            } else if (tickUnit.getSize() < 90) {
                return new NumberTickUnit(90);
            } else if (tickUnit.getSize() < 180) {
                return new NumberTickUnit(180);
            } else {
                return new NumberTickUnit(360);
            }
        }

    };
    rangeAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(rangeAxis);

    final OverflowCondition overflowCondition = new OverflowCondition() {
        @Override
        public boolean isOverflow(double y0, double x0, double y1, double x1) {
            return Math.abs(y1 - y0) > 180;
        }
    };
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        /**
         *
         */
        private static final long serialVersionUID = 1L;
        double min = 0;
        double max = 360;
        LinearInterpolator interpolator = new LinearInterpolator();

        @Override
        protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset,
                int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea) {
            if (item == 0) {
                return;
            }

            // get the data point...
            double x1 = dataset.getXValue(series, item);
            double y1 = dataset.getYValue(series, item);
            if (Double.isNaN(y1) || Double.isNaN(x1)) {
                return;
            }

            double x0 = dataset.getXValue(series, item - 1);
            double y0 = dataset.getYValue(series, item - 1);
            if (Double.isNaN(y0) || Double.isNaN(x0)) {
                return;
            }

            if (overflowCondition.isOverflow(y0, x0, y1, x1)) {
                boolean overflowAtMax = y1 < y0;
                if (overflowAtMax) {
                    LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) },
                            new double[] { x0, x1 });
                    double xmid = lf.value(max);
                    drawPrimaryLine(state, g2, plot, x0, y0, xmid, max, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                    drawPrimaryLine(state, g2, plot, xmid, min, x1, y1, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                } else {
                    LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 },
                            new double[] { x1, x0 });
                    double xmid = lf.value(min);
                    drawPrimaryLine(state, g2, plot, x0, y0, xmid, min, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                    drawPrimaryLine(state, g2, plot, xmid, max, x1, y1, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                }
            } else {
                drawPrimaryLine(state, g2, plot, x0, y0, x1, y1, pass, series, item, domainAxis, rangeAxis,
                        dataArea);
            }

        }

        private void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double x0,
                double y0, double x1, double y1, int pass, int series, int item, ValueAxis domainAxis,
                ValueAxis rangeAxis, Rectangle2D dataArea) {
            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
            double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
            double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
            double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
            // only draw if we have good values
            if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                    || Double.isNaN(transY1)) {
                return;
            }
            PlotOrientation orientation = plot.getOrientation();
            boolean visible;
            if (orientation == PlotOrientation.HORIZONTAL) {
                state.workingLine.setLine(transY0, transX0, transY1, transX1);
            } else if (orientation == PlotOrientation.VERTICAL) {
                state.workingLine.setLine(transX0, transY0, transX1, transY1);
            }
            visible = LineUtilities.clipLine(state.workingLine, dataArea);
            if (visible) {
                drawFirstPassShape(g2, pass, series, item, state.workingLine);
            }
        }

        @Override
        protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot,
                XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea) {

            // get the data point...
            State s = (State) state;
            try {
                double x1 = dataset.getXValue(series, item);
                double y1 = dataset.getYValue(series, item);
                if (Double.isNaN(x1) && Double.isNaN(y1)) {
                    s.setLastPointGood(false);
                    return;
                }

                if (!s.isLastPointGood()) {
                    ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                    s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                    s.setLastPointGood(true);
                    return;
                }

                double x0 = dataset.getXValue(series, item - 1);
                double y0 = dataset.getYValue(series, item - 1);
                if (overflowCondition.isOverflow(y0, x0, y1, x1)) {
                    boolean overflowAtMax = y1 < y0;
                    if (overflowAtMax) {
                        LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) },
                                new double[] { x0, x1 });
                        double xmid = lf.value(max);
                        ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid,
                                max);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, min);
                        s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                    } else {
                        LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 },
                                new double[] { x1, x0 });
                        double xmid = lf.value(min);
                        ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid,
                                min);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, max);
                        s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                    }
                } else {
                    ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                    s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                }

                s.setLastPointGood(true);
            } finally {
                // if this is the last item, draw the path ...
                if (item == s.getLastItemIndex()) {
                    // draw path
                    drawFirstPassShape(g2, pass, series, item, s.seriesPath);
                }

            }
        }

        private ImmutablePair<Float, Float> translate(XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea, double x, double y) {
            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX1 = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double transY1 = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
            // update path to reflect latest point
            float xtrans = (float) transX1;
            float ytrans = (float) transY1;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                xtrans = (float) transY1;
                ytrans = (float) transX1;
            }
            return new ImmutablePair<>(xtrans, ytrans);
        }
    };
    renderer.setDrawSeriesLineAsPath(true);
    plot.setRenderer(0, renderer);

    return chart;
}