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:srvclientmonitor.frmMain.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    JPanel panel = new JPanel();
    getContentPane().add(panel);//  ww  w .j a  va2 s  .  co  m
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    //DefaultPieDataset data = new DefaultPieDataset();  //Para el Grafico PIE

    data.addValue(20, "OSP", "HOY");
    data.addValue(99, "ETL", "HOY");
    data.addValue(25, "LOR", "HOY");
    data.addValue(12, "MOV", "HOY");

    // Creando el Grafico
    //JFreeChart chart = ChartFactory.createPieChart(
    //JFreeChart chart = ChartFactory.createBarChart("Ejemplo Rapido de Grafico en un ChartFrame", "Mes", "Valor", data);

    JFreeChart chart = ChartFactory.createBarChart("", "", "", data, PlotOrientation.VERTICAL, false, false,
            false);
    chart.setBackgroundPaint(Color.BLACK);
    chart.setTitle("");

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRangePannable(true);
    plot.setRangeGridlinesVisible(false);
    plot.setBackgroundAlpha(1);
    plot.setBackgroundPaint(Color.BLACK);
    plot.setForegroundAlpha(1);
    plot.setDomainCrosshairPaint(Color.WHITE);
    plot.setNoDataMessagePaint(Color.WHITE);
    plot.setOutlinePaint(Color.WHITE);
    plot.setRangeCrosshairPaint(Color.WHITE);
    plot.setRangeMinorGridlinePaint(Color.WHITE);
    plot.setRangeZeroBaselinePaint(Color.WHITE);

    //        Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green);
    //        plot.setBackgroundPaint(p);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLabelPaint(Color.WHITE);
    rangeAxis.setAxisLinePaint(Color.WHITE);
    rangeAxis.setTickLabelPaint(Color.WHITE);
    rangeAxis.setVerticalTickLabels(true);

    //ChartUtilities.applyCurrentTheme(chart);

    // Crear el Panel del Grafico con ChartPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(300, 150);
    chartPanel.setBackground(Color.BLACK);
    chartPanel.setOpaque(false);
    chartPanel.setDomainZoomable(true);
    this.jPanel1.setSize(300, 200);
    this.jPanel1.setBackground(Color.DARK_GRAY);
    this.jPanel1.add(chartPanel);

}

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

/**
 * Creates a chart for the specified dataset.
 * /*from w ww .j av a  2s .c  o m*/
 * @param dataset  the dataset.
 * 
 * @return A chart instance.
 */
public JFreeChart createChart(DatasetMap datasets) {
    XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1");
    //Creates the xAxis with its label and style
    NumberAxis xAxis = new NumberAxis(xLabel);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    xAxis.setLabel(xLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        xAxis.setLabelFont(addLabelsStyle.getFont());
        xAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    //Creates the yAxis with its label and style
    NumberAxis yAxis = new NumberAxis(yLabel);

    yAxis.setAutoRangeIncludesZero(false);
    yAxis.setInverted(false);
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    yAxis.setTickLabelsVisible(true);
    yAxis.setLabel(yLabel);
    if (addLabelsStyle != null && addLabelsStyle.getFont() != null) {
        yAxis.setLabelFont(addLabelsStyle.getFont());
        yAxis.setLabelPaint(addLabelsStyle.getColor());
    }
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    Color outboundCol = new Color(Integer.decode(outboundColor).intValue());

    //Sets the graph paint scale and the legend paintscale
    LookupPaintScale paintScale = new LookupPaintScale(zvalues[0], (new Double(zrangeMax)).doubleValue(),
            outboundCol);
    LookupPaintScale legendPaintScale = new LookupPaintScale(0.5, 0.5 + zvalues.length, outboundCol);

    for (int ke = 0; ke <= (zvalues.length - 1); ke++) {
        Double key = (new Double(zvalues[ke]));
        Color temp = (Color) colorRangeMap.get(key);
        paintScale.add(zvalues[ke], temp);
        legendPaintScale.add(0.5 + ke, temp);
    }
    //Configures the renderer
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setPaintScale(paintScale);
    double blockHeight = (new Double(blockH)).doubleValue();
    double blockWidth = (new Double(blockW)).doubleValue();
    renderer.setBlockWidth(blockWidth);
    renderer.setBlockHeight(blockHeight);

    //configures the plot with title, subtitle, axis ecc.
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setDomainCrosshairPaint(Color.black);

    plot.setForegroundAlpha(0.66f);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));
    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.removeLegend();
    chart.setBackgroundPaint(Color.white);

    //Sets legend labels
    SymbolAxis scaleAxis = new SymbolAxis(null, legendLabels);
    scaleAxis.setRange(0.5, 0.5 + zvalues.length);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    scaleAxis.setLabel(zLabel);
    //scaleAxis.setLabelAngle(3.14/2);
    scaleAxis.setLabelFont(addLabelsStyle.getFont());
    scaleAxis.setLabelPaint(addLabelsStyle.getColor());

    //draws legend as chart subtitle
    PaintScaleLegend psl = new PaintScaleLegend(legendPaintScale, scaleAxis);
    psl.setAxisOffset(2.0);
    psl.setPosition(RectangleEdge.RIGHT);
    psl.setMargin(new RectangleInsets(5, 1, 5, 1));
    chart.addSubtitle(psl);

    if (yLabels != null) {
        //Sets y legend labels
        LookupPaintScale legendPaintScale2 = new LookupPaintScale(0, (yLabels.length - 1), Color.white);

        for (int ke = 0; ke < yLabels.length; ke++) {
            Color temp = Color.white;
            legendPaintScale2.add(1 + ke, temp);
        }

        SymbolAxis scaleAxis2 = new SymbolAxis(null, yLabels);
        scaleAxis2.setRange(0, (yLabels.length - 1));
        scaleAxis2.setPlot(new PiePlot());
        scaleAxis2.setGridBandsVisible(false);

        //draws legend as chart subtitle
        PaintScaleLegend psl2 = new PaintScaleLegend(legendPaintScale2, scaleAxis2);
        psl2.setAxisOffset(5.0);
        psl2.setPosition(RectangleEdge.LEFT);
        psl2.setMargin(new RectangleInsets(8, 1, 40, 1));
        psl2.setStripWidth(0);
        psl2.setStripOutlineVisible(false);
        chart.addSubtitle(psl2);
    }

    return chart;
}

From source file:no.met.jtimeseries.MeteogramWrapper.java

private void plotPressure(GenericDataModel model, ChartPlotter plotter) {

    NumberPhenomenon pressure = model.getNumberPhenomenon(PhenomenonName.Pressure.toString());
    Color pressureColor = new Color(11, 164, 42);
    // number axis to be used for pressure plot
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(pressureColor);
    numberAxis.setTickLabelPaint(pressureColor);
    numberAxis.setLabel(messages.getString("parameter.pressure") + " (hPa)");
    double lowBound = 950;
    double upperBound = 1050;
    numberAxis.setLowerBound(lowBound);//from  www. j  a  v  a  2s  . com
    numberAxis.setUpperBound(upperBound);
    double tickUnit = (upperBound - lowBound) / BACKGROUND_LINES;
    numberAxis.setTickUnit(new NumberTickUnit(tickUnit));

    PlotStyle plotStyle = new PlotStyle.Builder("Pressure (hPa)").seriesColor(pressureColor)
            .plusDegreeColor(pressureColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(1.3f))
            .numberAxis(numberAxis).build();
    plotter.addThresholdLineChart(TimeBase.SECOND, pressure, plotStyle);
}

From source file:no.met.jtimeseries.MeteogramWrapper.java

private void plotTemperature(GenericDataModel model, ChartPlotter plotter) {

    NumberPhenomenon temperature = model.getNumberPhenomenon(PhenomenonName.AirTemperature.toString());
    Color temperatureColor = Color.RED;
    // number axis to be used for wind speed plot
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(temperatureColor);
    numberAxis.setTickLabelPaint(temperatureColor);
    numberAxis.setLabel(messages.getString("parameter.airTemperature") + " (\u00B0 C)");
    double maxValue = temperature.getMaxValue();
    double minValue = temperature.getMinValue();

    ChartPlotter.setAxisBound(numberAxis, maxValue, minValue, 8, BACKGROUND_LINES);

    PlotStyle plotStyle = new PlotStyle.Builder("AirTemperature").seriesColor(temperatureColor)
            .plusDegreeColor(temperatureColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f))
            .numberAxis(numberAxis).build();

    plotter.addThresholdLineChart(TimeBase.SECOND, temperature, plotStyle);

}

From source file:no.met.jtimeseries.MeteogramWrapper.java

private void plotDewPointTemperature(GenericDataModel model, ChartPlotter plotter) {

    NumberPhenomenon temperature = model.getNumberPhenomenon(PhenomenonName.dewPointTemperature.toString());
    if (temperature == null)
        throw new NullPointerException(
                "Missing parameter [" + messages.getString("parameter.dewPointTemperature") + "]");
    Color temperatureColor = Color.ORANGE;
    // number axis to be used for wind speed plot
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(temperatureColor);
    numberAxis.setTickLabelPaint(temperatureColor);
    numberAxis.setLabel(messages.getString("parameter.dewPointTemperature") + " (\u00B0 C)");
    double maxValue = temperature.getMaxValue();
    double minValue = temperature.getMinValue();

    ChartPlotter.setAxisBound(numberAxis, maxValue, minValue, 8, BACKGROUND_LINES);

    PlotStyle plotStyle = new PlotStyle.Builder("Dew point").seriesColor(temperatureColor)
            .plusDegreeColor(temperatureColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f))
            .numberAxis(numberAxis).build();

    plotter.addLineChart(TimeBase.SECOND, temperature, plotStyle);

}

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

/**
 * Create the charts/*from w  ww .j  ava  2s . co  m*/
 *
 * @throws RemoteException On badness
 * @throws VisADException On badness
 */
public void loadData() throws VisADException, RemoteException {

    try {
        createChart();
        for (int dataSetIdx = 0; dataSetIdx < plot.getDatasetCount(); dataSetIdx++) {
            XYSeriesCollection dataset = (XYSeriesCollection) plot.getDataset(dataSetIdx);
            dataset.removeAllSeries();
        }
        ((MyScatterPlot) plot).removeAllSeries();
        Hashtable props = new Hashtable();
        props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE);

        List dataChoiceWrappers = getDataChoiceWrappers();
        int dataSetCnt = 0;
        for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx += 2) {
            if (paramIdx + 1 >= dataChoiceWrappers.size()) {
                break;
            }
            DataChoiceWrapper wrapper1 = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);
            DataChoiceWrapper wrapper2 = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx + 1);

            DataChoice dataChoice1 = wrapper1.getDataChoice();
            DataChoice dataChoice2 = wrapper2.getDataChoice();

            FlatField data1 = getFlatField((FieldImpl) dataChoice1.getData(null, props));
            FlatField data2 = getFlatField((FieldImpl) dataChoice2.getData(null, props));
            Unit unit1 = ucar.visad.Util.getDefaultRangeUnits((FlatField) data1)[0];
            Unit unit2 = ucar.visad.Util.getDefaultRangeUnits((FlatField) data2)[0];

            NumberAxis rangeAxis = new NumberAxis(wrapper2.getLabel(unit2));
            NumberAxis domainAxis = new NumberAxis(wrapper1.getLabel(unit1));

            domainAxis.setAutoRange(getAutoRange());

            Color c = wrapper1.getColor(paramIdx);
            MyRenderer renderer = new MyRenderer(wrapper1.getLineState().getShape());
            domainAxis.setLabelPaint(c);
            rangeAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);

            double[][] samples1 = data1.getValues(false);
            double[][] samples2 = data2.getValues(false);
            double[] timeValues1 = getTimeValues(samples1, data1);
            double[] timeValues2 = getTimeValues(samples2, data2);
            double[][] values1 = filterData(samples1[0], timeValues1);
            double[][] values2 = filterData(samples2[0], timeValues2);
            if (values1.length > 1) {
                this.timeValues1 = values1[1];
                this.timeValues2 = values2[1];
            }
            double[][] values = { values1[0], values2[0] };
            ((MyScatterPlot) plot).addSeries(values);

            //Add in a dummy dataset
            XYSeriesCollection dataset = new XYSeriesCollection(new XYSeries(""));

            if (!getAutoRange()) {
                NumberAxis oldRangeAxis = (NumberAxis) plot.getRangeAxis(dataSetCnt);
                NumberAxis oldDomainAxis = (NumberAxis) plot.getDomainAxis(dataSetCnt);
                if ((oldRangeAxis != null) && (oldDomainAxis != null)) {
                    rangeAxis.setRange(oldRangeAxis.getRange());
                    domainAxis.setRange(oldDomainAxis.getRange());
                }
            }

            plot.setDataset(dataSetCnt, dataset);
            plot.setRenderer(dataSetCnt, renderer);
            plot.setRangeAxis(dataSetCnt, rangeAxis, false);
            plot.setDomainAxis(dataSetCnt, domainAxis, false);
            plot.mapDatasetToRangeAxis(dataSetCnt, dataSetCnt);
            plot.mapDatasetToDomainAxis(dataSetCnt, dataSetCnt);

            if (!getAutoRange()) {
                rangeAxis.setAutoRange(false);
                domainAxis.setAutoRange(false);
            }

            dataSetCnt++;
        }
    } catch (Exception exc) {
        LogUtil.logException("Error creating data set", exc);
    }

}

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

public JFreeChart createChart(DatasetMap datasets) {

    // 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/*from   ww w.  j a v  a  2  s  .  c om*/
            .setTickLabelFont(new Font(styleXaxesLabels.getFontName(), Font.PLAIN, styleXaxesLabels.getSize()));
    rangeAxis.setTickLabelPaint(styleXaxesLabels.getColor());
    rangeAxis.setNumberFormatOverride(nf);
    plot.setRangeAxis(rangeAxis);
    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    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());
    plot.setDomainAxis(domainAxis);

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

    DefaultCategoryDataset datasetBar = (DefaultCategoryDataset) datasets.getDatasets().get("stackedbar");

    //I create one bar renderer and one line

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

    if (useBars) {
        CategoryItemRenderer barRenderer = new StackedBarRenderer();

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

        if (additionalLabels) {
            barRenderer.setBaseItemLabelGenerator(generator);
            double orient = (-Math.PI / 2.0);
            if (styleValueLabels.getOrientation().equalsIgnoreCase("horizontal")) {
                orient = 0.0;
            }
            barRenderer.setBaseItemLabelFont(
                    new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
            barRenderer.setBaseItemLabelPaint(styleValueLabels.getColor());
            barRenderer.setBaseItemLabelsVisible(true);
            barRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));
            barRenderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
                    TextAnchor.CENTER, TextAnchor.CENTER, orient));

        }

        if (colorMap != null) {
            for (Iterator iterator = datasetBar.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 = datasetBar.getRowIndex(labelName);
                } else
                    index = datasetBar.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    barRenderer.setSeriesPaint(index, color);
                }
            }
        }
        // add tooltip if enabled
        if (enableToolTips) {
            MyCategoryToolTipGenerator generatorToolTip = new MyCategoryToolTipGenerator(freeToolTips,
                    seriesTooltip, categoriesTooltip, seriesCaptions);
            barRenderer.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) {
            barRenderer.setItemURLGenerator(mycatUrl);
        }

        plot.setDataset(1, datasetBar);
        plot.setRenderer(1, barRenderer);

    }

    if (useLines) {

        LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
        //lineRenderer.setShapesFilled(false);
        lineRenderer.setShapesFilled(true);
        if (additionalLabels) {
            lineRenderer.setBaseItemLabelGenerator(generator);
            lineRenderer.setBaseItemLabelFont(
                    new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
            lineRenderer.setBaseItemLabelPaint(defaultLabelsStyle.getColor());
            lineRenderer.setBaseItemLabelsVisible(true);
        }

        DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasets.getDatasets().get("line");

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

        if (colorMap != null) {
            for (Iterator iterator = datasetLine.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 = datasetLine.getRowIndex(labelName);
                } else
                    index = datasetLine.getRowIndex(serName);

                Color color = (Color) colorMap.get(serName);
                if (color != null) {
                    lineRenderer.setSeriesPaint(index, color);
                }
            }
        }
        plot.setDataset(0, datasetLine);
        plot.setRenderer(0, lineRenderer);
    }

    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);
        if (rangeIntegerValues == true) {
            na.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        }
        na.setNumberFormatOverride(nf);
        plot.setRangeAxis(1, na);
        plot.mapDatasetToRangeAxis(0, 1);
    }

    //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);
    return chart;

}

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

/**
 * Inherited by IChart./*  w w w .  j  av 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");

    CategoryAxis categoryAxis = new CategoryAxis(categoryLabel);
    ValueAxis valueAxis = new NumberAxis(valueLabel);
    if (rangeIntegerValues == true) {
        valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    org.jfree.chart.renderer.category.BarRenderer renderer = new org.jfree.chart.renderer.category.BarRenderer();

    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    //      renderer.setBaseItemLabelFont(new Font(styleValueLabels.getFontName(), Font.PLAIN, styleValueLabels.getSize()));
    //      renderer.setBaseItemLabelPaint(styleValueLabels.getColor());

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

    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);
    mycatUrl.setDrillDocTitle(drillDocTitle);
    mycatUrl.setTarget(target);

    renderer.setItemURLGenerator(mycatUrl);

    /*      }
    else{
       renderer.setItemURLGenerator(new StandardCategoryURLGenerator(rootUrl));
    }*/

    CategoryPlot plot = new CategoryPlot((CategoryDataset) dataset, categoryAxis, valueAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    if (horizontalView) {
        plot.setOrientation(PlotOrientation.HORIZONTAL);
    }

    JFreeChart chart = new JFreeChart(name, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);

    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);

    // get a reference to the plot for further customisation...
    //CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    NumberFormat nf = NumberFormat.getNumberInstance(locale);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    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 (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);
        }
    }

    // disable bar outlines...
    //BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    /*   if(currentSeries!=null && colorMap!=null){
       //for each serie selected
       int j=0;   
       for (Iterator iterator = currentSeries.iterator(); iterator.hasNext();) {
    String s = (String) iterator.next();
    Integer position=(Integer)seriesNumber.get(s);
    // check if for that position a value is defined
    if(colorMap.get("color"+position.toString())!=null){
       Color col= (Color)colorMap.get("color"+position);
       renderer.setSeriesPaint(j, col);
    }
    j++;
       }  // close for on series
    } // close case series selcted and color defined
    else{
       if(colorMap!=null){ // if series not selected check color each one
            
    for (Iterator iterator = colorMap.keySet().iterator(); iterator.hasNext();) {
       String key = (String) iterator.next();
       Color col= (Color)colorMap.get(key);
       String keyNum=key.substring(5, key.length());
       int num=Integer.valueOf(keyNum).intValue();
       num=num-1;
       renderer.setSeriesPaint(num, col);
    }
       }
    }*/

    int seriesN = dataset.getRowCount();

    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) {
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getRowKey(i);
            Color color = (Color) colorMap.get(serieName);
            if (color != null) {
                renderer.setSeriesPaint(i, color);
            }
        }
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    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());

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

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

}

From source file:no.met.jtimeseries.MeteogramWrapper.java

private void plotWindSpeedDirection(GenericDataModel model, ChartPlotter plotter, boolean showWindDirection,
        String unit, List<Date> symbolTimes) {

    // plot wind speed
    NumberPhenomenon windSpeed = model.getNumberPhenomenon(PhenomenonName.WindSpeedMPS.toString()).clone();
    Color windSpeedColor = new Color(0, 0, 0);
    // number axis to be used for wind speed plot
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(windSpeedColor);
    numberAxis.setTickLabelPaint(windSpeedColor);
    if (unit.equalsIgnoreCase("ms")) {
        numberAxis.setLabel(messages.getString("parameter.wind") + " (m/s)");
    } else {//from   w w w .  j  av  a2 s.  c  o m
        windSpeed.scaling(1 / MarinogramPlot.KNOT);
        numberAxis.setLabel(
                messages.getString("parameter.wind") + " (" + messages.getString("label.knots") + ")");
        NumberFormat formatter = new DecimalFormat("#0.0");
        numberAxis.setNumberFormatOverride(formatter);
    }
    double maxValue = windSpeed.getMaxValue();
    double minValue = windSpeed.getMinValue();

    ChartPlotter.setAxisBound(numberAxis, maxValue, minValue, 8, BACKGROUND_LINES);

    PlotStyle plotStyle = new PlotStyle.Builder("Wind").seriesColor(windSpeedColor)
            .plusDegreeColor(windSpeedColor).spline(SplineStyle.HYBRID).stroke(new BasicStroke(2.0f))
            .numberAxis(numberAxis).nonNegative(true).build();
    plotter.addLineChart(TimeBase.SECOND, windSpeed, plotStyle);

    // plot wind direction
    if (showWindDirection) {
        NumberPhenomenon windDirection = model
                .getNumberPhenomenon(PhenomenonName.WindDirectionDegree.toString()).clone();

        InListFromDateFilter symbolTimesFilter = new InListFromDateFilter(symbolTimes);
        windDirection.filter(symbolTimesFilter);
        windSpeed.filter(symbolTimesFilter);

        // when plot wind direction, the arrow should be rotated 180 degree
        windDirection = windDirection.transform(180);
        NumberAxis numberAxisDirection = null;
        try {
            numberAxisDirection = (NumberAxis) numberAxis.clone();
        } catch (CloneNotSupportedException e) {
        }
        numberAxisDirection.setVisible(false);
        plotter.getPlot().setRangeAxis(plotter.getPlotIndex(), numberAxisDirection);
        plotter.addArrowDirectionPlot(windDirection, windSpeed, 0.08, plotStyle);
        // transform back after plot
        windDirection = windDirection.transform(180);
    }
}

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

public NumberAxis formatYAxis(final IScope scope, NumberAxis axis) {
    axis.setAxisLinePaint(axesColor);// w w w .ja v a 2  s  . c  om
    axis.setTickLabelFont(getTickFont());
    axis.setLabelFont(getLabelFont());
    if (textColor != null) {
        axis.setLabelPaint(textColor);
        axis.setTickLabelPaint(textColor);
    }
    axis.setAxisLinePaint(axesColor);
    axis.setLabelFont(getLabelFont());
    axis.setTickLabelFont(getTickFont());
    if (textColor != null) {
        axis.setLabelPaint(textColor);
        axis.setTickLabelPaint(textColor);
    }
    if (!this.getYTickValueVisible(scope)) {
        axis.setTickMarksVisible(false);
        axis.setTickLabelsVisible(false);

    }
    return axis;

}