Example usage for org.jfree.chart JFreeChart getCategoryPlot

List of usage examples for org.jfree.chart JFreeChart getCategoryPlot

Introduction

In this page you can find the example usage for org.jfree.chart JFreeChart getCategoryPlot.

Prototype

public CategoryPlot getCategoryPlot() 

Source Link

Document

Returns the plot cast as a CategoryPlot .

Usage

From source file:com.pureinfo.srm.reports.impl.CategoryChartBuilder.java

/**
 * @see com.pureinfo.srm.reports.IChartBuilder#buildChart(java.util.List,
 *      int, java.lang.String)//w w  w . j a  v a  2 s .c  om
 */
public JFreeChart buildChart() {
    CategoryDataset dataset = createDataset();

    JFreeChart jfreechart = MyChartFactory.createBarChart3D(null, m_sXAxisName, m_sYXxisName, dataset,
            PlotOrientation.VERTICAL, false, false, false);

    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    jfreechart.setBackgroundPaint(Color.white);
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setRangeGridlinesVisible(true);

    categoryplot.setForegroundAlpha(0.8f);
    categoryplot.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    CategoryAxis categoryAxisX = categoryplot.getDomainAxis();
    categoryAxisX.setTickLabelsVisible(true);
    categoryAxisX.setLabel(null);
    categoryAxisX.setMaximumCategoryLabelWidthRatio(.8f);
    ValueAxis categoryAxisY = categoryplot.getRangeAxis();
    categoryAxisY.setVerticalTickLabels(false);

    //        categoryplot.setDrawSharedDomainAxis(false);
    categoryAxisX.setCategoryLabelPositions(
            CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));

    BarRenderer3D barrenderer3d = (BarRenderer3D) categoryplot.getRenderer();
    barrenderer3d.setDrawBarOutline(false);
    barrenderer3d.setItemLabelsVisible(true);

    barrenderer3d.setBaseItemLabelsVisible(false);
    barrenderer3d.setSeriesVisible(Boolean.FALSE);

    //CategoryPlot categoryPlot = jfreechart.getCategoryPlot();
    //        categoryPlot.setBackgroundPaint(Color.lightGray);
    //        categoryPlot.setDomainGridlinePaint(Color.white);
    //        categoryPlot.setRangeGridlinePaint(Color.white);
    //
    //        BarRenderer barRenderer = (BarRenderer) categoryPlot.getRenderer();
    //        barRenderer.setDrawBarOutline(false);
    //        barRenderer.setMaxBarWidth(0.03);
    //        GradientPaint gradientPaint = new GradientPaint(0.0F, 0.0F,
    // Color.red, 0.0F, 0.0F, new Color(64, 0, 0));
    //        barRenderer.setSeriesPaint(0, gradientPaint);

    DecimalFormat format = null;
    if (m_dblMaxData > 1) {
        format = new DecimalFormat("#,###");
    } else {
        StringBuffer sb = new StringBuffer();
        sb.append("0.00#");
        for (double i = m_dblMaxData; i != 0 && i < 1; i *= 10f) {
            sb.append("#");
        }
        format = new DecimalFormat(sb.toString());
    }
    fillChartInfo(dataset, format);
    barrenderer3d.setMaxBarWidth(8.0 / m_ChartInfo.getChartSize().x);
    NumberAxis numberAxis = (NumberAxis) categoryplot.getRangeAxis(0);
    numberAxis.setUpperMargin(0.149999999999D);
    numberAxis.setNumberFormatOverride(format);

    categoryAxisX.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    NumberAxis dataNumberAxis = (NumberAxis) categoryplot.getRangeAxisForDataset(0);
    dataNumberAxis.setUpperMargin(0.149999999999D);
    dataNumberAxis.setNumberFormatOverride(format);

    //        CategoryItemRenderer renderer = categoryPlot.getRenderer();
    //        CategoryItemLabelGenerator generator = new StandardCategoryItemLabelGenerator("{2}", format);
    //        renderer.setItemLabelGenerator(generator);
    //        renderer.setItemLabelFont(new Font("Serif", 0, 9));
    //        renderer.setItemLabelsVisible(true);
    return jfreechart;
}

From source file:userInterface.CustomerWorkArea.ViewChartJPanel.java

private void batteryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batteryBtnActionPerformed
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
        dataSet.setValue(carList.getBattery(), "Battery", carList.getTimestamp());
    }/*  w w w . j a  v a2  s .co m*/
    JFreeChart chart = ChartFactory.createBarChart("Battery", "Timestamp", "Battery", dataSet,
            PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame = new ChartFrame("BATTERY GRAPH", chart);
    frame.setVisible(true);
    frame.setSize(600, 600);
    // TODO add your handling code here:
}

From source file:my.estadistico.Grafica.java

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
    // JFreeChart chart = ChartFactory.createBarChart3D(null, null, null, dataset); //Barras vertical 3d
    //JFreeChart chart = ChartFactory.createLineChart(null, null, null, dataset); //Grafico de linea
    try {//from   w  w  w  .ja  v a  2  s.  com
        this.datos();//Obtiene los datos
        JFreeChart chart = ChartFactory.createBarChart3D(null, null, null, dataset); //Barras vertical 3d
        CategoryPlot catPlot = chart.getCategoryPlot();
        catPlot.setRangeGridlinePaint(Color.BLACK);
        this.mostrar(chart);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(rootPane, "FAVOR DE INGRESAR DATOS");

    }
    // TODO add your handling code here:
}

From source file:com.thalesgroup.hudson.plugins.cccc.CcccChartBuilder.java

protected JFreeChart createGraph() {

    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of modules",
            buildDataset(action), PlotOrientation.VERTICAL, true, false, true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);/* ww w. ja  v  a2  s.  c o  m*/
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer();
    CcccAreaRenderer renderer = new CcccAreaRenderer(action.getUrlName());
    plot.setRenderer(firstRender);

    //Second
    NumberAxis axis2 = new NumberAxis("Lines of Code");
    axis2.setLabelPaint(Color.BLUE);
    axis2.setAxisLinePaint(Color.BLUE);
    axis2.setTickLabelPaint(Color.BLUE);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    categoryPlot.setRangeAxis(1, axis2);
    //CategoryAxis categoryAxis = categoryPlot.getDomainAxis();
    categoryPlot.setDataset(1, buildDataset2(action));
    categoryPlot.mapDatasetToRangeAxis(1, 1);
    CategoryItemRenderer rendu = new DefaultCategoryItemRenderer();
    rendu.setBasePaint(Color.BLUE);
    categoryPlot.setRenderer(1, rendu);

    //Third
    NumberAxis axis3 = new NumberAxis("McCabe's Cyclomatic Number");
    axis3.setLabelPaint(Color.GREEN);
    axis3.setAxisLinePaint(Color.GREEN);
    axis3.setTickLabelPaint(Color.GREEN);
    CategoryPlot categoryPlot3 = chart.getCategoryPlot();
    categoryPlot3.setRangeAxis(2, axis3);
    categoryPlot3.setDataset(2, buildDataset3(action));
    categoryPlot3.mapDatasetToRangeAxis(2, 2);
    categoryPlot3.mapDatasetToDomainAxis(2, 0);
    CategoryItemRenderer rendu3 = new DefaultCategoryItemRenderer();
    rendu3.setBasePaint(Color.GREEN);
    categoryPlot3.setRenderer(2, rendu3);

    return chart;
}

From source file:userInterface.CustomerWorkArea.ViewChartJPanel.java

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
        dataSet.setValue(carList.getPollutionLevel(), "Pollution", carList.getTimestamp());
    }// ww  w.j a va2  s  . c  om
    JFreeChart chart = ChartFactory.createBarChart("Pollution", "Timestamp", "Pollution", dataSet,
            PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame = new ChartFrame("POLLUTION GRAPH", chart);
    frame.setVisible(true);
    frame.setSize(600, 600); // TODO add your handling code here:
}

From source file:userInterface.CustomerWorkArea.ViewChartJPanel.java

private void viewAlignmentBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewAlignmentBtnActionPerformed
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
        dataSet.setValue(carList.getAlignment(), "Alignment", carList.getTimestamp());
    }/* ww  w. ja  va 2 s.  c  o  m*/
    JFreeChart chart = ChartFactory.createBarChart("Alignment", "Timestamp", "Alignment", dataSet,
            PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame = new ChartFrame("ALIGNMENT GRAPH", chart);
    frame.setVisible(true);
    frame.setSize(600, 600);
    // TODO add your handling code here:
}

From source file:org.bench4Q.console.ui.section.S_SummarizeSection.java

/**
 * @return//ww w. j  av a2s.  c  o m
 * @throws IOException
 */
public JPanel drawSessionPic() throws IOException {

    CategoryDataset dataset = getDataSet();
    JFreeChart chart = ChartFactory.createBarChart3D("Session", "Session type", "Session number", dataset,
            PlotOrientation.VERTICAL, true, true, true);
    CategoryPlot plot = chart.getCategoryPlot();
    org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.1);
    domainAxis.setUpperMargin(0.1);
    domainAxis.setCategoryLabelPositionOffset(10);
    domainAxis.setCategoryMargin(0.2);

    org.jfree.chart.axis.ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setUpperMargin(0.1);

    org.jfree.chart.renderer.category.BarRenderer3D renderer;
    renderer = new org.jfree.chart.renderer.category.BarRenderer3D();
    renderer.setBaseOutlinePaint(Color.red);
    renderer.setSeriesPaint(0, new Color(0, 255, 255));
    renderer.setSeriesOutlinePaint(0, Color.BLACK);
    renderer.setSeriesPaint(1, new Color(0, 255, 0));
    renderer.setSeriesOutlinePaint(1, Color.red);
    renderer.setItemMargin(0.1);

    renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setItemLabelFont(new Font("", Font.PLAIN, 12));
    renderer.setItemLabelPaint(Color.black);
    renderer.setItemLabelsVisible(true);
    plot.setRenderer(renderer);

    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setBackgroundPaint(Color.WHITE);

    return new ChartPanel(chart);
}

From source file:org.squale.squaleweb.util.graph.RepartitionMaker.java

/**
 * @return le diagramme JFreeChart/*from   w  w w . java  2  s .  com*/
 */
public JFreeChart getChart() {
    JFreeChart retChart = super.getChart();
    if (null == retChart) {
        retChart = ChartFactory.createBarChart3D(mTitle, mXLabel, mYLabel, mDataSet, PlotOrientation.VERTICAL,
                false, true, true);
        CategoryPlot plot = retChart.getCategoryPlot();
        CategoryAxis xAxis = plot.getDomainAxis();
        xAxis.setAxisLineVisible(true);
        xAxis.setVisible(true);
        ValueAxis yAxis = plot.getRangeAxis();
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        // On rajoute 5% pour avoir une meilleure lisibilit
        final double YAxisCoeff = 1.05;
        yAxis.setRange(PracticeResultBO.REFUSED_MIN, Math.max(mMaxValue * YAxisCoeff, 1));

        // Positionne les couleurs et les liens
        mRenderer = (CategoryItemRenderer) plot.getRenderer();
        RepartitionUrlGenerator generator = new RepartitionUrlGenerator(mProjectId, mCurrentAuditId,
                mPreviousAuditId, mPracticeId, mFactorParentId, NB_SERIES_FOR_FLOAT_GRAPH);
        mRenderer.setItemURLGenerator(generator);
        BarRenderer barRenderer = (BarRenderer) mRenderer;
        barRenderer.setBaseSeriesVisible(true);
        RepartitionToolTipGenerator toolTipGenerator = new RepartitionToolTipGenerator();
        barRenderer.setToolTipGenerator(toolTipGenerator);
        manageColor(NB_SERIES_FOR_FLOAT_GRAPH);
        retChart.setBackgroundPaint(Color.WHITE);
        super.setChart(retChart);
    }
    return retChart;
}

From source file:userInterface.CustomerWorkArea.ViewChartJPanel.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

    for (CarInspection carList : userAccount.getPerson().getCarInspectionHistory().getCarInspectionHistory()) {
        dataSet.setValue(carList.getTyrePressure(), "Tyre Pressure", carList.getTimestamp());
    }/*from  w  w  w .j  a  va2 s  .  co m*/
    JFreeChart chart = ChartFactory.createBarChart("Tyre Pressure", "Timestamp", "Tyre Pressure", dataSet,
            PlotOrientation.HORIZONTAL.VERTICAL, false, true, false);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.BLACK);
    ChartFrame frame = new ChartFrame("TYRE PRESSURE GRAPH", chart);
    frame.setVisible(true);
    frame.setSize(600, 600); // TODO add your handling code here:
}

From source file:com.esprit.gui.Statistique.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    OffreDAO off = new OffreDAO();
    DefaultCategoryDataset barChartData = new DefaultCategoryDataset();
    barChartData.setValue(off.calculNombreOffreEnAttente(), "Nombre des offres", "En Attente");
    barChartData.setValue(off.calculNombreOffreApprouver(), "Nombre des offres", "Approuvs");
    barChartData.setValue(off.calculNombreOffreDeapprouver(), "Nombre des offres", "Non Approuvs");

    JFreeChart barChart = ChartFactory.createBarChart3D("Statistiques des Offres", "Type", "Nombre des offres",
            barChartData, PlotOrientation.VERTICAL, rootPaneCheckingEnabled, rootPaneCheckingEnabled,
            rootPaneCheckingEnabled);/* w  w  w  . ja  v  a2s.c  om*/
    CategoryPlot barchrt = barChart.getCategoryPlot();
    //barchrt.setRangeGridlinePaint(Color.YELLOW);
    ChartPanel barPanel = new ChartPanel(barChart);
    jPanel2.removeAll();
    jPanel2.add(barPanel, BorderLayout.CENTER);
    jPanel2.validate();
}