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

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

Introduction

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

Prototype

public void setAutoRangeIncludesZero(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.

Usage

From source file:org.jls.toolbox.math.chart.XYBarChart.java

/**
 * Permet de paramtrer le graphique une fois cr.
 *///from   www.  j  a  v  a 2 s  .  c  om
private void setChartStyle() {
    // Paramtrage des courbes
    this.plot.setBackgroundAlpha((float) 0.0);
    this.plot.setDomainCrosshairVisible(this.isGridXVisible);
    this.plot.setDomainCrosshairLockedOnData(true);
    this.plot.setRangeCrosshairVisible(this.isGridYVisible);
    this.plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    this.plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    this.chart.setBackgroundPaint(this.CHART_BACKGROUND_COLOR);

    NumberAxis xAxis = (NumberAxis) this.plot.getDomainAxis();
    NumberAxis yAxis = (NumberAxis) this.plot.getRangeAxis();

    xAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR);
    xAxis.setAutoRange(true);
    xAxis.setAutoRangeIncludesZero(false);

    yAxis.setAxisLinePaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setLabelPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setTickLabelPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setTickMarkPaint(this.CHART_FOREGROUND_COLOR);
    yAxis.setAutoRange(true);
    yAxis.setAutoRangeIncludesZero(false);

    this.plot.setBackgroundPaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setDomainGridlinePaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setRangeGridlinePaint(this.CHART_FOREGROUND_COLOR);
    this.plot.setDomainCrosshairPaint(this.CROSSHAIR_COLOR);
    this.plot.setRangeCrosshairPaint(this.CROSSHAIR_COLOR);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartAxisFactory.java

public static ValueAxis createRangeAxis(RangeAxisConfig rangeAxisConfig, PlotInstance plotInstance)
        throws ChartPlottimeException {
    if (rangeAxisConfig.getValueType() == ValueType.UNKNOWN
            || rangeAxisConfig.getValueType() == ValueType.INVALID) {
        return null;
    } else {//www. j  a v a 2s .  c o m
        RangeAxisData rangeAxisData = plotInstance.getPlotData().getRangeAxisData(rangeAxisConfig);

        double initialUpperBound = rangeAxisData.getUpperViewBound();
        double initialLowerBound = rangeAxisData.getLowerViewBound();

        double upperBound = initialUpperBound;
        double lowerBound = initialLowerBound;

        // fetch old zooming
        LinkAndBrushMaster linkAndBrushMaster = plotInstance.getMasterPlotConfiguration()
                .getLinkAndBrushMaster();
        Range axisZoom = linkAndBrushMaster.getRangeAxisZoom(rangeAxisConfig,
                plotInstance.getCurrentPlotConfigurationClone());

        List<ValueSource> valueSources = rangeAxisConfig.getValueSources();
        if (rangeAxisConfig.hasAbsolutStackedPlot()) {
            for (ValueSource valueSource : valueSources) {
                VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType();
                if (seriesType == VisualizationType.BARS || seriesType == VisualizationType.AREA) {
                    if (valueSource.getSeriesFormat().getStackingMode() == StackingMode.ABSOLUTE) {
                        Pair<Double, Double> minMax = calculateUpperAndLowerBounds(valueSource, plotInstance);
                        if (upperBound < minMax.getSecond()) {
                            upperBound = minMax.getSecond();
                        }
                        if (lowerBound > minMax.getFirst()) {
                            lowerBound = minMax.getFirst();
                        }
                    }
                }
            }
        }

        double margin = upperBound - lowerBound;
        if (lowerBound == upperBound) {
            margin = lowerBound;
        }
        if (margin == 0) {
            margin = 0.1;
        }

        double normalPad = RangeAxisConfig.padFactor * margin;

        if (rangeAxisConfig.isLogarithmicAxis()) {
            if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) {
                lowerBound -= RangeAxisConfig.logPadFactor * lowerBound;
            }
            if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) {
                upperBound += RangeAxisConfig.logPadFactor * upperBound;
            }
        } else {
            // add margin
            if (!rangeAxisConfig.isUsingUserDefinedLowerViewBound()) {
                lowerBound -= normalPad;
            }
            if (!rangeAxisConfig.isUsingUserDefinedUpperViewBound()) {
                upperBound += normalPad;
            }
        }

        boolean includeZero = false;
        if (isIncludingZero(rangeAxisConfig, initialLowerBound)
                && !rangeAxisConfig.isUsingUserDefinedLowerViewBound()) {
            // if so set lower bound to zero
            lowerBound = 0.0;
            includeZero = true;
        }

        boolean upToOne = false;
        // if there are only relative plots set upper Bound to 1.0
        if (rangeAxisConfig.mustHaveUpperBoundOne(initialUpperBound)
                && !rangeAxisConfig.isUsingUserDefinedUpperViewBound()) {
            upperBound = 1.0;
            upToOne = true;

        }

        if (includeZero && !upToOne) {
            upperBound *= 1.05;
        }

        String label = rangeAxisConfig.getLabel();
        if (label == null) {
            label = I18N.getGUILabel("plotter.unnamed_value_label");
        }

        ValueAxis rangeAxis;

        if (rangeAxisConfig.getValueType() == ValueType.NOMINAL && !valueSources.isEmpty()) {
            // get union of distinct values of all plotValueConfigs on range axis
            int maxValue = Integer.MIN_VALUE;
            for (ValueSource valueSource : rangeAxisData.getRangeAxisConfig().getValueSources()) {
                ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource);
                double maxValueInSource = valueSourceData.getMaxValue();
                if (maxValueInSource > maxValue) {
                    maxValue = (int) maxValueInSource;
                }
            }
            Vector<String> yValueStrings = new Vector<String>(maxValue);
            yValueStrings.setSize(maxValue + 1);
            ValueSourceData valueSourceData = plotInstance.getPlotData()
                    .getValueSourceData(valueSources.get(0));

            for (int i = 0; i <= maxValue; ++i) {
                yValueStrings.set(i, valueSourceData.getStringForValue(SeriesUsageType.MAIN_SERIES, i));
            }
            String[] yValueStringArray = new String[yValueStrings.size()];
            int i = 0;
            for (String s : yValueStrings) {
                yValueStringArray[i] = s;
                ++i;
            }
            CustomSymbolAxis symbolRangeAxis = new CustomSymbolAxis(null, yValueStringArray);
            symbolRangeAxis.setVisible(true);
            symbolRangeAxis.setAutoRangeIncludesZero(false);

            symbolRangeAxis.saveUpperBound(upperBound, initialUpperBound);
            symbolRangeAxis.saveLowerBound(lowerBound, initialLowerBound);

            symbolRangeAxis.setLabel(label);
            Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont();
            if (axesFont != null) {
                symbolRangeAxis.setLabelFont(axesFont);
                symbolRangeAxis.setTickLabelFont(axesFont);
            }

            // set range if axis has been zoomed before
            if (axisZoom != null) {
                symbolRangeAxis.setRange(axisZoom);
            }
            rangeAxis = symbolRangeAxis;
        } else if (rangeAxisConfig.getValueType() == ValueType.NUMERICAL) {
            NumberAxis numberRangeAxis;
            if (rangeAxisConfig.isLogarithmicAxis()) {
                if (rangeAxisData.getMinYValue() <= 0) {
                    throw new ChartPlottimeException("log_axis_contains_zero", label);
                }
                numberRangeAxis = new CustomLogarithmicAxis(null);
                ((CustomLogarithmicAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound);
                ((CustomLogarithmicAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound);
            } else {
                numberRangeAxis = new CustomNumberAxis();
                ((CustomNumberAxis) numberRangeAxis).saveUpperBound(upperBound, initialUpperBound);
                ((CustomNumberAxis) numberRangeAxis).saveLowerBound(lowerBound, initialLowerBound);
            }

            numberRangeAxis.setAutoRangeIncludesZero(false);

            numberRangeAxis.setVisible(true);
            numberRangeAxis.setLabel(label);
            Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont();
            if (axesFont != null) {
                numberRangeAxis.setLabelFont(axesFont);
                numberRangeAxis.setTickLabelFont(axesFont);
            }

            // set range if axis has been zoomed before
            if (axisZoom != null) {
                numberRangeAxis.setRange(axisZoom);
            }

            rangeAxis = numberRangeAxis;
        } else if (rangeAxisConfig.getValueType() == ValueType.DATE_TIME) {
            CustomDateAxis dateRangeAxis;
            if (rangeAxisConfig.isLogarithmicAxis()) {
                throw new ChartPlottimeException("logarithmic_not_supported_for_value_type", label,
                        ValueType.DATE_TIME);
            } else {
                dateRangeAxis = new CustomDateAxis();
            }

            dateRangeAxis.saveUpperBound(upperBound, initialUpperBound);
            dateRangeAxis.saveLowerBound(lowerBound, initialLowerBound);

            dateRangeAxis.setVisible(true);
            dateRangeAxis.setLabel(label);
            Font axesFont = plotInstance.getCurrentPlotConfigurationClone().getAxesFont();
            if (axesFont != null) {
                dateRangeAxis.setLabelFont(axesFont);
            }

            // set range if axis has been zoomed before
            if (axisZoom != null) {
                dateRangeAxis.setRange(axisZoom);
            }

            rangeAxis = dateRangeAxis;
        } else {
            throw new RuntimeException("Unknown value type. This should not happen");
        }

        // configure format
        formatAxis(plotInstance.getCurrentPlotConfigurationClone(), rangeAxis);
        return rangeAxis;
    }
}

From source file:com.charts.OneYearChart.java

public OneYearChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);

    renderer.setDrawVolume(false);/* w  w w.  ja v  a2s. c  o  m*/
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(900, 400));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();

    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:com.charts.YTDChart.java

public YTDChart(YStockQuote currentStock) throws ParseException {

    DateAxis domainAxis = new DateAxis("Date");
    NumberAxis rangeAxis = new NumberAxis("Price");
    CandlestickRenderer renderer = new CandlestickRenderer();
    XYDataset dataset = getDataSet(currentStock);

    XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);

    //Do some setting up, see the API Doc
    renderer.setSeriesPaint(0, Color.BLACK);

    renderer.setDrawVolume(false);/*from w  ww.  j  a v a  2s.  c  om*/
    rangeAxis.setAutoRangeIncludesZero(false);

    domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy"));
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);

    //Now create the chart and chart panel
    JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(900, 400));

    XYPlot plot = (XYPlot) chart.getPlot();
    LegendTitle legend = new LegendTitle(plot);
    chart.addLegend(legend);
    chart.getLegend().setVisible(true);
    chart.getLegend().setPosition(RectangleEdge.BOTTOM);

    ValueAxis yAxis = (ValueAxis) plot.getRangeAxis();
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();

    xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y"));
    xAxis.setAutoTickUnitSelection(true);
    xAxis.setAutoRange(true);
    renderer.setAutoWidthFactor(0.5);
    renderer.setUpPaint(Color.green);
    renderer.setDownPaint(new Color(0xc0, 0x00, 0x00));
    renderer.setSeriesPaint(0, Color.black);
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    renderer1.setSeriesPaint(0, Color.BLUE);
    TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0);
    Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue();
    currMA30 = Math.round(currMA30 * 100.0) / 100.0;
    movingAverage30.setKey("MA(30): " + currMA30);
    TimeSeriesCollection collection = new TimeSeriesCollection();
    collection.addSeries(movingAverage30);
    plot.setDataset(1, collection);
    plot.setRenderer(1, renderer1);

    chartPanel.revalidate();
    chartPanel.repaint();
    chartPanel.revalidate();
    chartPanel.repaint();
}

From source file:gov.nih.nci.cma.web.graphing.GEPlot.java

public String generateBWLog2IntensityChart(String xAxisLabel, String yAxisLabel, HttpSession session,
        PrintWriter pw, boolean isCoinPlot) {
    String bwFilename = "";

    //PlotSize ps = PlotSize.MEDIUM;

    JFreeChart bwChart = null;//  ww w  .  j av a  2s . co  m
    try {
        //IMAGE Size Control

        CategoryAxis xAxis = new CategoryAxis(xAxisLabel);
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
        NumberAxis yAxis = new NumberAxis(yAxisLabel);
        yAxis.setAutoRangeIncludesZero(true);
        BoxAndWhiskerCoinPlotRenderer bwRenderer = null;
        CategoryPlot bwPlot = null;

        if (isCoinPlot) {
            Map<String, List<Double>> groupMap = rawDataMap.get(reporterName);
            DefaultBoxAndWhiskerCategoryDataset smallBwdataset = new DefaultBoxAndWhiskerCategoryDataset();
            int row = 0;
            int column = 0;
            HashMap<String, List> caIntegatorCoinList = new HashMap<String, List>();
            for (String group : groupList) {
                smallBwdataset.add(groupMap.get(group), reporterName, group);
                caIntegatorCoinList.put(row + "_" + column++, groupMap.get(group));
            }
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer(caIntegatorCoinList);
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setDisplayCoinCloud(true);
            bwRenderer.setDisplayMean(false);
            bwRenderer.setFillBox(false);
            bwRenderer.setPlotColor(null);
            bwPlot = new CategoryPlot(smallBwdataset, xAxis, yAxis, bwRenderer);

            if (groupList.size() < 6)
                imgW = 200;

        } else {
            bwRenderer = new BoxAndWhiskerCoinPlotRenderer();
            bwRenderer.setDisplayAllOutliers(true);
            bwRenderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
                public String generateToolTip(CategoryDataset dataset, int series, int item) {
                    String tt = "";
                    NumberFormat formatter = new DecimalFormat(".####");
                    String key = "";
                    //String s = formatter.format(-1234.567);  // -001235
                    if (dataset instanceof DefaultBoxAndWhiskerCategoryDataset) {
                        DefaultBoxAndWhiskerCategoryDataset ds = (DefaultBoxAndWhiskerCategoryDataset) dataset;
                        try {
                            String med = formatter.format(ds.getMedianValue(series, item));
                            tt += "Median: " + med + "<br/>";
                            tt += "Mean: " + formatter.format(ds.getMeanValue(series, item)) + "<br/>";
                            tt += "Q1: " + formatter.format(ds.getQ1Value(series, item)) + "<br/>";
                            tt += "Q3: " + formatter.format(ds.getQ3Value(series, item)) + "<br/>";
                            tt += "Max: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMaxFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "Min: " + formatter.format(
                                    FaroutOutlierBoxAndWhiskerCalculator.getMinFaroutOutlier(ds, series, item))
                                    + "<br/>";
                            tt += "<br/><br/>Please click on the box and whisker to view a plot for this reporter.<br/>";
                            key = ds.getRowKeys().get(series).toString();
                        } catch (Exception e) {
                        }
                    }
                    String returnString = "onclick=\"popCoin('" + geneSymbol + "','" + key + "');\" | ";

                    return returnString + tt;
                }
            });
            bwRenderer.setFillBox(false);
            bwPlot = new CategoryPlot(bwdataset, xAxis, yAxis, bwRenderer);
        }

        bwChart = new JFreeChart(bwPlot);

        bwChart.setBackgroundPaint(java.awt.Color.white);
        LegendTitle title = bwChart.getLegend();
        LegendItemSource[] sources = title.getSources();

        legendItemCollection = sources[0].getLegendItems();
        bwChart.removeLegend();

        // Write the chart image to the temporary directory
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

        // BW
        if (bwChart != null) {
            //int bwwidth = new BigDecimal(1.5).multiply(new BigDecimal(imgW)).intValue();
            bwFilename = ServletUtilities.saveChartAsPNG(bwChart, imgW, 400, info, session);
            CustomOverlibToolTipTagFragmentGenerator ttip = new CustomOverlibToolTipTagFragmentGenerator();
            ttip.setExtra(" href='javascript:void(0);' "); //must have href for area tags to have cursor:pointer
            ChartUtilities.writeImageMap(pw, bwFilename, info, ttip, new StandardURLTagFragmentGenerator());
            info.clear(); // lose the first one
            info = new ChartRenderingInfo(new StandardEntityCollection());
        }
        //END  BW

        pw.flush();

    } catch (Exception e) {
        System.out.println("Exception - " + e.toString());
        e.printStackTrace(System.out);
    }
    // return filename;
    //charts.put("errorBars", log2Filename);
    //charts.put("noErrorBars", rawFilename);
    //charts.put("bwFilename", bwFilename);
    //charts.put("legend", legendHtml);
    //charts.put("size", ps.toString());

    return bwFilename;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();

    if (isSharedRangeAxis() == false) {
        final ValueAxis linesAxis = plot.getRangeAxis(1);
        if (linesAxis instanceof NumberAxis) {
            final NumberAxis numberAxis = (NumberAxis) linesAxis;
            numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero());
            numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero());

            if (getLinePeriodCount() > 0) {
                if (getLineTicksLabelFormat() != null) {
                    final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(),
                            getResourceBundleFactory().getLocale());
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount()));
                }/*from  ww  w. ja  v  a 2 s .co m*/
            } else {
                if (getLineTicksLabelFormat() != null) {
                    final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(),
                            new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setNumberFormatOverride(formatter);
                }
            }
        } else if (linesAxis instanceof DateAxis) {
            final DateAxis numberAxis = (DateAxis) linesAxis;

            if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) {
                if (getLineTicksLabelFormat() != null) {
                    final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(),
                            new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount()));
                }
            } else if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setDateFormatOverride(formatter);
            }
        }

        if (linesAxis != null) {
            final Font labelFont = Font.decode(getLabelFont());
            linesAxis.setLabelFont(labelFont);
            linesAxis.setTickLabelFont(labelFont);

            if (getLineTitleFont() != null) {
                linesAxis.setLabelFont(getLineTitleFont());
            }
            if (getLineTickFont() != null) {
                linesAxis.setTickLabelFont(getLineTickFont());
            }
            final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
            if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
                final double lineRangeMinimumVal = lineRangeMinimum == null ? 0 : lineRangeMinimum;
                final double lineRangeMaximumVal = lineRangeMaximum == null ? 0 : lineRangeMaximum;
                if (lineRangeMinimum != null) {
                    linesAxis.setLowerBound(getLineRangeMinimum());
                }
                if (lineRangeMaximum != null) {
                    linesAxis.setUpperBound(getRangeMaximum());
                }
                if (lineRangeMinimumVal == 0 && lineRangeMaximumVal == 1) {
                    linesAxis.setLowerBound(0);
                    linesAxis.setUpperBound(1);
                    linesAxis.setAutoRange(true);
                }
            } else {
                if (lineRangeMinimum != null) {
                    linesAxis.setLowerBound(lineRangeMinimum);
                }
                if (lineRangeMaximum != null) {
                    linesAxis.setUpperBound(lineRangeMaximum);
                }
                linesAxis.setAutoRange(isLineAxisAutoRange());
            }
        }
    }

    final XYLineAndShapeRenderer linesRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1);
    if (linesRenderer != null) {
        //set stroke with line width
        linesRenderer.setStroke(translateLineStyle(getLineWidth(), getLineStyle()));
        //hide shapes on line
        linesRenderer.setShapesVisible(isMarkersVisible());
        linesRenderer.setBaseShapesFilled(isMarkersVisible());

        //set colors for each line
        for (int i = 0; i < lineSeriesColor.size(); i++) {
            final String s = (String) lineSeriesColor.get(i);
            linesRenderer.setSeriesPaint(i, parseColorFromString(s));
        }
    }
}

From source file:be.nbb.demetra.dfm.output.ConfidenceGraph.java

private JFreeChart createMarginViewChart() {
    final JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);

    XYPlot plot = result.getXYPlot();/*from   w w w.j a  va 2s . c o  m*/
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    XYLineAndShapeRenderer main = new LineRenderer(MAIN_INDEX);
    plot.setRenderer(MAIN_INDEX, main);

    XYLineAndShapeRenderer original = new LineRenderer(ORIGINAL_DATA_INDEX);
    plot.setRenderer(ORIGINAL_DATA_INDEX, original);

    for (int i = 0; i < indexes.length - 1; i++) {
        plot.setRenderer(indexes[i], getDifferenceRenderer());
        for (int j = 1; j < intermediateValues; j++) {
            plot.setRenderer(indexes[i] - j, getDifferenceRenderer());
        }
    }

    plot.setRenderer(CONFIDENCE99_INDEX, getDifferenceRenderer());

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    return result;
}

From source file:charts.Chart.java

public static void LineChart(DefaultCategoryDataset dataset, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue) {

    JFrame chartwindow = new JFrame(title);

    JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, dataset,
            PlotOrientation.VERTICAL, showlegend, // include legend
            true, // tooltips
            true // urls
    );//  www  .jav  a2s  . c o  m

    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.black);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    CategoryPlot plot = (CategoryPlot) jfreechart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRangeIncludesZero(true);
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setBaseStroke(new BasicStroke(2.0f));
    lineandshaperenderer.setShapesVisible(true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setFillPaint(Color.white);

    //GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.MAGENTA, 0.0f, 0.0f, Color.MAGENTA);
    //lineandshaperenderer.setSeriesPaint(0, gp1);
    //ou
    lineandshaperenderer.setSeriesPaint(0, Color.RED);

    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
}

From source file:ch.agent.crnickl.demo.stox.Chart.java

private XYPlot getLinePlot() throws KeyedException {
    // use a number axis on the left side (default)
    NumberAxis axis = new NumberAxis();
    axis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, null, axis, null);
    return plot;//w ww  .ja va 2 s.  c  om
}

From source file:ch.agent.crnickl.demo.stox.Chart.java

private XYPlot getBarPlot() throws KeyedException {
    // use a number axis on the right side with a special formatter for millions
    NumberAxis axis = new NumberAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setNumberFormatOverride(new NumberFormatForMillions());
    XYPlot plot = new XYPlot(null, null, axis, null);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT);
    return plot;/* w ww.  j  a v  a  2  s. c o  m*/
}