Example usage for org.jfree.chart.axis ValueAxis setRangeWithMargins

List of usage examples for org.jfree.chart.axis ValueAxis setRangeWithMargins

Introduction

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

Prototype

public void setRangeWithMargins(double lower, double upper) 

Source Link

Document

Sets the axis range (after first adding the current margins to the range) and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:org.multiwii.swingui.gui.chart.MwChartFactory.java

public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) {
    final JFreeChart chart;

    chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true);

    chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));
    chart.setBorderVisible(false);/*from  ww w . j  a  v a  2 s .co m*/
    final XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));

    plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS"));
    axis.setAxisLineVisible(false);
    axis.setTickLabelsVisible(false);
    axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    // force integer display
    final ValueAxis va = plot.getRangeAxis();
    va.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    // va.setRange(-280,280);
    // va.setFixedAutoRange(560);
    // va.setLowerBound(-280);
    // va.setUpperBound(280);
    // va.setAutoRange(false);
    va.setRangeWithMargins(-280, 280);

    final MwChartPanel chartPanel = new MwChartPanel(chart, conf);
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);

    return chartPanel;

}

From source file:eu.kprod.gui.chart.MwChartFactory.java

public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) {
    final JFreeChart chart;

    chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true);

    chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));
    chart.setBorderVisible(false);/*from   w  w w. jav a2 s . c o  m*/
    final XYPlot plot = chart.getXYPlot();

    plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR));

    plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    final DateAxis axis = (DateAxis) plot.getDomainAxis();
    // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS"));
    axis.setAxisLineVisible(false);
    axis.setTickLabelsVisible(false);
    axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    // force integer display
    final ValueAxis va = plot.getRangeAxis();
    va.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR));
    va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR));

    //        va.setRange(-280,280);
    //        va.setFixedAutoRange(560);
    //        va.setLowerBound(-280);
    //        va.setUpperBound(280);
    //        va.setAutoRange(false);
    va.setRangeWithMargins(-280, 280);

    final MwChartPanel chartPanel = new MwChartPanel(chart, conf);
    chartPanel.setMouseWheelEnabled(false);
    chartPanel.setDomainZoomable(false);
    chartPanel.setRangeZoomable(false);

    return chartPanel;

}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java

public JFreeChart createChart(DatasetMap datasets) {

    DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1");

    JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL,
            false, true, false);/*w  w  w . j  a  v a  2  s  . com*/

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

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setForegroundAlpha(0.65f);

    XYItemRenderer renderer = plot.getRenderer();

    //defines colors 
    int seriesN = dataset.getSeriesCount();
    if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) {
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getSeriesKey(i);
            Color color = new Color(Integer.decode(defaultColor).intValue());
            if (colorMap != null && colorMap.size() > 0)
                color = (Color) colorMap.get(serieName);
            if (color != null)
                renderer.setSeriesPaint(i, color);
        }
    }

    // add un interval  marker for the Y axis...
    if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("")
            && !yMarkerEndInt.equals("")) {
        Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt),
                Double.parseDouble(yMarkerEndInt));
        intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerY.setPaint(
                new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue()));
        //intMarkerY.setLabel(yMarkerLabel);
        intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(intMarkerY, Layer.BACKGROUND);
    }
    // add un interval  marker for the X axis...
    if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("")
            && !xMarkerEndInt.equals("")) {
        Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt),
                Double.parseDouble(xMarkerEndInt));
        intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        intMarkerX.setPaint(
                new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue()));
        //intMarkerX.setLabel(xMarkerLabel);
        intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(intMarkerX, Layer.BACKGROUND);
    }
    // add a labelled marker for the Y axis...
    if (yMarkerValue != null && !yMarkerValue.equals("")) {
        Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue));
        markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!yMarkerColor.equals(""))
            markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue()));
        markerY.setLabel(yMarkerLabel);
        markerY.setLabelFont(new Font("Arial", Font.BOLD, 11));
        markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addDomainMarker(markerY, Layer.BACKGROUND);
    }
    // add a labelled marker for the X axis...
    if (xMarkerValue != null && !xMarkerValue.equals("")) {
        Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue));
        markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND);
        if (!xMarkerColor.equals(""))
            markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue()));
        markerX.setLabel(xMarkerLabel);
        markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
        markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        plot.addRangeMarker(markerX, Layer.BACKGROUND);
    }

    if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) {
        if (Double.valueOf(xRangeLow).doubleValue() > xMin)
            xRangeLow = String.valueOf(xMin);
        if (Double.valueOf(xRangeHigh).doubleValue() < xMax)
            xRangeHigh = String.valueOf(xMax);
        ValueAxis rangeAxis = plot.getRangeAxis();
        //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
        rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh));
    } else {
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setAutoRange(true);
        rangeAxis.setRange(xMin, xMax);
    }

    if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) {
        if (Double.valueOf(yRangeLow).doubleValue() > yMin)
            yRangeLow = String.valueOf(yMin);
        if (Double.valueOf(yRangeHigh).doubleValue() < yMax)
            yRangeHigh = String.valueOf(yMax);
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh));
        domainAxis.setAutoRangeIncludesZero(false);
    } else {
        NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
        domainAxis.setAutoRange(true);
        domainAxis.setRange(yMin, yMax);
        domainAxis.setAutoRangeIncludesZero(false);
    }

    //add annotations if requested
    if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) {
        if (annotationMap == null || annotationMap.size() == 0)
            logger.error("Annotations on the chart are requested but the annotationMap is null!");
        else {
            int cont = 1;
            for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) {
                String text = (String) iterator.next();
                String pos = (String) annotationMap.get(text);
                double x = Double.parseDouble(pos.substring(0, pos.indexOf("__")));
                double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2));
                //default up position
                XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1,
                        x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                if (cont % 2 != 0)
                    //dx
                    annotation = new XYTextAnnotation(text, y,
                            x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1));
                else
                    //sx
                    //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1));
                    annotation = new XYTextAnnotation(text, y, x - (text.length() - 1));

                annotation.setFont(new Font("SansSerif", Font.PLAIN, 11));
                //annotation.setRotationAngle(Math.PI / 4.0);
                annotation.setRotationAngle(0.0); // horizontal
                plot.addAnnotation(annotation);
                cont++;
            }
            renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
        }
    } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) {
        renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8));
    }
    if (legend == true) {

        drawLegend(chart);
    }
    return chart;
}