Example usage for org.jfree.chart.axis NumberAxis setNumberFormatOverride

List of usage examples for org.jfree.chart.axis NumberAxis setNumberFormatOverride

Introduction

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

Prototype

public void setNumberFormatOverride(NumberFormat formatter) 

Source Link

Document

Sets the number format override.

Usage

From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotWindow.java

public IntensityPlotWindow(ParameterSet parameters) {

    PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue()
            .getMatchingPeakLists()[0];/*w  w  w  . j  ava  2  s.  com*/

    String title = "Intensity plot [" + peakList + "]";
    String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString();
    String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString();

    // create dataset
    dataset = new IntensityPlotDataset(parameters);

    // create new JFreeChart
    logger.finest("Creating new chart instance");
    Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue();
    boolean isCombo = (xAxisValueSource instanceof ParameterWrapper)
            && (!(((ParameterWrapper) xAxisValueSource).getParameter() instanceof DoubleParameter));
    if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) {

        chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();

        // set renderer
        StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true);
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

        CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    } else {

        chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);

        XYPlot plot = (XYPlot) chart.getPlot();

        XYErrorRenderer renderer = new XYErrorRenderer();
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

    }

    chart.setBackgroundPaint(Color.white);

    // create chart JPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);

    IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this);
    add(toolBar, BorderLayout.EAST);

    // disable maximum size (we don't want scaling)
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    // set title properties
    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    LegendTitle legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setBorder(0, 0, 0, 0);

    Plot plot = chart.getPlot();

    // set shape provider
    IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier();
    plot.setDrawingSupplier(shapeSupplier);

    // set y axis properties
    NumberAxis yAxis;
    if (plot instanceof CategoryPlot)
        yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis();
    else
        yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis();
    NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat();
    if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT)
        yAxisFormat = MZmineCore.getConfiguration().getRTFormat();
    yAxis.setNumberFormatOverride(yAxisFormat);

    setTitle(title);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBackground(Color.white);

    // Add the Windows menu
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(new WindowsMenu());
    setJMenuBar(menuBar);

    pack();

    // get the window settings parameter
    ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(IntensityPlotModule.class);
    WindowSettingsParameter settings = paramSet.getParameter(IntensityPlotParameters.windowSettings);

    // update the window and listen for changes
    settings.applySettingsToWindow(this);
    this.addComponentListener(settings);

}

From source file:stockit.ClientFrame.java

private void createChart() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int row = StockInfoTable.getSelectedRow();
    if (row != -1) {
        //dataset.setValue(, "", table.getValueAt(0,1).toString());
        String selectedStock = StockInfoTable.getValueAt(row, 0).toString();
        try {//from   ww w .j ava 2 s  .c o  m
            DBConnection dbcon = new DBConnection();
            dbcon.establishConnection();
            Statement stmt = dbcon.con.createStatement();
            ResultSet rs = stmt
                    .executeQuery("Select stock_daily_performance.Closing_Price, stock_daily_performance.Date\n"
                            + "FROM stock_daily_performance, stock\n"
                            + "WHERE stock_daily_performance.StockID = stock.StockID AND stock.StockID = '"
                            + selectedStock + "'" + "AND Date IN\n" + "( Select * from\n" + "(\n"
                            + "SELECT Date \n" + "FROM stock_daily_performance \n"
                            + "WHERE StockID = stockID \n" + "ORDER BY Date ASC\n" + ") temp_table)\n"
                            + "            ");

            while (rs.next()) {

                String formattedDate = rs.getString("Date");
                int closing_price = rs.getInt("Closing_Price");
                dataset.setValue(closing_price, "value", formattedDate);

            }
            dbcon.con.close();
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
        String stockName = StockInfoTable.getValueAt(row, 1).toString();
        JFreeChart chart = ChartFactory.createBarChart3D(stockName + " Stock Performance", "Date", "Value",
                dataset, PlotOrientation.VERTICAL, false, false, false);

        Color c = new Color(240, 240, 240, 0);
        chart.setBackgroundPaint(c);
        CategoryPlot catPlot = chart.getCategoryPlot();
        catPlot.setRangeGridlinePaint(Color.BLACK);
        //set interval of Y-axis ticks (tick every 5 units)
        NumberAxis yAxis = (NumberAxis) catPlot.getRangeAxis();
        yAxis.setTickUnit(new NumberTickUnit(5));

        //set y-axis labels as currency types ($)
        NumberFormat currency = NumberFormat.getCurrencyInstance();
        yAxis.setNumberFormatOverride(currency);

        //setting number of lines an x-axis label is displayed on
        CategoryAxis categoryAxis = catPlot.getDomainAxis();
        categoryAxis.setMaximumCategoryLabelLines(4);
        ChartContainer.setLayout(new java.awt.BorderLayout());
        ChartPanel chartPanel = new ChartPanel(chart);
        ChartContainer.removeAll();
        ChartContainer.add(chartPanel, BorderLayout.CENTER);
        ChartContainer.validate();
        ChartContainer.repaint();
    }
}

From source file:org.paxle.tools.charts.impl.gui.ChartServlet.java

private JFreeChart createIndexChart() {
    // init Time-Series
    TimeSeries indexSizeSeries = new TimeSeries("Index Size", Minute.class);
    indexSizeSeries.setMaximumItemAge(24 * 60);
    this.seriesMap.put(TSERIES_INDEX_SIZE, indexSizeSeries);

    // init chart
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, "Time", "#Docs",
            new TimeSeriesCollection(indexSizeSeries), true, false, false);

    XYPlot plot = chart.getXYPlot();/*w  ww . ja  v a 2 s  .c  o m*/

    final TimeSeriesCollection linksDataset = new TimeSeriesCollection();

    TimeSeries totalLinksSeries = new TimeSeries("Total URI", Minute.class);
    totalLinksSeries.setMaximumItemAge(24 * 60);
    linksDataset.addSeries(totalLinksSeries);
    this.seriesMap.put(TSERIES_CMD_SIZE_TOTAL, totalLinksSeries);

    TimeSeries enqueuedLinksSeries = new TimeSeries("Enqueued URI", Minute.class);
    enqueuedLinksSeries.setMaximumItemAge(24 * 60);
    linksDataset.addSeries(enqueuedLinksSeries);
    this.seriesMap.put(TSERIES_CMD_SIZE_ENQUEUD, enqueuedLinksSeries);

    NumberAxis axis2 = new NumberAxis("#Links");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setNumberFormatOverride(new DecimalFormat("#,##0"));
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, linksDataset);
    plot.setRenderer(1, new StandardXYItemRenderer());
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis axis1 = (NumberAxis) plot.getRangeAxis(0);
    axis1.setNumberFormatOverride(new DecimalFormat("#,##0"));

    // change axis date format
    ((DateAxis) plot.getDomainAxis()).setDateFormatOverride(new SimpleDateFormat("HH:mm"));
    chart.setBackgroundPaint(Color.WHITE);
    return chart;
}

From source file:OAT.ui.BarChartFrame.java

public void addDataset(ChartDataset dataset) {
    if (dataset == null || dataset.getSeriesCount() == 0) {
        return;//from   w  w  w . j  a v a 2s .c  om
    }

    XYPlot plot = getChart().getXYPlot();
    int i = plot.getDatasetCount();

    for (int j = 0; j < i; j++) {
        if (plot.getDataset(j).equals(dataset)) {
            //                System.out.println("eq " + i
            //                        + " " + ((ChartDataset) plot.getDataset(j)).getTitle()
            //                        + " " + dataset.getTitle());
            return;
        }
    }

    plot.setDataset(i, dataset);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    Double[] range = dataset.getAxisRange();

    //axis
    int axisId = 0;

    if (range != null) {
        //        if (range == null || range.length < 2) {
        //            plot.mapDatasetToRangeAxis(i, 0);
        //        } else {

        //scan for equal axis range, reuse if found
        boolean hasSameRange = false;

        if (range.length > 1) {
            for (int j = 1; j < plot.getRangeAxisCount(); j++) {
                Range otherRange = plot.getRangeAxis(j).getRange();

                if (otherRange != null && otherRange.getLowerBound() == range[0]
                        && otherRange.getUpperBound() == range[1]) {
                    axisId = j;
                    hasSameRange = true;
                    break;
                }
            }
        }

        if (!hasSameRange) {
            NumberAxis newAxis = new NumberAxis();

            if (range.length > 1) {
                newAxis.setAutoRange(false);
                newAxis.setRange(range[0], range[1]);
            }

            if (range.length > 2) {
                newAxis.setAutoTickUnitSelection(false, false);
                newAxis.setTickUnit(new NumberTickUnit(range[2]));
            }

            newAxis.setNumberFormatOverride(TextUtil.SIMPLE_FORMATTER);
            //                    newAxis.setAxisLinePaint(new Color(100, 0, 0));
            //                    newAxis.setLabelPaint(paints[i][0]);
            //                    newAxis.setTickLabelPaint(paints[i][0]);
            //                    newAxis.setTickMarkPaint(paints[i][0]);
            //                    newAxis.setTickLabelsVisible(true);

            axisId = plot.getRangeAxisCount();
            plot.setRangeAxis(axisId, newAxis, false);
            plot.setRangeAxisLocation(axisId, AxisLocation.BOTTOM_OR_LEFT, false);
        }
        //            plot.mapDatasetToRangeAxis(i, newAxisId);
    }
    plot.mapDatasetToRangeAxis(i, axisId);
    //

    //renderer
    XYLineAndShapeRenderer renderer;

    if (dataset instanceof TradeDataset) {
        renderer = new TradeRenderer();

        for (int j = 0; j < dataset.getSeriesCount(); j++) {
            renderer.setSeriesLinesVisible(j, false);
        }
    } else {

        Shape shape = Main.defaultShape;
        Paint[][] seriesPaints;
        Stroke stroke;

        if (dataset.getSource() instanceof Stopper && !(dataset.getSource() instanceof Calculator)) {
            seriesPaints = Main.greyPaints;
            stroke = Main.dottedStoke;
        } else {
            seriesPaints = Main.defaultPaints;
            stroke = Main.defaultStoke;
        }

        renderer = new IndicatorRenderer(seriesPaints[(i - 1) % seriesPaints.length], shape, stroke);
    }

    plot.setRenderer(i, renderer, false);
}

From source file:org.jgrasstools.gears.ui.OmsMatrixCharter.java

private JFreeChart doBarChart() {
    XYSeriesCollection collection = getSeriesCollection();
    XYBarDataset xyBarDataset = new XYBarDataset(collection, minInterval);
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    if (doHorizontal) {
        orientation = PlotOrientation.HORIZONTAL;
    }/*www  . j  a  v  a2 s.  co  m*/
    JFreeChart chart = ChartFactory.createHistogram(inTitle, inLabels[0], inLabels[1], xyBarDataset,
            orientation, doLegend, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    double delta = (max - min) * 0.1;
    yAxis.setRange(min, max + delta);
    yAxis.setMinorTickCount(4);
    yAxis.setMinorTickMarksVisible(true);
    if (inFormats != null && inFormats.length > 0 && inFormats[1].trim().length() > 0) {
        yAxis.setNumberFormatOverride(new DecimalFormat(inFormats[1]));
    }

    if (inFormats != null && inFormats.length > 0 && inFormats[0].trim().length() > 0) {
        ValueAxis domainAxis = plot.getDomainAxis();
        if (domainAxis instanceof NumberAxis) {
            NumberAxis xAxis = (NumberAxis) domainAxis;
            xAxis.setNumberFormatOverride(new DecimalFormat(inFormats[0]));
        }
    }

    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);

    if (inColors != null) {
        String[] colorSplit = inColors.split(";");
        for (int i = 0; i < colorSplit.length; i++) {
            String[] split = colorSplit[i].split(",");
            int r = (int) Double.parseDouble(split[0]);
            int g = (int) Double.parseDouble(split[1]);
            int b = (int) Double.parseDouble(split[2]);
            renderer.setSeriesPaint(i, new Color(r, g, b));
        }
    }

    return chart;
}

From source file:org.jgrasstools.gears.ui.OmsMatrixCharter.java

@SuppressWarnings("deprecation")
private JFreeChart doLineChart() {
    XYSeriesCollection collection = getSeriesCollection();
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    if (doHorizontal) {
        orientation = PlotOrientation.HORIZONTAL;
    }/*  ww  w.j av  a 2 s.co  m*/

    JFreeChart chart = ChartFactory.createXYLineChart(inTitle, inLabels[0], inLabels[1], collection,
            orientation, doLegend, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();

    // plot.setDomainGridlinePaint(Color.red);
    // plot.setRangeGridlinePaint(Color.cyan);
    // plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer plotRenderer = plot.getRenderer();
    if (plotRenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plotRenderer;
        if (doPoints) {
            renderer.setShapesVisible(true);
            renderer.setShapesFilled(true);
        }

        if (inColors != null) {
            String[] colorSplit = inColors.split(";");
            for (int i = 0; i < colorSplit.length; i++) {
                String[] split = colorSplit[i].split(",");
                int r = (int) Double.parseDouble(split[0]);
                int g = (int) Double.parseDouble(split[1]);
                int b = (int) Double.parseDouble(split[2]);
                renderer.setSeriesPaint(i, new Color(r, g, b));
            }
        }
    }

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    double delta = (max - min) * 0.1;
    yAxis.setRange(min, max + delta);
    yAxis.setMinorTickCount(4);
    yAxis.setMinorTickMarksVisible(true);
    if (inFormats != null && inFormats.length > 1 && inFormats[1].trim().length() > 0) {
        yAxis.setNumberFormatOverride(new DecimalFormat(inFormats[1]));
    }

    if (inFormats != null && inFormats.length > 0 && inFormats[0].trim().length() > 0) {
        ValueAxis domainAxis = plot.getDomainAxis();
        if (domainAxis instanceof NumberAxis) {
            NumberAxis xAxis = (NumberAxis) domainAxis;
            xAxis.setNumberFormatOverride(new DecimalFormat(inFormats[0]));
        }
    }
    return chart;
}

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

private XYPlot createPlot(TimeZone timezone, boolean plotWindDirection, boolean plotWindSpeed) {
    ChartPlotter plotter = new ChartPlotter();
    // default setting
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");
    Color windSpeedColor = new Color(0, 0, 0);
    Color windDirectionColor = new Color(0, 0, 0);
    // plot style
    PlotStyle.Builder currentStyleBuilder = new PlotStyle.Builder("Wind");
    PlotStyle plotStyle;/*w w w  . ja v  a 2  s. c  o m*/
    NumberPhenomenon windDirection = getLocationForecastDataModel()
            .getPhenomenen(PhenomenonName.WindDirectionDegree.toString(), NumberPhenomenon.class);
    NumberPhenomenon windSpeed = getLocationForecastDataModel()
            .getPhenomenen(PhenomenonName.WindSpeedMPS.toString(), NumberPhenomenon.class);
    if (windSpeed == null || windDirection == null) {
        return null;
    }

    double tick = (windSpeed.getMaxValue() - windSpeed.getMinValue()) / 3;
    tick = Math.ceil(tick);
    double lowBound = Math.floor(windSpeed.getMinValue() / (tick)) * (tick);
    //The minimum scale is 0
    lowBound = lowBound < 0 ? 0 : lowBound;
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 6;

    // reference the range axis
    NumberAxis leftNumberAxis = new NumberAxis();
    leftNumberAxis.setLabel(messages.getString("parameter.wind") + " (m/s)");
    leftNumberAxis.setLabelPaint(windSpeedColor);
    leftNumberAxis.setTickLabelPaint(windSpeedColor);
    //int tickUnit = (int) Math.ceil((upperBound - lowBound) / 6);
    leftNumberAxis.setTickUnit(new NumberTickUnit(tick));
    leftNumberAxis.setLowerBound(lowBound);
    leftNumberAxis.setUpperBound(upperBound);

    NumberAxis rightNumberAxis = new NumberAxis();
    rightNumberAxis.setLabel(messages.getString("label.knots"));
    rightNumberAxis.setLabelPaint(windSpeedColor);
    rightNumberAxis.setTickLabelPaint(windSpeedColor);
    lowBound = lowBound / KNOT;
    upperBound = upperBound / KNOT;
    rightNumberAxis.setLowerBound(lowBound);
    rightNumberAxis.setUpperBound(upperBound);
    rightNumberAxis.setTickUnit(new NumberTickUnit(tick / KNOT));
    NumberFormat formatter = new DecimalFormat("#0.0");
    rightNumberAxis.setNumberFormatOverride(formatter);

    List<Date> shortTermTimeList = this.getShortTermTime(windDirection.getTime().get(0));

    // set thte plot current speed color to be transparent if show current
    // speed is false
    if (!plotWindSpeed) {
        windSpeedColor = new Color(0, 0, 0, 0);
    }

    // plot style
    plotStyle = currentStyleBuilder.spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f))
            .seriesColor(windSpeedColor).numberAxis(leftNumberAxis).nonNegative(true).build();

    // Draw the current direction even if plotCurrentSpeed is false (but
    // with transparent in such a case)
    // for the purpose to keep the same background grid and tick label on
    // the y-axis
    // no matter the wave height is shown or not
    plotter.addLineChart(TimeBase.SECOND, windSpeed, plotStyle);

    plotter.getPlot().setRangeAxis(1, rightNumberAxis);
    plotter.getPlot().setOutlineVisible(true);

    Date minDate = shortTermTimeList.get(0);
    Date maxDate = shortTermTimeList.get(shortTermTimeList.size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // invisible domain axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);
    // add markers
    plotter.addDomainMarkers(shortTermTimeList, timezone, locale);

    if (plotWindDirection) {
        List<Date> symbolTimes = Utility.filterMinimumHourInterval(windDirection.getTime(), 2, 1);
        InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes);
        windDirection.filter(symbolTimesFilter);
        windSpeed = null;
        if (plotWindSpeed) {
            windSpeed = getLocationForecastDataModel().getPhenomenen(PhenomenonName.WindSpeedMPS.toString(),
                    NumberPhenomenon.class);
            windSpeed.filter(symbolTimesFilter);
            windSpeed = windSpeed.scaling(1 / KNOT);
        }

        plotStyle = currentStyleBuilder.seriesColor(windDirectionColor).build();
        // when plot wind direction, the arrow should be rotated 180 degree
        windDirection = windDirection.transform(180);
        plotter.addArrowDirectionPlot(windDirection, windSpeed, 2, plotStyle);
        // transform back after plot
        windDirection = windDirection.transform(180);
    }
    plotter.getPlot().setRangeZeroBaselineVisible(false);

    return plotter.getPlot();

}

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

private XYPlot createPlot(TimeZone timezone, boolean plotCurrentDirection, boolean plotCurrentSpeed) {
    ChartPlotter plotter = new ChartPlotter();
    // default setting
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");
    Color currentSpeedColor = new Color(142, 25, 131);
    Color currentDirectionColor = new Color(142, 25, 131);
    // plot style
    PlotStyle.Builder currentStyleBuilder = new PlotStyle.Builder("Current");
    PlotStyle plotStyle;//from   w w w.  java 2  s  .  c o  m
    NumberPhenomenon currentDirection = getOceanForecastDataModel()
            .getPhenomenen(PhenomenonName.CurrentDirection.toString(), NumberPhenomenon.class);
    NumberPhenomenon currentSpeed = getOceanForecastDataModel()
            .getPhenomenen(PhenomenonName.CurrentSpeed.toString(), NumberPhenomenon.class);
    if (currentSpeed == null || currentDirection == null) {
        return null;
    }
    currentSpeed = currentSpeed.scaling(100);
    double tick = (currentSpeed.getMaxValue() - currentSpeed.getMinValue()) / 2;
    tick = Math.ceil(tick / 10) * 10;
    double lowBound = Math.floor(currentSpeed.getMinValue() / (tick)) * (tick);
    //The minimum scale is 0
    lowBound = lowBound < 0 ? 0 : lowBound;
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 4;

    // reference the range axis
    NumberAxis leftNumberAxis = new NumberAxis();
    leftNumberAxis.setLabel(messages.getString("parameter.current") + " (cm/s)");
    leftNumberAxis.setLabelPaint(currentSpeedColor);
    leftNumberAxis.setTickLabelPaint(currentSpeedColor);
    leftNumberAxis.setLowerBound(lowBound);
    leftNumberAxis.setUpperBound(upperBound);
    leftNumberAxis.setTickUnit(new NumberTickUnit(tick));

    NumberAxis rightNumberAxis = new NumberAxis();
    rightNumberAxis.setLabel(messages.getString("label.knots"));
    rightNumberAxis.setLabelPaint(currentSpeedColor);
    rightNumberAxis.setTickLabelPaint(currentSpeedColor);
    lowBound = lowBound / 100.0 / KNOT;
    upperBound = upperBound / 100.0 / KNOT;
    rightNumberAxis.setLowerBound(lowBound);
    rightNumberAxis.setUpperBound(upperBound);
    rightNumberAxis.setTickUnit(new NumberTickUnit(tick / 100.0 / KNOT));
    NumberFormat formatter = new DecimalFormat("#0.00");
    rightNumberAxis.setNumberFormatOverride(formatter);

    List<Date> shortTermTimeList = this.getShortTermTime(currentDirection.getTime().get(0));

    //set thte plot current speed color to be transparent if show current speed is false
    if (!plotCurrentSpeed) {
        currentSpeedColor = new Color(0, 0, 0, 0);
    }

    // plot style
    BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 2.0f,
            new float[] { 2.0f, 6.0f }, 0.0f);
    plotStyle = currentStyleBuilder.spline(SplineStyle.HYBRID).stroke(dottedStroke)
            .seriesColor(currentSpeedColor).numberAxis(leftNumberAxis).nonNegative(true).build();

    //Draw the current direction even if plotCurrentSpeed is false (but with transparent in such a case)
    //for the purpose to keep the same background grid and tick label on the y-axis 
    //no matter the wave height is shown or not
    plotter.addLineChart(TimeBase.SECOND, currentSpeed, plotStyle);

    plotter.getPlot().setRangeAxis(1, rightNumberAxis);
    plotter.getPlot().setOutlineVisible(true);

    Date minDate = shortTermTimeList.get(0);
    Date maxDate = shortTermTimeList.get(shortTermTimeList.size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // invisible domain axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);
    // add markers
    plotter.addDomainMarkers(shortTermTimeList, timezone, locale);

    if (plotCurrentDirection) {
        List<Date> symbolTimes = Utility.filterMinimumHourInterval(currentDirection.getTime(), 2, 1);
        InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes);
        currentDirection.filter(symbolTimesFilter);
        currentSpeed = null;
        if (plotCurrentSpeed) {
            currentSpeed = getOceanForecastDataModel().getPhenomenen(PhenomenonName.CurrentSpeed.toString(),
                    NumberPhenomenon.class);
            currentSpeed.filter(symbolTimesFilter);
            currentSpeed = currentSpeed.scaling(1 / 100.0 / KNOT);
        }

        plotStyle = currentStyleBuilder.seriesColor(currentDirectionColor).build();
        plotter.addArrowDirectionPlot(currentDirection, currentSpeed, 2, plotStyle);
    }
    plotter.getPlot().setRangeZeroBaselineVisible(false);

    return plotter.getPlot();

}

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

/**
 * Creates a chart./* w w  w  . jav  a  2  s  .  c o  m*/
 *
 * @return a chart.
 */
private JFreeChart createChart() {

    final XYDataset priceData = createPriceDataset();
    final String title = "Eurodollar Futures Contract (MAR03)";
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(title, "Date", "Price", priceData, true, true,
            false);
    final XYPlot plot = chart.getXYPlot();
    final NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
    rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars
    final DecimalFormat format = new DecimalFormat("00.00");
    rangeAxis1.setNumberFormatOverride(format);

    final XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));

    final NumberAxis rangeAxis2 = new NumberAxis("Volume");
    rangeAxis2.setUpperMargin(1.00); // to leave room for price line
    plot.setRangeAxis(1, rangeAxis2);
    plot.setDataset(1, createVolumeDataset());
    plot.setRangeAxis(1, rangeAxis2);
    plot.mapDatasetToRangeAxis(1, 1);
    final XYBarRenderer renderer2 = new XYBarRenderer(0.20);
    renderer2.setToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00")));
    plot.setRenderer(1, renderer2);
    return chart;

}

From source file:org.metacsp.utility.UI.PlotBoxTLSmall.java

/**
 * Creates a chart for the PlotBoxBehavior
 * //w  ww.  j a  v a  2  s  .c  o m
 * @param dataset  A dataset for the chart.
 * 
 * @return A chart where the PlotBoxBehavior will be plotted.
 */
@SuppressWarnings("deprecation")
private JFreeChart createChart(CategoryDataset dataset) {

    //      String s = name;
    String s = null;
    String tit = null;
    String ax = null;
    //      if (first)
    //         tit = title + " (EST)";
    //      else if (last)
    //         ax = "Time";

    tit = this.name;

    chart = ChartFactory.createStackedBarChart(tit, // chart title
            s, // domain axis label
            ax, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // the plot orientation
            false, // legend
            false, // tooltips
            false // urls
    );
    CategoryPlot plot = chart.getCategoryPlot();

    chart.getTitle().setHorizontalAlignment(HorizontalAlignment.LEFT);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    //plot.getCategories();
    //CategoryItemRenderer renderer = plot.getRenderer();
    StackedBarRenderer renderer = (StackedBarRenderer) plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelGenerator(new LabelGenerator(true));
    ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.TOP_RIGHT);
    renderer.setPositiveItemLabelPositionFallback(pos);
    for (int i = 0; i < dataset.getRowCount(); i++) {
        renderer.setSeriesPositiveItemLabelPosition(i, pos);
    }

    /*
    if (values.elementAt(0) instanceof ResourceLevel) {
       renderer.setItemLabelGenerator( new PlotBoxTL.LabelGenerator(true));
    }
    else
       renderer.setItemLabelGenerator( new PlotBoxTL.LabelGenerator(false));
    */
    renderer.setToolTipGenerator(new PlotBoxTooltip());
    plot.setRenderer(renderer);
    // renderer.getSeriesStroke(0).
    plot.setForegroundAlpha(0.8f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerMargin(2.0);
    rangeAxis.setUpperMargin(2.0);

    //long origin = stl.getSerializableSimpleTimeline().getEarliestStartTime();
    //long horizon = stl.getSerializableSimpleTimeline().getLatestEndTime();
    long origin = stl.getPulses()[0].longValue();
    NumberFormat nf = new DecimalFormat();
    rangeAxis.setNumberFormatOverride(nf);
    if (this.range != null)
        rangeAxis.setRange(range);
    //rangeAxis.setRange((new Double(origin)).doubleValue(), (new Double(horizon)).doubleValue());

    ///// 0 should be replaced by the start of the horizon
    renderer.setBase(origin);

    //renderer.setBase();

    for (int i = 0; i < durations.length; i++) {
        if (stl.isInconsistent(values[i]))
            renderer.setSeriesPaint(i, new Color(198, 30, 69));
        else if (stl.isCritical(values[i]))
            renderer.setSeriesPaint(i, new Color(238, 234, 111));
        else if (stl.isUndetermined(values[i]))
            renderer.setSeriesPaint(i, new Color(255, 255, 255));
        else
            renderer.setSeriesPaint(i, new Color(111, 180, 238));
        renderer.setSeriesOutlinePaint(i, Color.black);
    }

    renderer.setBaseSeriesVisibleInLegend(false, false);

    renderer.setSeriesStroke(0, new BasicStroke(40f));

    return chart;
}