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

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

Introduction

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

Prototype

@Override
public Object clone() throws CloneNotSupportedException 

Source Link

Document

Returns a clone of the object.

Usage

From source file:RDGraphGenerator.java

/**
 * Creates a sample chart./* w w w.  jav a 2s  .c o m*/
 *
 * @param dataset  the dataset for the chart.
 *
 * @return A sample chart.
 */
private JFreeChart createDistChart(String riderID) {

    String riderName = (String) riders.get(riderID);
    final JFreeChart chart = ChartFactory.createStackedBarChart(riderName + "'s Distances", // chart title
            "Month", // domain axis label
            mainDist, // range axis label
            (CategoryDataset) riderDistances.get(riderID), // data
            PlotOrientation.VERTICAL, // the plot orientation
            true, // legend
            true, // tooltips
            false // urls
    );

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("0", "G1");
    map.mapKeyToGroup("1", "G1");
    map.mapKeyToGroup("2", "G1");
    map.mapKeyToGroup("3", "G1");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(renderer);
    plot.setFixedLegendItems(createLegendItems());
    ValueAxis va = (ValueAxis) plot.getRangeAxis();
    ValueAxis ova = null;
    try {
        ova = (ValueAxis) va.clone();
    } catch (CloneNotSupportedException cnse) {
    }
    ova.setLabel(secondaryDist);
    ova.setLowerBound(va.getLowerBound() * unitConversion);
    ova.setUpperBound(va.getUpperBound() * unitConversion);
    plot.setRangeAxis(1, ova);
    plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT);
    CategoryAxis ca = plot.getDomainAxis();
    ca.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    //Make around the chart transparent.
    chart.setBackgroundPaint(null);
    return chart;

}

From source file:ucar.unidata.idv.control.chart.MyXYPlot.java

/**
 * Returns a clone of the plot./*w ww . ja  v  a 2  s .co m*/
 *
 * @return A clone.
 *
 * @throws CloneNotSupportedException  this can occur if some component of
 *         the plot cannot be cloned.
 */
public Object clone() throws CloneNotSupportedException {

    MyXYPlot clone = (MyXYPlot) super.clone();
    clone.domainAxes = (ObjectList) ObjectUtilities.clone(this.domainAxes);
    for (int i = 0; i < this.domainAxes.size(); i++) {
        ValueAxis axis = (ValueAxis) this.domainAxes.get(i);
        if (axis != null) {
            ValueAxis clonedAxis = (ValueAxis) axis.clone();
            clone.domainAxes.set(i, clonedAxis);
            clonedAxis.setPlot(clone);
            clonedAxis.addChangeListener(clone);
        }
    }
    clone.domainAxisLocations = (ObjectList) this.domainAxisLocations.clone();

    clone.rangeAxes = (ObjectList) ObjectUtilities.clone(this.rangeAxes);
    for (int i = 0; i < this.rangeAxes.size(); i++) {
        ValueAxis axis = (ValueAxis) this.rangeAxes.get(i);
        if (axis != null) {
            ValueAxis clonedAxis = (ValueAxis) axis.clone();
            clone.rangeAxes.set(i, clonedAxis);
            clonedAxis.setPlot(clone);
            clonedAxis.addChangeListener(clone);
        }
    }
    clone.rangeAxisLocations = (ObjectList) ObjectUtilities.clone(this.rangeAxisLocations);

    // the datasets are not cloned, but listeners need to be added...
    clone.datasets = (ObjectList) ObjectUtilities.clone(this.datasets);
    for (int i = 0; i < clone.datasets.size(); ++i) {
        XYDataset d = getDataset(i);
        if (d != null) {
            d.addChangeListener(clone);
        }
    }

    clone.datasetToDomainAxisMap = new TreeMap();
    clone.datasetToDomainAxisMap.putAll(this.datasetToDomainAxisMap);
    clone.datasetToRangeAxisMap = new TreeMap();
    clone.datasetToRangeAxisMap.putAll(this.datasetToRangeAxisMap);

    clone.renderers = (ObjectList) ObjectUtilities.clone(this.renderers);
    for (int i = 0; i < this.renderers.size(); i++) {
        XYItemRenderer renderer2 = (XYItemRenderer) this.renderers.get(i);
        if (renderer2 instanceof PublicCloneable) {
            PublicCloneable pc = (PublicCloneable) renderer2;
            clone.renderers.set(i, pc.clone());
        }
    }
    clone.foregroundDomainMarkers = (Map) ObjectUtilities.clone(this.foregroundDomainMarkers);
    clone.backgroundDomainMarkers = (Map) ObjectUtilities.clone(this.backgroundDomainMarkers);
    clone.foregroundRangeMarkers = (Map) ObjectUtilities.clone(this.foregroundRangeMarkers);
    clone.backgroundRangeMarkers = (Map) ObjectUtilities.clone(this.backgroundRangeMarkers);
    clone.annotations = (List) ObjectUtilities.deepClone(this.annotations);
    if (this.fixedDomainAxisSpace != null) {
        clone.fixedDomainAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedDomainAxisSpace);
    }
    if (this.fixedRangeAxisSpace != null) {
        clone.fixedRangeAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedRangeAxisSpace);
    }
    return clone;

}