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

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

Introduction

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

Prototype

public void setLabelPaint(Paint paint) 

Source Link

Document

Sets the paint used to draw the axis label and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java

/**
 * Creates a chart for the specified dataset.
 * /* www .java2  s  .  co  m*/
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");

    JFreeChart chart = null;

    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    if (xLowerBound != null && xUpperBound != null) {
        xAxis.setLowerBound(xLowerBound);
        xAxis.setUpperBound(xUpperBound);
    } else {
        xAxis.setAutoRange(true);
    }
    xAxis.setAxisLinePaint(Color.white);
    xAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    NumberAxis yAxis = new NumberAxis(yLabel);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (yLowerBound != null && yUpperBound != null) {
        yAxis.setLowerBound(yLowerBound);
        yAxis.setUpperBound(yUpperBound);
    } else
        yAxis.setAutoRange(true);

    yAxis.setAxisLinePaint(Color.white);
    yAxis.setTickMarkPaint(Color.white);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    XYBlockRenderer renderer = new XYBlockRenderer();

    PaintScale paintScale = null;

    if (grayPaintScale) {
        paintScale = new GrayPaintScale(minScaleValue, maxScaleValue);
    } else {
        if (scaleLowerBound != null && scaleUpperBound != null) {
            paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray);
        } else {
            paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray);
        }
        for (int i = 0; i < zRangeArray.length; i++) {
            ZRange zRange = zRangeArray[i];
            ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor());

        }
    }

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    plot.setForegroundAlpha(0.66f);

    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.removeLegend();

    NumberAxis scaleAxis = new NumberAxis(zLabel);
    scaleAxis.setAxisLinePaint(Color.white);
    scaleAxis.setTickMarkPaint(Color.white);
    scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7));
    if (scaleLowerBound != null && scaleUpperBound != null) {
        scaleAxis.setLowerBound(scaleLowerBound);
        scaleAxis.setUpperBound(scaleUpperBound);
    } else
        scaleAxis.setAutoRange(true);

    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        scaleAxis.setLabelFont(addLabelsStyle.getFont());
        scaleAxis.setLabelPaint(addLabelsStyle.getColor());
    }

    if (blockHeight != null && blockWidth != null) {
        renderer.setBlockWidth(blockWidth.doubleValue());
        renderer.setBlockHeight(blockHeight.doubleValue());
    }

    PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis);
    legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    legend.setAxisOffset(5.0);
    legend.setMargin(new RectangleInsets(5, 5, 5, 5));
    legend.setFrame(new BlockBorder(Color.black));
    legend.setPadding(new RectangleInsets(10, 10, 10, 10));
    legend.setStripWidth(10);
    legend.setPosition(RectangleEdge.RIGHT);
    legend.setBackgroundPaint(color);

    chart.addSubtitle(legend);

    //      chart.setBackgroundPaint(new Color(180, 180, 250));   
    chart.setBackgroundPaint(color);

    logger.debug("OUT");
    return chart;
}

From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java

protected void resetRenderer(final IScope scope, final String serieid) {
    final XYBlockRenderer newr = (XYBlockRenderer) this.getOrCreateRenderer(scope, serieid);

    // newr.setSeriesStroke(0, new BasicStroke(0));
    final ChartDataSeries myserie = this.getChartdataset().getDataSeries(scope, serieid);

    if (myserie.getMycolor() != null) {
        newr.setSeriesPaint(0, myserie.getMycolor());
    }/*from  w  w  w . j a va  2s .  c  o m*/
    if (myserie.getSValues(scope).size() > 0) {
        final double maxval = Collections.max(myserie.getSValues(scope));
        final double minval = Collections.min(myserie.getSValues(scope));
        Color cdeb = new Color(0, 0, 0, 0);
        if (myserie.getMyMincolor() != null)
            cdeb = myserie.getMyMincolor();
        Color cend = new Color(0.9f, 0.9f, 0.9f, 1.0f);
        if (myserie.getMycolor() != null)
            cend = myserie.getMycolor();

        LookupPaintScale paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, cend);
        if (myserie.getMyMedcolor() != null)
            paintscale = createLUT(100, (float) minval, (float) maxval, cdeb, myserie.getMyMedcolor(), cend);

        newr.setPaintScale(paintscale);

        final NumberAxis scaleAxis = new NumberAxis(myserie.getName());
        scaleAxis.setAxisLinePaint(this.axesColor);
        scaleAxis.setTickMarkPaint(this.axesColor);
        scaleAxis.setTickLabelFont(this.getTickFont());
        scaleAxis.setRange(minval, maxval);
        scaleAxis.setAxisLinePaint(axesColor);
        scaleAxis.setLabelFont(getLabelFont());
        if (textColor != null) {
            scaleAxis.setLabelPaint(textColor);
            scaleAxis.setTickLabelPaint(textColor);
        }
        if (!this.getXTickValueVisible(scope)) {
            scaleAxis.setTickMarksVisible(false);
            scaleAxis.setTickLabelsVisible(false);

        }

        final PaintScaleLegend legend = new PaintScaleLegend(paintscale, scaleAxis);
        legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
        legend.setAxisOffset(5.0);
        // legend.setMargin(new RectangleInsets(5, 5, 5, 5));
        // legend.setFrame(new BlockBorder(Color.red));
        // legend.setPadding(new RectangleInsets(10, 10, 10, 10));
        // legend.setStripWidth(10);
        legend.setPosition(RectangleEdge.RIGHT);
        legend.setBackgroundPaint(this.backgroundColor);
        // ArrayList<PaintScaleLegend> caxe=new
        // ArrayList<PaintScaleLegend>();
        // caxe.add(legend);
        // chart.setSubtitles(caxe);
        if (!this.series_label_position.equals("none"))
            chart.addSubtitle(legend);

    }
}

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

/**
 * Inherited by IChart./*from  w  ww  .j a  v  a2  s.c  o  m*/
 * 
 * @param chartTitle the chart title
 * @param dataset the dataset
 * 
 * @return the j free chart
 */

public JFreeChart createChart(DatasetMap datasets) {

    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    logger.debug("Get plot orientaton");
    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }

    JFreeChart chart = ChartFactory.createStackedBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // the plot orientation
            legend, // legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(color);
    plot.setRangeGridlinePaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    int numElForGroup = 0;
    for (int idx = 0; idx < numGroups.intValue(); idx++) {
        for (int j = 0; j < numSerieForGroup.intValue(); j++) {
            try {
                String tmpSubCat = (String) subCategoryNames.get(j + idx * numSerieForGroup.intValue());
                map.mapKeyToGroup(tmpSubCat, "G" + (idx + 1));

            } catch (Exception e) {
                logger.error("out of range error in inserting in stacked bar group: continue anayway", e);
            }
        }
    }

    renderer.setSeriesToGroupMap(map);
    renderer.setItemMargin(0.0);
    renderer.setDrawBarOutline(false);
    renderer.setBaseItemLabelsVisible(true);
    if (percentageValue)
        renderer.setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}", new DecimalFormat("#,##.#%")));
    else
        renderer.setBaseItemLabelGenerator(new FilterZeroStandardCategoryItemLabelGenerator());
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    if (maxBarWidth != null) {
        renderer.setMaximumBarWidth(maxBarWidth.doubleValue());
    }

    boolean document_composition = false;
    if (mode.equalsIgnoreCase(SpagoBIConstants.DOCUMENT_COMPOSITION))
        document_composition = true;

    /*
    MyCategoryUrlGenerator mycatUrl=new MyCategoryUrlGenerator(rootUrl);
    mycatUrl.setDocument_composition(document_composition);
    mycatUrl.setCategoryUrlLabel(categoryUrlName);
    mycatUrl.setSerieUrlLabel(serieUrlname);
            
    renderer.setItemURLGenerator(mycatUrl);
     */

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

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(color);

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setLabelPaint(styleXaxesLabels.getColor());
    rangeAxis
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setNumberFormatOverride(nf);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    if (rangeAxisLocation != null) {
        if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
        } else if (rangeAxisLocation.equalsIgnoreCase("BOTTOM_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_RIGHT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_RIGHT);
        } else if (rangeAxisLocation.equalsIgnoreCase("TOP_OR_LEFT")) {
            plot.setRangeAxisLocation(0, AxisLocation.TOP_OR_LEFT);
        }
    }

    int seriesN = dataset.getRowCount();
    int numSerieColored = 0;

    if (orderColorVector != null && orderColorVector.size() > 0) {
        logger.debug("color serie by SERIES_ORDER_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            if (orderColorVector.get(i) != null) {
                Color color = orderColorVector.get(i);
                renderer.setSeriesPaint(i, color);
            }
        }
    } else if (colorMap != null) {
        while (numSerieColored < seriesN) {
            for (int i = 1; i <= colorMap.size(); i++) {
                Color color = (Color) colorMap.get("SER" + i);
                Color gradient = new Color(Integer.decode("#FFFFFF").intValue());
                if (gradientMap != null)
                    gradient = (Color) gradientMap.get("SER" + i);

                if (color != null) {
                    Paint p = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, gradient);

                    //renderer.setSeriesPaint(numSerieColored, color);
                    renderer.setSeriesPaint(numSerieColored, p);
                }
                numSerieColored++;
            }
        }
    }
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

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

        double orient = (-Math.PI / 2.0);
        if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
            orient = 0.0;
        }
        renderer.setBaseItemLabelFont(
                new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
        renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

        renderer.setBaseItemLabelGenerator(generator);
        renderer.setBaseItemLabelsVisible(true);
        //vertical labels          
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));
        renderer.setBaseNegativeItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, orient));

        //horizontal labels
        /*
        renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
           ItemLabelAnchor.CENTER, TextAnchor.CENTER));
        renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
           ItemLabelAnchor.CENTER, TextAnchor.CENTER));
         */

    }

    SubCategoryAxis domainAxis = new SubCategoryAxis(categoryLabel + " / " + subCategoryLabel);
    String subCatLabel = "";
    for (int j = 1; j <= numGroups.intValue(); j++) {
        if (subCatLabelsMap != null)
            subCatLabel = (String) subCatLabelsMap.get("CAT" + j);
        else
            subCatLabel = subCategoryLabel;

        domainAxis.addSubCategory(subCatLabel);
        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());
    }
    plot.setDomainAxis(domainAxis);
    plot.setRenderer(renderer);

    /*
    domainAxis.setCategoryLabelPositions(
    CategoryLabelPositions.createUpRotationLabelPositions(
          Math.PI / 6.0));
     */
    if (legend == true)
        drawLegend(chart);
    logger.debug("OUT");
    return chart;

}

From source file:edu.wisc.ssec.mcidasv.control.McIDASVHistogramWrapper.java

/**
 * Assumes that {@code data} has been validated and is okay to actually try
 * loading.//from w w w .ja v  a2s. c om
 *
 * @param data Data to use in histogram. Cannot be {@code null} or all NaNs.
 *
 * @throws VisADException
 * @throws RemoteException
 */
private void reallyLoadData(FlatField data) throws VisADException, RemoteException {
    createChart();
    List dataChoiceWrappers = getDataChoiceWrappers();

    try {
        clearHistogram();

        Hashtable props = new Hashtable();
        ErrorEstimate[] errOut = new ErrorEstimate[1];
        for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) {
            DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);

            DataChoice dataChoice = wrapper.getDataChoice();
            props = dataChoice.getProperties();
            Unit defaultUnit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0];
            Unit unit = ((DisplayControlImpl) imageControl).getDisplayUnit();
            double[][] samples = data.getValues(false);
            double[] actualValues = filterData(samples[0], getTimeValues(samples, data))[0];
            if ((defaultUnit != null) && !defaultUnit.equals(unit)) {
                actualValues = Unit.transformUnits(unit, errOut, defaultUnit, null, actualValues);
            }
            final NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit));

            domainAxis.setAutoRangeIncludesZero(false);

            XYItemRenderer renderer;
            if (getStacked()) {
                renderer = new StackedXYBarRenderer();
            } else {
                renderer = new XYBarRenderer();
            }
            if ((plot == null) && (chartPanel != null)) {
                plot = chartPanel.getChart().getXYPlot();
            }
            plot.setRenderer(paramIdx, renderer);
            Color c = wrapper.getColor(paramIdx);
            domainAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);

            MyHistogramDataset dataset = new MyHistogramDataset();
            dataset.setType(HistogramType.FREQUENCY);
            dataset.addSeries(dataChoice.getName() + " [" + unit + ']', actualValues, getBins());
            samples = null;
            actualValues = null;
            plot.setDomainAxis(paramIdx, domainAxis, false);
            plot.mapDatasetToDomainAxis(paramIdx, paramIdx);
            plot.setDataset(paramIdx, dataset);

            domainAxis.addChangeListener(new AxisChangeListener() {
                public void axisChanged(AxisChangeEvent ae) {
                    if (!imageControl.isInitDone()) {
                        return;
                    }

                    Range range = domainAxis.getRange();
                    double newLow = Math.floor(range.getLowerBound() + 0.5);
                    double newHigh = Math.floor(range.getUpperBound() + 0.5);
                    double prevLow = getLow();
                    double prevHigh = getHigh();
                    try {
                        ucar.unidata.util.Range newRange;
                        if (prevLow > prevHigh) {
                            newRange = new ucar.unidata.util.Range(newHigh, newLow);
                        } else {
                            newRange = new ucar.unidata.util.Range(newLow, newHigh);
                        }
                        ((DisplayControlImpl) imageControl).setRange(newRange);
                    } catch (Exception e) {
                        logger.error("Cannot change range", e);
                    }
                }
            });

            Range range = domainAxis.getRange();
            low = range.getLowerBound();
            high = range.getUpperBound();
        }

    } catch (Exception exc) {
        System.out.println("Exception exc=" + exc);
        LogUtil.logException("Error creating data set", exc);
    }
}

From source file:com.rapidminer.gui.plotter.charts.MultipleSeriesChartPlotter.java

private JFreeChart createChart() {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );//  w w  w .  j  a  v  a2 s .c  o m

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    // domain axis

    if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
        if ((dataTable.isDate(indexAxis)) || (dataTable.isDateTime(indexAxis))) {
            DateAxis domainAxis = new DateAxis(dataTable.getColumnName(indexAxis));
            domainAxis.setTimeZone(Tools.getPreferredTimeZone());
            chart.getXYPlot().setDomainAxis(domainAxis);
        }
    } else {
        plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeStickyZero(false);
        ((NumberAxis) plot.getDomainAxis()).setAutoRangeIncludesZero(false);
    }
    ValueAxis xAxis = plot.getDomainAxis();
    if (indexAxis > -1) {
        xAxis.setLabel(getDataTable().getColumnName(indexAxis));
    } else {
        xAxis.setLabel(SERIESINDEX_LABEL);
    }
    xAxis.setAutoRange(true);
    xAxis.setLabelFont(LABEL_FONT_BOLD);
    xAxis.setTickLabelFont(LABEL_FONT);
    xAxis.setVerticalTickLabels(isLabelRotating());
    if (indexAxis > 0) {
        if (getRangeForDimension(indexAxis) != null) {
            xAxis.setRange(getRangeForDimension(indexAxis));
        }
    } else {
        if (getRangeForName(SERIESINDEX_LABEL) != null) {
            xAxis.setRange(getRangeForName(SERIESINDEX_LABEL));
        }
    }

    // renderer and range axis
    synchronized (dataTable) {
        int numberOfSelectedColumns = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    numberOfSelectedColumns++;
                }
            }
        }

        int columnCount = 0;
        for (int c = 0; c < dataTable.getNumberOfColumns(); c++) {
            if (getPlotColumn(c)) {
                if (dataTable.isNumerical(c)) {
                    // YIntervalSeries series = new
                    // YIntervalSeries(this.dataTable.getColumnName(c));
                    XYSeriesCollection dataset = new XYSeriesCollection();
                    XYSeries series = new XYSeries(dataTable.getColumnName(c));
                    Iterator<DataTableRow> i = dataTable.iterator();
                    int index = 1;
                    while (i.hasNext()) {
                        DataTableRow row = i.next();
                        double value = row.getValue(c);

                        if ((indexAxis >= 0) && (!dataTable.isNominal(indexAxis))) {
                            double indexValue = row.getValue(indexAxis);
                            series.add(indexValue, value);
                        } else {
                            series.add(index++, value);
                        }
                    }
                    dataset.addSeries(series);

                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

                    Color color = getColorProvider().getPointColor(1.0d);
                    if (numberOfSelectedColumns > 1) {
                        color = getColorProvider()
                                .getPointColor(columnCount / (double) (numberOfSelectedColumns - 1));
                    }
                    renderer.setSeriesPaint(0, color);
                    renderer.setSeriesStroke(0,
                            new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
                    renderer.setSeriesShapesVisible(0, false);

                    NumberAxis yAxis = new NumberAxis(dataTable.getColumnName(c));
                    if (getRangeForDimension(c) != null) {
                        yAxis.setRange(getRangeForDimension(c));
                    } else {
                        yAxis.setAutoRange(true);
                        yAxis.setAutoRangeStickyZero(false);
                        yAxis.setAutoRangeIncludesZero(false);
                    }
                    yAxis.setLabelFont(LABEL_FONT_BOLD);
                    yAxis.setTickLabelFont(LABEL_FONT);
                    if (numberOfSelectedColumns > 1) {
                        yAxis.setAxisLinePaint(color);
                        yAxis.setTickMarkPaint(color);
                        yAxis.setLabelPaint(color);
                        yAxis.setTickLabelPaint(color);
                    }

                    plot.setRangeAxis(columnCount, yAxis);
                    plot.setRangeAxisLocation(columnCount, AxisLocation.TOP_OR_LEFT);

                    plot.setDataset(columnCount, dataset);
                    plot.setRenderer(columnCount, renderer);
                    plot.mapDatasetToRangeAxis(columnCount, columnCount);

                    columnCount++;
                }
            }
        }
    }

    chart.setBackgroundPaint(Color.white);

    return chart;
}

From source file:ucar.unidata.idv.control.McVHistogramWrapper.java

/**
 * Assumes that {@code data} has been validated and is okay to actually try
 * loading./*from ww w . j  a v  a2 s .c o  m*/
 *
 * @param data Data to use in histogram. Cannot be {@code null} or all NaNs.
 *
 * @throws VisADException
 * @throws RemoteException
 */
private void reallyLoadData(FlatField data) throws VisADException, RemoteException {
    createChart();
    List dataChoiceWrappers = getDataChoiceWrappers();

    try {
        clearHistogram();

        ErrorEstimate[] errOut = new ErrorEstimate[1];
        for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) {
            DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);

            DataChoice dataChoice = wrapper.getDataChoice();
            Unit defaultUnit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0];
            Unit unit = ((DisplayControlImpl) imageControl).getDisplayUnit();
            double[][] samples = data.getValues(false);
            double[] actualValues = filterData(samples[0], getTimeValues(samples, data))[0];
            if ((defaultUnit != null) && !defaultUnit.equals(unit)) {
                actualValues = Unit.transformUnits(unit, errOut, defaultUnit, null, actualValues);
            }
            final NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit));

            domainAxis.setAutoRangeIncludesZero(false);

            XYItemRenderer renderer;
            if (getStacked()) {
                renderer = new StackedXYBarRenderer();
            } else {
                renderer = new XYBarRenderer();
            }
            if ((plot == null) && (chartPanel != null)) {
                plot = chartPanel.getChart().getXYPlot();
            }
            plot.setRenderer(paramIdx, renderer);
            Color c = wrapper.getColor(paramIdx);
            domainAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);

            MyHistogramDataset dataset = new MyHistogramDataset();
            dataset.setType(HistogramType.FREQUENCY);
            dataset.addSeries(dataChoice.getName() + " [" + unit + ']', actualValues, getBins());
            samples = null;
            actualValues = null;
            plot.setDomainAxis(paramIdx, domainAxis, false);
            plot.mapDatasetToDomainAxis(paramIdx, paramIdx);
            plot.setDataset(paramIdx, dataset);

            domainAxis.addChangeListener(new AxisChangeListener() {
                public void axisChanged(AxisChangeEvent ae) {
                    if (!imageControl.isInitDone()) {
                        return;
                    }

                    Range range = domainAxis.getRange();
                    double newLow = Math.floor(range.getLowerBound() + 0.5);
                    double newHigh = Math.floor(range.getUpperBound() + 0.5);
                    double prevLow = getLow();
                    double prevHigh = getHigh();
                    try {
                        ucar.unidata.util.Range newRange;
                        if (prevLow > prevHigh) {
                            newRange = new ucar.unidata.util.Range(newHigh, newLow);
                        } else {
                            newRange = new ucar.unidata.util.Range(newLow, newHigh);
                        }
                        ((DisplayControlImpl) imageControl).setRange(newRange);
                    } catch (Exception e) {
                        logger.error("Cannot change range", e);
                    }
                }
            });

            Range range = domainAxis.getRange();
            low = range.getLowerBound();
            high = range.getUpperBound();
        }

    } catch (Exception exc) {
        System.out.println("Exception exc=" + exc);
        LogUtil.logException("Error creating data set", exc);
    }
}

From source file:uk.co.moonsit.sockets.GraphClient.java

private NumberAxis getTheRangeAxis(int index) {//, DatasetAndAxis[] dAnda) {
    //if (dAnda[index].numberAxisObj !=null) {
    //  return dAnda[index].numberAxisObj;
    //}//from w w w .  j a v  a 2 s  . com

    NumberAxis rangeAxis;
    Color axisColor = getAxisColor(index);
    String axisLabel = "Range";
    if (index > 0) {
        axisLabel += "-" + (index + 1);
    }
    rangeAxis = new NumberAxis(axisLabel);
    rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 9));
    rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    // rangeAxis.setRange(new Range(0,0)); // need to set a range or we get a NaN on getRange() calls
    //rangeAxis.setAutoRange(false);
    rangeAxis.setAutoRangeIncludesZero(false);

    // set colors
    rangeAxis.setLabelPaint(axisColor);
    rangeAxis.setAxisLinePaint(axisColor);
    rangeAxis.setLabelPaint(axisColor);
    rangeAxis.setTickLabelPaint(axisColor);
    rangeAxis.setTickMarkPaint(axisColor);
    //dAnda[index].numberAxisObj=rangeAxis;
    return rangeAxis;
}

From source file:com.chart.SwingChart.java

/**
 * Update background, tick and gridline colors
 * @param cfg cfg[0] Background, cfg[1] Chart background, cfg[2] y cfg[3] gridline
 *//*w  w w.  jav a  2 s  .  c om*/
public void updateChartColors(String[] cfg) {
    strBackgroundColor = cfg[0];
    for (Node le : legendFrame.getChildren()) {
        if (le instanceof LegendAxis) {
            le.setStyle("-fx-background-color:" + strBackgroundColor);
            ((LegendAxis) le).selected = false;
        }
    }
    chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));
    chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)))));
    chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));

    legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;");

    strChartBackgroundColor = cfg[1];
    ;
    plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor)));

    for (Node le : legendFrame.getChildren()) {
        if (le instanceof LegendAxis) {
            le.setStyle("-fx-background-color:" + strBackgroundColor);
            ((LegendAxis) le).selected = false;
            for (Node nn : ((LegendAxis) le).getChildren()) {
                if (nn instanceof Label) {
                    ((Label) nn).setStyle("fondo: " + strChartBackgroundColor
                            + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                            + String.valueOf(fontSize) + "px");
                }
            }
        }
    }

    strGridlineColor = cfg[2];
    ;
    plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));
    plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));

    strTickColor = cfg[3];
    ;
    abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    for (NumberAxis ejeOrdenada : AxesList) {
        ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
        ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    }
}

From source file:com.chart.SwingChart.java

/**
 * Add axis//from w  w  w .j  a  v a  2s . c  o m
 * @param name new axis name 
 */
@Override
public final void addAxis(String name) {
    boolean encontrado = false;
    for (AxisChart categoria : axes) {
        if (categoria.getName().equals(name)) {
            encontrado = true;
            break;
        }
    }
    if (!encontrado) {
        axes.add(new AxisChart((name)));
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    NumberAxis ejeOrdenada = new NumberAxis(name);

    ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    ejeOrdenada.setLabelFont(ejeOrdenada.getLabelFont().deriveFont(fontSize));
    ejeOrdenada.setTickLabelFont(ejeOrdenada.getLabelFont().deriveFont(fontSize));

    int i = datasetList.size();

    datasetList.add(dataset);
    AxesList.add(ejeOrdenada);
    plot.setDataset(i, dataset);
    plot.setRangeAxis(i, ejeOrdenada);
    plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT);
    plot.mapDatasetToRangeAxis(i, i);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, true);
    if (i == 0) {
        plot.setRenderer(renderer);
    } else {
        plot.setRenderer(i, renderer);
    }

    final LegendAxis le;
    final int indiceLeyenda = legendFrame.getChildren().size();

    legendFrame.getChildren().add(le = new LegendAxis(name));

    le.setOnMouseClicked((MouseEvent t) -> {
        if (le.selected && t.getClickCount() == 2) {
            setOrdinateRange(AxesList.get(indiceLeyenda));
        }
    });

    le.setOnMouseEntered((MouseEvent t) -> {
        le.setStyle("-fx-background-color:blue");
        le.selected = true;
        AxesList.get(indiceLeyenda).setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web("blue")));
        AxesList.get(indiceLeyenda).setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web("blue")));
    });

    le.setOnMouseExited((MouseEvent t) -> {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        le.selected = false;
        AxesList.get(indiceLeyenda).setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
        AxesList.get(indiceLeyenda)
                .setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    });
}