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

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

Introduction

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

Prototype

public void setTickLabelPaint(Paint paint) 

Source Link

Document

Sets the paint used to draw tick labels (if they are showing) and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:dk.netarkivet.harvester.harvesting.monitor.StartedJobHistoryChartGen.java

/**
 * Generates a chart in PNG format./*w  w  w  .  jav a 2s  . c om*/
 * @param outputFile the output file, it should exist.
 * @param pxWidth the image width in pixels.
 * @param pxHeight the image height in pixels.
 * @param chartTitle the chart title, may be null.
 * @param xAxisTitle the x axis title
 * @param yDataSeriesRange the axis range (null for auto)
 * @param yDataSeriesTitles the Y axis titles.
 * @param timeValuesInSeconds the time values in seconds
 * @param yDataSeries the Y axis value series.
 * @param yDataSeriesColors the Y axis value series drawing colors.
 * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix
 * @param drawBorder draw, or not, the border.
 * @param backgroundColor the chart background color.
 */
final void generatePngChart(File outputFile, int pxWidth, int pxHeight, String chartTitle, String xAxisTitle,
        String[] yDataSeriesTitles, double[] timeValuesInSeconds, double[][] yDataSeriesRange,
        double[][] yDataSeries, Color[] yDataSeriesColors, String[] yDataSeriesTickSuffix, boolean drawBorder,
        Color backgroundColor) {

    // Domain axis
    NumberAxis xAxis = new NumberAxis(xAxisTitle);
    xAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    xAxis.setLabelPaint(Color.black);
    xAxis.setTickLabelPaint(Color.black);

    double maxSeconds = getMaxValue(timeValuesInSeconds);
    TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds);
    xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep));
    double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds);

    String tickSymbol = I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name());
    xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'"));

    // First dataset
    String firstDataSetTitle = yDataSeriesTitles[0];
    XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]);
    Color firstDataSetColor = yDataSeriesColors[0];

    // First range axis
    NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle);

    firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION);
    setAxisRange(firstYAxis, yDataSeriesRange[0]);
    firstYAxis.setLabelPaint(firstDataSetColor);
    firstYAxis.setTickLabelPaint(firstDataSetColor);
    String firstAxisTickSuffix = yDataSeriesTickSuffix[0];
    if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) {
        firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'"));
    }

    // Create the plot with domain axis and first range axis
    XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null);

    XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false);
    plot.setRenderer(firstRenderer);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    firstRenderer.setSeriesPaint(0, firstDataSetColor);

    // Now iterate on next axes
    for (int i = 1; i < yDataSeries.length; i++) {
        // Create axis
        String seriesTitle = yDataSeriesTitles[i];
        Color seriesColor = yDataSeriesColors[i];
        NumberAxis yAxis = new NumberAxis(seriesTitle);

        yAxis.setFixedDimension(CHART_AXIS_DIMENSION);
        setAxisRange(yAxis, yDataSeriesRange[i]);

        yAxis.setLabelPaint(seriesColor);
        yAxis.setTickLabelPaint(seriesColor);

        String yAxisTickSuffix = yDataSeriesTickSuffix[i];
        if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) {
            yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'"));
        }

        // Create dataset and add axis to plot
        plot.setRangeAxis(i, yAxis);
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT);
        plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i]));
        plot.mapDatasetToRangeAxis(i, i);
        XYItemRenderer renderer = new StandardXYItemRenderer();
        renderer.setSeriesPaint(0, seriesColor);
        plot.setRenderer(i, renderer);
    }

    // Create the chart
    JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    // Customize rendering
    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);

    // Render image
    try {
        ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight);
    } catch (IOException e) {
        LOG.error("Chart export failed", e);
    }
}

From source file:org.owasp.benchmark.score.report.ScatterScores.java

private JFreeChart display(String title, int height, int width, List<Report> toolResults) {
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (int i = 0; i < toolResults.size(); i++) {
        Report toolReport = toolResults.get(i);
        OverallResults overallResults = toolReport.getOverallResults();
        series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100);
    }//from  ww w  . j  a  va  2  s.  c om
    dataset.addSeries(series);

    chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-5, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String label = ""+((String)dataset.getSeries(i).getKey());
    //            int idx = label.indexOf( ':');
    //            label = label.substring( 0, idx );
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); 
    //            renderer.setSeriesItemLabelGenerator(i, generator); 
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(toolResults, xyplot);
    makeLegend(toolResults, 57, 48, dataset, xyplot);

    Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 },
            0);
    for (XYDataItem item : (List<XYDataItem>) series.getItems()) {
        double x = item.getX().doubleValue();
        double y = item.getY().doubleValue();
        double z = (x + y) / 2;
        XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue);
        xyplot.addAnnotation(score);
    }

    //        // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext = new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false,
            false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);
    return chart;
}

From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java

private JFreeChart createChart() {
    JFreeChart result = ChartFactory.createXYBarChart("", "", false, "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);
    result.getTitle().setFont(TsCharts.CHART_TITLE_FONT);

    XYPlot plot = result.getXYPlot();/*from  ww  w  .  j a  v a2s  .c o m*/

    plot.setDataset(DFM_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(DFM_INDEX, dfmRenderer);
    plot.mapDatasetToDomainAxis(DFM_INDEX, 0);
    plot.mapDatasetToRangeAxis(DFM_INDEX, 0);

    plot.setDataset(ARIMA_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(ARIMA_INDEX, arimaRenderer);
    plot.mapDatasetToDomainAxis(ARIMA_INDEX, 0);
    plot.mapDatasetToRangeAxis(ARIMA_INDEX, 0);

    plot.setDataset(STDEV_INDEX, Charts.emptyXYDataset());
    plot.setRenderer(STDEV_INDEX, stdevRenderer);
    plot.mapDatasetToDomainAxis(STDEV_INDEX, 0);
    plot.mapDatasetToRangeAxis(STDEV_INDEX, 0);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    return result;
}

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);/* w ww.j a  v  a 2 s. com*/
    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: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);/* w w  w.j a va  2s  . c om*/
    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:it.eng.spagobi.engines.chart.bo.charttypes.barcharts.SimpleBar.java

public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    CategoryDataset dataset = (CategoryDataset) datasets.getDatasets().get("1");

    PlotOrientation plotOrientation = PlotOrientation.VERTICAL;
    if (horizontalView) {
        plotOrientation = PlotOrientation.HORIZONTAL;
    }//from www . ja v  a 2  s.co  m

    JFreeChart chart = ChartFactory.createBarChart(name, // chart title
            categoryLabel, // domain axis label
            valueLabel, // range axis label
            dataset, // data
            plotOrientation, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

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

    // 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.setBackgroundPaint(Color.white);
    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.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.setUpperMargin(0.10);
    rangeAxis.setNumberFormatOverride(nf);

    if (firstAxisLB != null && firstAxisUB != null) {
        rangeAxis.setLowerBound(firstAxisLB);
        rangeAxis.setUpperBound(firstAxisUB);
    }

    if (rangeIntegerValues == true) {
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    } else
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

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

    // add
    CategorySeriesLabelGenerator generator = new StandardCategorySeriesLabelGenerator("{0}");
    renderer.setLegendItemLabelGenerator(generator);

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

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

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

    }

    // PROVA LEGENDA      
    if (legend == true) {

        drawLegend(chart);

        /*BlockContainer wrapper = new BlockContainer(new BorderArrangement());
        wrapper.setFrame(new BlockBorder(1.0, 1.0, 1.0, 1.0));
                
        LabelBlock titleBlock = new LabelBlock("Legend Items:",
              new Font("SansSerif", Font.BOLD, 12));
        title.setPadding(5, 5, 5, 5);
        wrapper.add(titleBlock, RectangleEdge.TOP);
                
        LegendTitle legend = new LegendTitle(chart.getPlot());
        BlockContainer items = legend.getItemContainer();
        items.setPadding(2, 10, 5, 2);
        wrapper.add(items);
        legend.setWrapper(wrapper);
                
        if(legendPosition.equalsIgnoreCase("bottom")) legend.setPosition(RectangleEdge.BOTTOM);
        else if(legendPosition.equalsIgnoreCase("left")) legend.setPosition(RectangleEdge.LEFT);
        else if(legendPosition.equalsIgnoreCase("right")) legend.setPosition(RectangleEdge.RIGHT);
        else if(legendPosition.equalsIgnoreCase("top")) legend.setPosition(RectangleEdge.TOP);
        else legend.setPosition(RectangleEdge.BOTTOM);
                
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        chart.addSubtitle(legend);*/
    }

    int seriesN = dataset.getRowCount();

    // the order color vedctor overrides the color map!!

    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) {
        logger.debug("color serie by SERIES_COLORS template specification");
        for (int i = 0; i < seriesN; i++) {
            String serieName = (String) dataset.getRowKey(i);
            String labelName = "";
            int index = -1;
            if (seriesCaptions != null && seriesCaptions.size() > 0) {
                labelName = serieName;
                serieName = (String) seriesCaptions.get(serieName);
                index = dataset.getRowIndex(labelName);
            } else
                index = dataset.getRowIndex(serieName);

            Color color = (Color) colorMap.get(serieName);
            if (color != null) {
                //renderer.setSeriesPaint(i, color);
                renderer.setSeriesPaint(index, color);
                renderer.setSeriesItemLabelFont(i,
                        new Font(defaultLabelsStyle.getFontName(), Font.PLAIN, defaultLabelsStyle.getSize()));
                renderer.setSeriesItemLabelPaint(i, defaultLabelsStyle.getColor());
            }
        }
    }

    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());
    domainAxis.setUpperMargin(0.10);
    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   ww w  .  j a  v a 2 s . c om*/
        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: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  o m
            .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;

}