Example usage for org.jfree.chart.plot CategoryPlot setBackgroundAlpha

List of usage examples for org.jfree.chart.plot CategoryPlot setBackgroundAlpha

Introduction

In this page you can find the example usage for org.jfree.chart.plot CategoryPlot setBackgroundAlpha.

Prototype

public void setBackgroundAlpha(float alpha) 

Source Link

Document

Sets the alpha transparency of the plot area background, and notifies registered listeners that the plot has been modified.

Usage

From source file:presentation.webgui.vitroappservlet.StyleCreator.java

private static JFreeChart createChart(CategoryDataset dataset, Vector<String> givCategColors,
        Model3dStylesEntry givStyleEntry) {
    String capSimpleName = givStyleEntry.getCorrCapability();
    capSimpleName = capSimpleName.replaceAll(Capability.dcaPrefix, "");
    JFreeChart chart = ChartFactory.createBarChart("Style Legend for " + capSimpleName, // chart title
            null, // domain axis label
            null, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, false, // include legend
            true, false);//  w w w . j ava  2  s. c o m

    chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 14));
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white); // seen
    CategoryPlot plot = chart.getCategoryPlot();
    chart.setPadding(new RectangleInsets(0, 0, 0, 0)); //new

    plot.setNoDataMessage("NO DATA!");

    Paint[] tmpPaintCategories = { Color.white };
    if (givCategColors.size() > 0) {
        tmpPaintCategories = new Paint[givCategColors.size()];
        for (int i = 0; i < givCategColors.size(); i++) {
            tmpPaintCategories[i] = Color.decode(givCategColors.elementAt(i));
        }
    }

    CategoryItemRenderer renderer = new CustomRenderer(tmpPaintCategories);

    renderer.setSeriesPaint(0, new Color(255, 204, 51)); //new

    plot.setRenderer(renderer);

    plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); //new
    plot.setForegroundAlpha(1f); //new
    plot.setBackgroundAlpha(1f); //new
    plot.setInsets(new RectangleInsets(5, 0, 5, 0)); //new was 5,0,5,0
    plot.setRangeGridlinesVisible(false); //new was true
    plot.setBackgroundPaint(Color.white);//new: was (Color.lightGray);
    plot.setOutlinePaint(Color.white);

    //plot.setOrientation(PlotOrientation.HORIZONTAL);

    CategoryAxis domainAxis = plot.getDomainAxis();

    domainAxis.setLowerMargin(0.04);
    domainAxis.setUpperMargin(0.04);
    domainAxis.setVisible(true);
    domainAxis.setLabelAngle(Math.PI / 2);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(0.0, 100.0); // new: was 100
    rangeAxis.setVisible(false);
    // OPTIONAL CUSTOMISATION COMPLETED.
    return chart;
}

From source file:Graphic.camion.java

private void initialiser() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    int k = 0;//from www  .j av  a2  s  .c o  m
    for (int j = 0; j < categories.size(); j++) {
        for (int i = 0; i < series.size(); i++) {
            dataset.addValue(valeurs.get(k), series.get(i), categories.get(j));
            k++;
        }

    }
    JFreeChart chart = ChartFactory.createBarChart(titre, // chart title
            abscisse, // domain axis label
            ordonnee, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            legende, // include legend
            true, // tooltips
            false // URL
    );

    // definition de la couleur de fond
    //chart.setBackgroundPaint(couleurFond);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();

    //valeur comprise entre 0 et 1 transparence de la zone graphique
    plot.setBackgroundAlpha(0.9f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // pour la couleur des barres pour chaque serie
    for (int s = 0; s < series.size(); s++) {
        GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, couleursBarres[s], 0.0f, 0.0f, new Color(0, 40, 70));
        renderer.setSeriesPaint(s, gp0);

    }

    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);

    add(chartPanel);
}

From source file:charts.ErroresPorMilChart.java

private JFreeChart createChart(DefaultCategoryDataset dataset, String title) {
    JFreeChart chart = ChartFactory.createBarChart(title, "Tipo de Control", "Cantidad de Imagenes", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Inclinamos 45 grados las etiquetas del eje X
    plot.setBackgroundAlpha(0.5f);
    return chart;
}

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  v  a 2s  . 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:org.jajuk.ui.views.StatView.java

/**
 * Collection size bars./* ww  w.j  a  va2s. c  o m*/
 * 
 * @return the chart
 */
private ChartPanel createCollectionSize() {
    try {
        final DateFormat additionFormatter = UtilString.getAdditionDateFormatter();
        CategoryDataset cdata = null;
        JFreeChart jfchart = null;
        int iMonthsNumber = 5; // number of mounts we show, mounts
        // before are set together in 'before'
        long lSizeByMonth[] = new long[iMonthsNumber + 1];
        // contains size ( in Go ) for each month, first cell is before
        // data
        int[] iMonths = getMonths(iMonthsNumber);
        ReadOnlyIterator<Track> tracks = TrackManager.getInstance().getTracksIterator();
        while (tracks.hasNext()) {
            Track track = tracks.next();
            int i = Integer.parseInt(additionFormatter.format(track.getDiscoveryDate())) / 100;
            for (int j = 0; j < iMonthsNumber + 1; j++) {
                if (i <= iMonths[j]) {
                    lSizeByMonth[j] += track.getTotalSize();
                }
            }
        }
        double[][] data = new double[1][iMonthsNumber + 1];
        for (int i = 0; i < iMonthsNumber + 1; i++) {
            data[0][i] = (double) lSizeByMonth[i] / 1073741824;
        }
        cdata = DatasetUtilities.createCategoryDataset(new String[] { "" }, getMonthsLabels(iMonthsNumber),
                data);
        // chart, use local copy of method to use better format string for
        // tooltips
        jfchart = createBarChart3D(Messages.getString("StatView.7"), // chart
                // title
                Messages.getString("StatView.8"), // domain axis label
                Messages.getString("StatView.9"), // range axis label
                cdata, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips
                false, // urls
                "{1} = {2} GB");
        CategoryPlot plot = jfchart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();
        new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT,
                -Math.PI / 8.0, CategoryLabelWidthType.CATEGORY, 0);
        axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
        // set the background color for the chart...
        plot.setNoDataMessage(Messages.getString("StatView.10"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        // plot.setBackgroundImage(IconLoader.IMAGES_STAT_PAPER).getImage());
        return new ChartPanel(jfchart);
    } catch (Exception e) {
        Log.error(e);
        return null;
    }
}

From source file:org.jajuk.ui.views.StatView.java

/**
 * Track number bars./*from www .ja  v a 2  s  .  c  o  m*/
 * 
 * @return the chart
 */
private ChartPanel createTrackNumber() {
    try {
        final DateFormat additionFormatter = UtilString.getAdditionDateFormatter();
        CategoryDataset cdata = null;
        JFreeChart jfchart = null;
        // number of months we show, mounts
        // before are set together in 'before'
        int iMonthsNumber = 5;
        // contains number of tracks for each month, first cell is 'before'
        // data
        int iTracksByMonth[] = new int[iMonthsNumber + 1];
        int[] iMounts = getMonths(iMonthsNumber);
        ReadOnlyIterator<Track> tracks = TrackManager.getInstance().getTracksIterator();
        while (tracks.hasNext()) {
            Track track = tracks.next();
            int i = Integer.parseInt(additionFormatter.format(track.getDiscoveryDate())) / 100;
            for (int j = 0; j < iMonthsNumber + 1; j++) {
                if (i <= iMounts[j]) {
                    iTracksByMonth[j]++;
                }
            }
        }
        double[][] data = new double[1][iMonthsNumber + 1];
        // cannot use System.arraycopy() here because we have different types in
        // the arrays...
        // System.arraycopy(iTracksByMonth, 0, data[0], 0, iMonthsNumber);
        for (int i = 0; i < iMonthsNumber + 1; i++) {
            data[0][i] = iTracksByMonth[i];
        }
        cdata = DatasetUtilities.createCategoryDataset(new String[] { "" }, getMonthsLabels(iMonthsNumber),
                data);
        // chart, use local copy of method to use better format string for
        // tooltips
        jfchart = createBarChart3D(Messages.getString("StatView.12"), // chart
                // title
                Messages.getString("StatView.13"), // domain axis label
                Messages.getString("StatView.14"), // range axis label
                cdata, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips
                false, // urls
                "{1} = {2}");
        CategoryPlot plot = jfchart.getCategoryPlot();
        CategoryAxis axis = plot.getDomainAxis();
        new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT,
                -Math.PI / 8.0, CategoryLabelWidthType.CATEGORY, 0);
        axis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);
        // set the background color for the chart...
        plot.setNoDataMessage(Messages.getString("StatView.15"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        // plot.setBackgroundImage(IconLoader.IMAGES_STAT_PAPER).getImage());
        return new ChartPanel(jfchart);
    } catch (Exception e) {
        Log.error(e);
        return null;
    }
}

From source file:org.jfree.chart.demo.JFreeChartDemoBase.java

/**
 * Creates and returns a sample line chart.
 *
 * @return a line chart.//from  ww w  . ja va 2  s. com
 */
public JFreeChart createLineChart() {

    // create a default chart based on some sample data...
    final String title = this.resources.getString("other.line.title");
    final String domain = this.resources.getString("other.line.domain");
    final String range = this.resources.getString("other.line.range");
    final CategoryDataset data = DemoDatasetFactory.createCategoryDataset();
    final JFreeChart chart = ChartFactory.createLineChart(title, domain, range, data, PlotOrientation.VERTICAL,
            true, true, false);

    // then customise it a little...
    chart.setBackgroundImage(JFreeChart.INFO.getLogo());
    chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.green));

    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundAlpha(0.65f);
    return chart;
}

From source file:app.RunApp.java

/**
 * Create Chart/*from w w  w  .j  a  v  a 2s .c om*/
 * 
 * @param jpanel Panel
 * @param type Chart type
 * @param titleX Title for X axis
 * @param titleY Title for Y axis
 * @param showXAxis Indicates if shows X axis
 * @param chartTitle Chart title
 * @return ChartPanel with the generated chart
 */
private ChartPanel createJChart(JPanel jpanel, String type, String titleX, String titleY, boolean showXAxis,
        String chartTitle) {
    DefaultCategoryDataset myData = new DefaultCategoryDataset();
    JFreeChart chart1;

    CategoryPlot plot1;

    LineAndShapeRenderer lineandshaperenderer;

    //hide horizontal axis
    switch (type) {
    case "bar":
        chart1 = ChartFactory.createBarChart(chartTitle, titleY, titleX, myData, PlotOrientation.VERTICAL,
                false, true, false);
        plot1 = chart1.getCategoryPlot();
        //Custom tooltips
        BarRenderer renderer = (BarRenderer) plot1.getRenderer();
        switch (chartTitle.toLowerCase()) {
        case "label frequency":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "labelset frequency":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "labels histogram":
            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(
                    "Instances with {1} labels = {2}", NumberFormat.getInstance()));
            break;
        case "ir inter class":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "ir intra class":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("{0} = {2}", NumberFormat.getInstance()));
            break;
        case "ir per labelset":
            renderer.setBaseToolTipGenerator(
                    new StandardCategoryToolTipGenerator("ID: {0} = {2}", NumberFormat.getInstance()));
            break;
        default:
            renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
            break;
        }
        plot1.setBackgroundAlpha(0);
        plot1.setRangeGridlinePaint(Color.black);
        break;
    case "line_2_axis":
        chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false,
                true, false);
        plot1 = chart1.getCategoryPlot();
        plot1.setRangeGridlinePaint(Color.black);

        //show little rectangles
        lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer();
        lineandshaperenderer.setBaseShapesVisible(true);
        CategoryAxis domainAxis = plot1.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);

        ValueAxis axis2 = new NumberAxis("# Labels");
        plot1.setRangeAxis(1, axis2);
        plot1.mapDatasetToRangeAxis(1, 1);
        LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
        plot1.setRenderer(1, renderer2);
        break;
    default:
        //type == "line")
        chart1 = ChartFactory.createLineChart(" ", titleX, titleY, myData, PlotOrientation.VERTICAL, false,
                true, false);
        plot1 = chart1.getCategoryPlot();
        plot1.setRangeGridlinePaint(Color.black);

        //show little rectangles
        lineandshaperenderer = (LineAndShapeRenderer) plot1.getRenderer();
        lineandshaperenderer.setBaseShapesVisible(true);
        break;
    }

    //Hide X axis
    plot1.getDomainAxis().setTickLabelsVisible(showXAxis);

    ChartPanel cp1 = new ChartPanel(chart1);
    cp1.setSize(new Dimension(450, 300));
    cp1.setBounds(260, 100, 450, 300);
    cp1.setPreferredSize(new Dimension(450, 300));
    cp1.repaint();

    jpanel.setBounds(260, 100, 450, 300);
    jpanel.setLayout(new BorderLayout());
    jpanel.add(cp1, BorderLayout.CENTER);
    jpanel.repaint();
    jpanel.validate();

    return cp1;
}