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

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

Introduction

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

Prototype

public void setUpperMargin(double margin) 

Source Link

Document

Sets the upper margin for the axis (as a percentage of the axis range) and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java

private byte[] createToolAnalysisChart(int width, int height) {
    CategoryDataset dataset = getToolAnalysisDataSet();

    if (dataset == null) {
        return generateNoDataChart(width, height);
    }//w  ww  .  j av a2  s .  c  o  m

    JFreeChart chart = ChartFactory.createBarChart(null, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // the plot orientation
            false, // legend
            false, // tooltips
            false // urls
    );

    // set background
    chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor()));

    // set chart border
    chart.setPadding(new RectangleInsets(10, 5, 5, 5));
    chart.setBorderVisible(true);
    chart.setBorderPaint(parseColor("#cccccc"));

    // set anti alias
    chart.setAntiAlias(true);

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

    // set transparency
    plot.setForegroundAlpha(0.7f);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);
    domainAxis.setUpperMargin(0);
    domainAxis.setLowerMargin(0);

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

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{1}",
            NumberFormat.getInstance(new ResourceLoader().getLocale()));
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelFont(new Font("SansSerif", Font.PLAIN, 9));
    renderer.setBaseItemLabelsVisible(true);
    renderer.setItemMargin(0);
    renderer.setSeriesPaint(0, Color.BLUE);

    BufferedImage img = chart.createBufferedImage(width, height);
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        ImageIO.write(img, "png", out);
    } catch (IOException e) {
        log.warn("Error occurred while generating SiteStats chart image data", e);
    }
    return out.toByteArray();
}

From source file:com.peterbochs.instrument.InstrumentPanel.java

private static JFreeChart createEmptyChart(XYZDataset dataset) {
    NumberAxis xAxis = new NumberAxis("address");
    xAxis.setLowerMargin(0.0);/*from w w w.  j av a 2 s  .  c  o m*/
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis("address");
    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setInverted(false);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    // yAxis.setAxisLinePaint(Color.pink);
    // yAxis.setTickMarkPaint(Color.white);
    yAxis.setTickLabelFont(new Font("Dialog", 0, 7));
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    MyXYBlockRenderer renderer = new MyXYBlockRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    // plot.setBackgroundPaint(Color.white);
    // plot.setDomainGridlineStroke(new BasicStroke(1));
    plot.setDomainGridlinePaint(Color.white);

    // plot.setRangeGridlineStroke(new BasicStroke(1));
    plot.setRangeGridlinePaint(Color.white);

    JFreeChart chart = new JFreeChart("Memory read/write hot zone", new Font("Serif", Font.PLAIN, 12), plot,
            true);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    return chart;
}

From source file:org.operamasks.faces.render.graph.ChartRenderer.java

private void setNumberAxisStyles(NumberAxis axis, UIAxis comp) {
    axis.setInverted(comp.isInverted());

    Object lowerBound = comp.getLowerBound();
    Object upperBound = comp.getUpperBound();
    Double lowerMargin = comp.getLowerMargin();
    Double upperMargin = comp.getUpperMargin();

    if (lowerBound != null)
        axis.setLowerBound(Coercion.coerceToDouble(lowerBound));
    if (upperBound != null)
        axis.setUpperBound(Coercion.coerceToDouble(upperBound));
    if (lowerMargin != null)
        axis.setLowerMargin(lowerMargin);
    if (upperMargin != null)
        axis.setUpperMargin(upperMargin);

    Double tickStep = comp.getTickStep();
    String tickFormat = comp.getTickLabelFormat();

    if ((tickStep != null && tickStep > 0) || tickFormat != null) {
        if (tickFormat == null) {
            axis.setTickUnit(new NumberTickUnit(tickStep));
        } else if (tickStep == null) {
            NumberFormat format = new DecimalFormat(tickFormat);
            axis.setNumberFormatOverride(format);
        } else {/* w ww  .  ja  v a2 s .c  o m*/
            NumberFormat format = new DecimalFormat(tickFormat);
            axis.setTickUnit(new NumberTickUnit(tickStep, format));
        }
    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.OverlaidBarLine.java

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");

    // create the first renderer...

    CategoryPlot plot = new CategoryPlot();

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    NumberAxis rangeAxis = new NumberAxis(getValueLabel());
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis//  w  ww .ja  v a2 s. com
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    //      rangeAxis.setLowerBound(600);
    //      rangeAxis.setUpperBound(720);
    if (firstAxisLB != null && firstAxisUB != null) {
        rangeAxis.setLowerBound(firstAxisLB);
        rangeAxis.setUpperBound(firstAxisUB);
    }

    rangeAxis.setUpperMargin(0.10);
    plot.setRangeAxis(0, rangeAxis);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    rangeAxis.setNumberFormatOverride(nf);

    CategoryAxis domainAxis = new CategoryAxis(getCategoryLabel());
    domainAxis.setLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setLabelPaint(styleYaxesLabels.getColor());
    domainAxis
            .setTickLabelFont(new Font(styleYaxesLabels.getFontName(), Font.PLAIN, styleYaxesLabels.getSize()));
    domainAxis.setTickLabelPaint(styleYaxesLabels.getColor());
    domainAxis.setUpperMargin(0.10);
    plot.setDomainAxis(domainAxis);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    DefaultCategoryDataset datasetLineFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-line");
    DefaultCategoryDataset datasetBarFirstAxis = (DefaultCategoryDataset) datasets.getDatasets().get("1-bar");
    DefaultCategoryDataset datasetLineSecondAxis = (DefaultCategoryDataset) datasets.getDatasets()
            .get("2-line");
    DefaultCategoryDataset datasetBarSecondAxis = (DefaultCategoryDataset) datasets.getDatasets().get("2-bar");

    //I create one bar renderer and one line
    MyStandardCategoryItemLabelGenerator generator = null;

    // value labels and additional values are mutually exclusive
    if (showValueLabels == true)
        additionalLabels = false;

    if (additionalLabels) {
        generator = new MyStandardCategoryItemLabelGenerator(catSerLabels, "{1}", NumberFormat.getInstance());
    }

    if (useBars) {

        CategoryItemRenderer barRenderer = null;
        if (stackedBarRenderer_1 == true) {
            barRenderer = new StackedBarRenderer();
        } else {
            barRenderer = new BarRenderer();
        }

        CategoryItemRenderer barRenderer2 = new BarRenderer();

        if (stackedBarRenderer_2 == true) {
            barRenderer2 = new StackedBarRenderer();
        } else {
            barRenderer2 = new BarRenderer();
        }

        if (maxBarWidth != null) {
            ((BarRenderer) barRenderer).setMaximumBarWidth(maxBarWidth.doubleValue());
            ((BarRenderer) barRenderer2).setMaximumBarWidth(maxBarWidth.doubleValue());
        }

        if (showValueLabels) {
            barRenderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            barRenderer.setBaseItemLabelsVisible(true);
            barRenderer.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            barRenderer.setBaseItemLabelPaint(styleValueLabels.getColor());

            //            barRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
            //                  ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            //
            //            barRenderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
            //                  ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

            if (valueLabelsPosition.equalsIgnoreCase("inside")) {
                barRenderer.setBasePositiveItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
                barRenderer.setBaseNegativeItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
            } else {
                barRenderer.setBasePositiveItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
                barRenderer.setBaseNegativeItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            }

        } else if (additionalLabels) {
            barRenderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
            barRenderer.setBaseItemLabelGenerator(generator);
            double orient = (-Math.PI / 2.0);
            if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
                orient = 0.0;
            }

            barRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            barRenderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            barRenderer.setBaseItemLabelFont(
                    new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
            barRenderer.setBaseItemLabelPaint(defaultLabelsStyle.getColor());
            barRenderer.setBaseItemLabelsVisible(true);
        }

        if (showValueLabels) {
            barRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            barRenderer2.setBaseItemLabelsVisible(true);
            barRenderer2.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            barRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());

            //            barRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(
            //                  ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            //
            //            barRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
            //                  ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

            if (valueLabelsPosition.equalsIgnoreCase("inside")) {
                barRenderer2.setBasePositiveItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
                barRenderer2.setBaseNegativeItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT));
            } else {
                barRenderer2.setBasePositiveItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
                barRenderer2.setBaseNegativeItemLabelPosition(
                        new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));
            }

        } else if (additionalLabels) {
            barRenderer2.setBaseItemLabelGenerator(generator);
            double orient = (-Math.PI / 2.0);
            if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
                orient = 0.0;
            }

            barRenderer2.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            barRenderer2.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));

            barRenderer2.setBaseItemLabelFont(
                    new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
            barRenderer2.setBaseItemLabelPaint(defaultLabelsStyle.getColor());
            barRenderer2.setBaseItemLabelsVisible(true);

        }

        if (colorMap != null) {
            int idx = -1;
            for (Iterator iterator = datasetBarFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetBarFirstAxis.getRowIndex(labelName);
                } else
                    index = datasetBarFirstAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    barRenderer.setSeriesPaint(index, color);
                }
            }
            for (Iterator iterator = datasetBarSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
                idx++;
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetBarSecondAxis.getRowIndex(labelName);
                } else
                    index = datasetBarSecondAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    barRenderer2.setSeriesPaint(index, color);
                    /* test con un renderer
                    if (idx > index){
                       index = idx+1;
                    }
                            
                    barRenderer.setSeriesPaint(index, color);*/
                }
            }
        }
        // add tooltip if enabled
        if (enableToolTips) {
            MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                    seriesTooltip, categoriesTooltip, seriesCaptions);
            barRenderer.setToolTipGenerator(generatorToolTip);
            barRenderer2.setToolTipGenerator(generatorToolTip);
        }
        //defines url for drill
        boolean document_composition = false;
        if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
            document_composition = true;

        logger.debug("Calling Url Generation");

        MyCategoryUrlGenerator mycatUrl = null;
        if (super.rootUrl != null) {
            logger.debug("Set MycatUrl");
            mycatUrl = new MyCategoryUrlGenerator(super.rootUrl);

            mycatUrl.setDocument_composition(document_composition);
            mycatUrl.setCategoryUrlLabel(super.categoryUrlName);
            mycatUrl.setSerieUrlLabel(super.serieUrlname);
            mycatUrl.setDrillDocTitle(drillDocTitle);
            mycatUrl.setTarget(target);
        }
        if (mycatUrl != null
                && (!mycatUrl.getCategoryUrlLabel().equals("") || !mycatUrl.getSerieUrlLabel().equals(""))) {
            barRenderer.setItemURLGenerator(mycatUrl);
            barRenderer2.setItemURLGenerator(mycatUrl);
        }

        plot.setDataset(2, datasetBarFirstAxis);
        plot.setDataset(3, datasetBarSecondAxis);

        plot.setRenderer(2, barRenderer);
        plot.setRenderer(3, barRenderer2);

    }

    if (useLines) {

        LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
        LineAndShapeRenderer lineRenderer2 = new LineAndShapeRenderer();

        //lineRenderer.setShapesFilled(false);
        lineRenderer.setShapesFilled(true);
        lineRenderer2.setShapesFilled(true);

        // no shapes for line_no_shapes  series
        for (Iterator iterator = lineNoShapeSeries1.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that

            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineFirstAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer.setSeriesShapesVisible(index, false);
            }
        }

        for (Iterator iterator = lineNoShapeSeries2.iterator(); iterator.hasNext();) {
            String ser = (String) iterator.next();
            // if there iS a abel associated search for that
            String label = null;
            if (seriesLabelsMap != null) {
                label = (String) seriesLabelsMap.get(ser);
            }
            if (label == null)
                label = ser;
            int index = datasetLineSecondAxis.getRowIndex(label);
            if (index != -1) {
                lineRenderer2.setSeriesShapesVisible(index, false);
            }
        }

        if (enableToolTips) {
            MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                    seriesTooltip, categoriesTooltip, seriesCaptions);
            lineRenderer.setToolTipGenerator(generatorToolTip);
            lineRenderer2.setToolTipGenerator(generatorToolTip);
        }

        if (showValueLabels) {
            lineRenderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer.setBaseItemLabelsVisible(true);
            lineRenderer.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.ITALIC, styleValueLabels.getSize()));
            lineRenderer.setBaseItemLabelPaint(styleValueLabels.getColor());

            lineRenderer.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_RIGHT));

            lineRenderer.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_RIGHT));

        } else if (additionalLabels) {
            lineRenderer.setBaseItemLabelGenerator(generator);
            lineRenderer.setBaseItemLabelFont(
                    new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
            lineRenderer.setBaseItemLabelPaint(defaultLabelsStyle.getColor());
            lineRenderer.setBaseItemLabelsVisible(true);
        }

        if (showValueLabels) {
            lineRenderer2.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
            lineRenderer2.setBaseItemLabelsVisible(true);
            lineRenderer2.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.ITALIC, styleValueLabels.getSize()));
            lineRenderer2.setBaseItemLabelPaint(styleValueLabels.getColor());

            lineRenderer2.setBasePositiveItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_RIGHT));

            lineRenderer2.setBaseNegativeItemLabelPosition(
                    new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_RIGHT));

        } else if (additionalLabels) {
            lineRenderer2.setBaseItemLabelGenerator(generator);
            lineRenderer2.setBaseItemLabelFont(
                    new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
            lineRenderer2.setBaseItemLabelPaint(defaultLabelsStyle.getColor());
            lineRenderer2.setBaseItemLabelsVisible(true);
        }

        //         DefaultCategoryDataset datasetSecondAxis=(DefaultCategoryDataset)datasets.getDatasets().get("2");

        if (colorMap != null) {
            for (Iterator iterator = datasetLineSecondAxis.getRowKeys().iterator(); iterator.hasNext();) {
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineSecondAxis.getRowIndex(labelName);
                } else
                    index = datasetLineSecondAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer2.setSeriesPaint(index, color);
                }
            }
            for (Iterator iterator = datasetLineFirstAxis.getRowKeys().iterator(); iterator.hasNext();) {
                String serName = (String) iterator.next();
                String labelName = "";
                int index = -1;

                if (seriesCaptions != null && seriesCaptions.size() > 0) {
                    labelName = serName;
                    serName = (String) seriesCaptions.get(serName);
                    index = datasetLineFirstAxis.getRowIndex(labelName);
                } else
                    index = datasetLineFirstAxis.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer.setSeriesPaint(index, color);
                }
            }

        }
        plot.setDataset(0, datasetLineFirstAxis);
        plot.setRenderer(0, lineRenderer);
        plot.setDataset(1, datasetLineSecondAxis);
        plot.setRenderer(1, lineRenderer2);

    }

    if (secondAxis) {
        NumberAxis na = new NumberAxis(secondAxisLabel);
        na.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
        na.setLabelPaint(styleXaxesLabels.getColor());
        na.setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
        na.setTickLabelPaint(styleXaxesLabels.getColor());
        na.setUpperMargin(0.10);
        na.setNumberFormatOverride(nf);
        //         rangeAxis.setLowerBound(270);
        //         rangeAxis.setUpperBound(340);
        if (secondAxisLB != null && secondAxisUB != null) {
            rangeAxis.setLowerBound(secondAxisLB);
            rangeAxis.setUpperBound(secondAxisUB);
        }
        plot.setRangeAxis(1, na);
        plot.mapDatasetToRangeAxis(0, 0);
        plot.mapDatasetToRangeAxis(2, 0);
        plot.mapDatasetToRangeAxis(1, 1);
        plot.mapDatasetToRangeAxis(3, 1);
        if (rangeIntegerValues == true) {
            na.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        }

    }

    //plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }
    chart.setBackgroundPaint(Color.white);

    if (legend == true)
        drawLegend(chart);

    logger.debug("OUT");

    return chart;

}

From source file:com.peterbochs.instrument.InstrumentPanel.java

private static JFreeChart createChart(XYZDataset dataset) {
    NumberAxis xAxis = new NumberAxis("address (" + jBlockSizeComboBox.getSelectedItem() + ")");
    xAxis.setLowerMargin(0.0);// ww  w.  ja  v  a2s . c o m
    xAxis.setUpperMargin(0.0);
    xAxis.setAxisLinePaint(Color.cyan);
    xAxis.setTickMarkPaint(Color.cyan);
    // xAxis.setAutoTickUnitSelection(false);
    // xAxis.setTickUnit(new NumberTickUnit(1));
    // NumberFormat nf = NumberFormat.getPercentInstance();
    // xAxis.setNumberFormatOverride(nf);
    // xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    NumberAxis yAxis = new NumberAxis("address (" + jBlockSizeComboBox.getSelectedItem() + " KB)");
    // yAxis.setAutoRangeIncludesZero(true);
    // yAxis.setInverted(false);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setAxisLinePaint(Color.pink);
    yAxis.setTickMarkPaint(Color.pink);
    // yAxis.setTickUnit(new NumberTickUnit(10));
    // yAxis.setTickLabelFont(new Font("Dialog", 0, 7));
    // yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    MyXYBlockRenderer renderer = new MyXYBlockRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    // plot.setBackgroundPaint(Color.white);
    // plot.setDomainGridlineStroke(new BasicStroke(1));
    plot.setDomainGridlinePaint(Color.white);

    // plot.setRangeGridlineStroke(new BasicStroke(1));
    plot.setRangeGridlinePaint(Color.white);

    // JFreeChart chart = new JFreeChart("Memory read/write hot zone", new
    // Font("Serif", Font.PLAIN, 12), plot, true);
    JFreeChart chart = new JFreeChart("Memory read/write hot zone", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    return chart;
}

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

protected void customizeXYLineAndShapeRenderer(ChartDefinition cd, XYPlot plot, PlotInformation pi) {
    AbstractXYItemRenderer renderer = (AbstractXYItemRenderer) plot.getRenderer();

    if (renderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xrenderer = (XYLineAndShapeRenderer) renderer;

        if (pi != null) {
            ShapeStyle fs = pi.getShapeStyle();

            if (renderer instanceof XYAreaSplineRendererEx) {
                fs = pi.getShapeStyleEx();
            }/*from w  w  w.j av a 2s  . c om*/

            switch (fs) {
            case FILLED:
                xrenderer.setBaseShapesVisible(true);
                xrenderer.setBaseShapesFilled(true);
                xrenderer.setUseFillPaint(true);

                break;

            case OUTLINED:
                xrenderer.setBaseShapesVisible(true);
                xrenderer.setDrawOutlines(true);
                xrenderer.setUseOutlinePaint(true);

                break;

            case FILLED_AND_OUTLINED:
                xrenderer.setBaseShapesVisible(true);
                xrenderer.setDrawOutlines(true);
                xrenderer.setBaseShapesFilled(true);
                xrenderer.setUseOutlinePaint(true);
                xrenderer.setUseFillPaint(true);

                break;

            default:
                xrenderer.setBaseShapesVisible(false);

                break;
            }
        }

        if (xrenderer.getBaseShapesVisible()) {
            xrenderer.setBaseShape(getDefaultShape(0));
        }
    }

    StandardXYItemLabelGenerator lg = null;

    renderer.setBaseItemLabelsVisible(cd.isShowPlotLabels());
    lg = new XYToolTipLabelGenerator(((ChartInfo) cd.getChartHandlerInfo()).seriesData);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    renderer.setBaseItemLabelGenerator(lg);
    rangeAxis.setUpperMargin(0.25);

    if (cd.isShowToolTips()) {
        renderer.setBaseToolTipGenerator((XYToolTipLabelGenerator) lg);
    }
}

From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java

/**
 * Creates a chart.//from   w  w w  .j a va2s  . co m
 *
 * @return a chart.
 */
private JFreeChart createPriceVolumeChart(XYDataset priceDataset, XYDataset volumeDataset) {
    final String title = getBestStockName();

    final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date"));
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);

    final NumberAxis rangeAxis1 = new NumberAxis(GUIBundle.getString("ChartJDialog_Price"));
    rangeAxis1.setAutoRangeIncludesZero(false); // override default
    rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars
    DecimalFormat format = new DecimalFormat("0.00#");
    rangeAxis1.setNumberFormatOverride(format);

    XYPlot plot = new XYPlot(priceDataset, timeAxis, rangeAxis1, null);

    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#")));
    plot.setRenderer(0, renderer1);

    final NumberAxis rangeAxis2 = new NumberAxis("Volume");
    rangeAxis2.setUpperMargin(1.00); // to leave room for price line
    plot.setRangeAxis(1, rangeAxis2);
    plot.setDataset(1, volumeDataset);
    plot.mapDatasetToRangeAxis(1, 1);

    XYBarRenderer renderer2 = new XYBarRenderer(0.20);
    renderer2.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.00")));
    plot.setRenderer(1, renderer2);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(timeAxis);
    cplot.add(plot, 1);
    cplot.setGap(8.0);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, cplot, true);
    org.yccheok.jstock.charting.Utils.applyChartThemeEx(chart);

    // Only do it after applying chart theme.
    org.yccheok.jstock.charting.Utils.setPriceSeriesPaint(renderer1);
    org.yccheok.jstock.charting.Utils.setVolumeSeriesPaint(renderer2);

    // Handle zooming event.
    chart.addChangeListener(this.getChartChangeListner());

    return chart;
}

From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java

/**
 * Creates a chart./*from  ww w.  j a v a2  s .  c o  m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The dataset.
 */
private JFreeChart createCandlestickChart(OHLCDataset priceOHLCDataset) {
    final String title = getBestStockName();

    final ValueAxis timeAxis = new DateAxis(GUIBundle.getString("ChartJDialog_Date"));
    final NumberAxis valueAxis = new NumberAxis(GUIBundle.getString("ChartJDialog_Price"));
    valueAxis.setAutoRangeIncludesZero(false);
    valueAxis.setUpperMargin(0.0);
    valueAxis.setLowerMargin(0.0);
    XYPlot plot = new XYPlot(priceOHLCDataset, timeAxis, valueAxis, null);

    final CandlestickRenderer candlestickRenderer = new CandlestickRenderer();
    plot.setRenderer(candlestickRenderer);

    // Give good width when zoom in, but too slow in calculation.
    ((CandlestickRenderer) plot.getRenderer()).setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);

    CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(timeAxis);
    cplot.add(plot, 3);
    cplot.setGap(8.0);

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, cplot, true);

    org.yccheok.jstock.charting.Utils.applyChartThemeEx(chart);

    // Handle zooming event.
    chart.addChangeListener(this.getChartChangeListner());

    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createXYZBubbleChart(String title, String xLabel, String yLabel, XYZDataset dataset) {
    JFreeChart chart = ChartFactory.createBubbleChart(title, xLabel, yLabel, dataset, orientation, true, true,
            false);/*from   w w w .j av a2 s . c om*/
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    //renderer.setLegendItemLabelGenerator(new SOCRXYZSeriesLabelGenerator());

    // increase the margins to account for the fact that the auto-range
    // doesn't take into account the bubble size...
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setLowerMargin(0.15);
    domainAxis.setUpperMargin(0.15);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);
    return chart;
}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createXYLineChart(String title, String xLabel, String yLabel, XYDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // data
            orientation, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );//from   w  w  w .  j a  va2 s  .  c  o  m

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setNoDataMessage("No data available");

    // customise the renderer...
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    // customise the range axis...

    if (lineCondition.indexOf("qq") != -1) {
        renderer.setBaseShapesFilled(true);
        renderer.setSeriesLinesVisible(1, true);
        renderer.setSeriesShapesVisible(1, false);
        renderer.setSeriesLinesVisible(0, false);
        renderer.setSeriesShapesVisible(0, true);

        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setAutoRangeIncludesZero(false);
        rangeAxis.setUpperMargin(0);
        rangeAxis.setLowerMargin(0);

        // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setAutoRangeIncludesZero(false);
        domainAxis.setUpperMargin(0);
        domainAxis.setLowerMargin(0);
        return chart;
    }

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRange(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (timeType.length() != 0) {
        setDateAxis(plot);
    } else {
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setAutoRange(false);
        domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    // System.out.println("lineCondition "+lineCondition);
    if (lineCondition.indexOf("noshape") != -1)
        renderer.setBaseShapesVisible(false);
    else
        renderer.setBaseShapesVisible(true);

    if (lineCondition.indexOf("noline") != -1)
        renderer.setBaseLinesVisible(false);

    if (lineCondition.indexOf("nofill") != -1) {
        renderer.setBaseShapesFilled(false);
        renderer.setBaseFillPaint(Color.white);
        renderer.setDrawOutlines(true);
    } else {
        renderer.setBaseShapesFilled(true);
        renderer.setUseFillPaint(false);
    }

    return chart;
}