Example usage for org.jfree.chart.axis CategoryAxis setTickLabelsVisible

List of usage examples for org.jfree.chart.axis CategoryAxis setTickLabelsVisible

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis setTickLabelsVisible.

Prototype

public void setTickLabelsVisible(boolean flag) 

Source Link

Document

Sets the flag that determines whether or not the tick labels are visible and sends an AxisChangeEvent to all registered listeners.

Usage

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

public JFreeChart createChart(CategoryDataset categoryDataSet, String groupByName, String valueName,
        boolean createLegend) {

    JFreeChart chart = ChartFactory.createBarChart3D(null, // chart title
            groupByName, // domain axis label
            valueName, // range axis label
            categoryDataSet, // data
            PlotOrientation.VERTICAL, // orientation
            ((createLegend) && (groupByName != null)), // include legend if group by column is set
            true, // tooltips
            false // URLs
    );//from   ww w  .j  a v  a 2  s.  c om

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

    // set up paints for series
    if (groupByName == null) {
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, SwingTools.LIGHT_BLUE);
        renderer.setSeriesPaint(1, SwingTools.LIGHT_YELLOW);
    }

    // domain axis labels
    CategoryAxis domainAxis = plot.getDomainAxis();
    if (groupByName == null) {
        domainAxis.setTickLabelsVisible(true);
        domainAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    } else {
        domainAxis.setTickLabelsVisible(false);
    }

    return chart;
}

From source file:org.shredzone.bullshitcharts.chart.BarChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());// w  ww  .  j  a v a 2  s  .c  o m
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    BarRenderer3D renderer = new BarRenderer3D();

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

From source file:org.shredzone.bullshitcharts.chart.LineChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());/*from   w  w w .  j  a  va2 s.c o  m*/
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    LineAndShapeRenderer renderer = new LineRenderer3D();
    renderer.setBaseShapesVisible(false);
    //        renderer.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

From source file:org.sonar.plugins.buildstability.BuildStabilityChart.java

private void configureDomainAxis(CategoryPlot plot, String days) {
    CategoryAxis categoryAxis = new CategoryAxis();
    if (!StringUtils.isBlank(days)) {
        categoryAxis.setLabel("Last " + days + " days");
    }//from w  w w  .  jav  a 2s  . co m
    categoryAxis.setTickLabelsVisible(false);
    plot.setDomainAxis(categoryAxis);
    plot.setDomainGridlinesVisible(false);
}

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

/**
 * @see com.pureinfo.srm.reports.IChartBuilder#buildChart(java.util.List,
 *      int, java.lang.String)//from  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:uk.ac.lkl.cram.ui.chart.FeedbackChartMaker.java

/**
 * Create a chart from the provided category dataset
 * @return a Chart that can be rendered in a ChartPanel
 *//*w w w  .  ja  va2  s  .  c o  m*/
@Override
protected JFreeChart createChart() {
    //Create a vertical bar chart from the chart factory, with no title, no axis labels, a legend, tooltips but no URLs
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, (CategoryDataset) dataset,
            PlotOrientation.VERTICAL, true, true, false);
    //Get the font from the platform UI
    Font chartFont = UIManager.getFont("Label.font");
    //Get the plot from the chart
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    //Get the renderer from the plot
    BarRenderer barRenderer = (BarRenderer) plot.getRenderer();
    //Set the rendered to use a standard bar painter (nothing fancy)
    barRenderer.setBarPainter(new StandardBarPainter());
    //Set the colours for the bars
    barRenderer.setSeriesPaint(0, PEER_ONLY_COLOR);
    barRenderer.setSeriesPaint(1, TEL_COLOR);
    barRenderer.setSeriesPaint(2, TUTOR_COLOR);
    //Set the tooltip to be series, category and value
    barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(
            "<html><center>{0} ({2} hours)<br/>Double-click for more</center></html>",
            NumberFormat.getInstance()));
    //Get the category axis (that's the X-axis in this case)
    CategoryAxis categoryAxis = plot.getDomainAxis();
    //Set the font for rendering the labels on the x-axis to be the platform default
    categoryAxis.setLabelFont(chartFont);
    //Hide the tick marks and labels for the x-axis
    categoryAxis.setTickMarksVisible(false);
    categoryAxis.setTickLabelsVisible(false);
    //Set the label for the x-axis
    categoryAxis.setLabel("Feedback to individuals or group");
    //Get the number axis (that's the Y-axis in this case)
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    //Use the same font as the x-axis
    numberAxis.setLabelFont(chartFont);
    //Set the label for the vertical axis
    numberAxis.setLabel("Hours");
    return chart;
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Processes a string that indicates the axes that should be visible on
 * the plot./*  w ww.  j a v a  2s .c  om*/
 *
 * @param plot  the plot.
 * @param axisStr  the axis specification.
 * @param axes  a list that will be populated with any axes added to the
 *              plot.
 */
private static void processAxisStrH(CategoryPlot plot, String axisStr, List axes) {
    int xAxisCount = 0;
    int yAxisCount = 0;
    for (int i = 0; i < axisStr.length(); i++) {
        char c = axisStr.charAt(i);
        if (c == 'y') {
            if (yAxisCount == 0) {
                CategoryAxis axis = plot.getDomainAxis();
                axis.setTickLabelsVisible(true);
                axes.add(axis);
                yAxisCount++;
            } else {
                GCategoryAxis axis = new GCategoryAxis();
                axis.setAxisLineVisible(false);
                plot.setDomainAxis(yAxisCount, axis);
                plot.setDomainAxisLocation(xAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                yAxisCount++;
            }
        } else if (c == 'x') {
            if (xAxisCount == 0) {
                Axis axis = plot.getRangeAxis();
                axis.setTickLabelsVisible(true);
                axis.setTickMarksVisible(true);
                axes.add(axis);
                xAxisCount++;
            } else {
                GValueAxis axis = new GValueAxis();
                axis.setAxisLineVisible(false);
                plot.setRangeAxis(xAxisCount, axis);
                plot.setRangeAxisLocation(xAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                xAxisCount++;
            }
        } else if (c == 't') {
            GValueAxis axis = new GValueAxis();
            plot.setRangeAxis(xAxisCount, axis);
            plot.setRangeAxisLocation(yAxisCount, AxisLocation.TOP_OR_LEFT);
            axes.add(axis);
            xAxisCount++;
        } else if (c == 'r') {
            GCategoryAxis axis = new GCategoryAxis();
            plot.setDomainAxis(yAxisCount, axis);
            plot.setDomainAxisLocation(xAxisCount, AxisLocation.BOTTOM_OR_RIGHT);
            axes.add(axis);
            yAxisCount++;
        } else if (c == ',') {
            // nothing to do
        } else {
            throw new RuntimeException("Bad character " + c);
        }
    }

}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * Processes a string that indicates the axes that should be visible on
 * the plot./*from w  w w  .  jav a2  s. c  om*/
 *
 * @param plot  the plot.
 * @param axisStr  the axis specification.
 * @param axes  a list that will be populated with any axes added to the
 *              plot.
 */
private static void processAxisStrV(CategoryPlot plot, String axisStr, List axes) {
    int xAxisCount = 0;
    int yAxisCount = 0;
    for (int i = 0; i < axisStr.length(); i++) {
        char c = axisStr.charAt(i);
        if (c == 'x') {
            if (xAxisCount == 0) {
                CategoryAxis xAxis = plot.getDomainAxis();
                xAxis.setTickLabelsVisible(true);
                axes.add(xAxis);
                xAxisCount++;
            } else {
                GCategoryAxis axis = new GCategoryAxis();
                axis.setAxisLineVisible(false);
                plot.setDomainAxis(xAxisCount, axis);
                plot.setDomainAxisLocation(xAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                xAxisCount++;
            }
        } else if (c == 'y') {
            if (yAxisCount == 0) {
                Axis yAxis = plot.getRangeAxis();
                yAxis.setTickLabelsVisible(true);
                yAxis.setTickMarksVisible(true);
                axes.add(yAxis);
                yAxisCount++;
            } else {
                GValueAxis axis = new GValueAxis();
                axis.setAxisLineVisible(false);
                plot.setRangeAxis(yAxisCount, axis);
                plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_LEFT);
                axes.add(axis);
                yAxisCount++;
            }
        } else if (c == 'r') {
            GValueAxis axis = new GValueAxis();
            plot.setRangeAxis(yAxisCount, axis);
            plot.setRangeAxisLocation(yAxisCount, AxisLocation.BOTTOM_OR_RIGHT);
            axes.add(axis);
            yAxisCount++;
        } else if (c == 't') {
            GCategoryAxis axis = new GCategoryAxis();
            axis.setAxisLineVisible(false);
            plot.setDomainAxis(xAxisCount, axis);
            plot.setDomainAxisLocation(xAxisCount, AxisLocation.TOP_OR_LEFT);
            axes.add(axis);
            xAxisCount++;
        } else if (c == ',') {
            // nothing to do
        } else {
            throw new RuntimeException("Bad character " + c);
        }
    }

}

From source file:org.pentaho.di.ui.spoon.trans.StepPerformanceSnapShotDialog.java

private void updateCanvas() {
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;//from   w ww .ja  va 2s  .c  o  m
    }

    // The list of snapshots : convert to JFreeChart dataset
    //
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    String[] selectedSteps = stepsList.getSelection();
    if (selectedSteps == null || selectedSteps.length == 0) {
        selectedSteps = new String[] { steps[0], }; // first step
        stepsList.select(0);
    }
    int[] dataIndices = dataList.getSelectionIndices();
    if (dataIndices == null || dataIndices.length == 0) {
        dataIndices = new int[] { DATA_CHOICE_WRITTEN, };
        dataList.select(0);
    }

    boolean multiStep = stepsList.getSelectionCount() > 1;
    boolean multiData = dataList.getSelectionCount() > 1;
    boolean calcMoving = !multiStep && !multiData; // A single metric shown for a single step
    List<Double> movingList = new ArrayList<Double>();
    int movingSize = 10;
    double movingTotal = 0;
    int totalTimeInSeconds = 0;

    for (int t = 0; t < selectedSteps.length; t++) {

        String stepNameCopy = selectedSteps[t];

        List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy);
        if (snapShotList != null && snapShotList.size() > 1) {
            totalTimeInSeconds = (int) Math
                    .round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime()
                            - snapShotList.get(0).getDate().getTime())) / 1000);
            for (int i = 0; i < snapShotList.size(); i++) {
                StepPerformanceSnapShot snapShot = snapShotList.get(i);
                if (snapShot.getTimeDifference() != 0) {

                    double factor = (double) 1000 / (double) snapShot.getTimeDifference();

                    for (int d = 0; d < dataIndices.length; d++) {

                        String dataType;
                        if (multiStep) {
                            dataType = stepNameCopy;
                        } else {
                            dataType = dataChoices[dataIndices[d]];
                        }
                        String xLabel = Integer.toString(Math.round(i * timeDifference / 1000));
                        Double metric = null;
                        switch (dataIndices[d]) {
                        case DATA_CHOICE_INPUT:
                            metric = snapShot.getLinesInput() * factor;
                            break;
                        case DATA_CHOICE_OUTPUT:
                            metric = snapShot.getLinesOutput() * factor;
                            break;
                        case DATA_CHOICE_READ:
                            metric = snapShot.getLinesRead() * factor;
                            break;
                        case DATA_CHOICE_WRITTEN:
                            metric = snapShot.getLinesWritten() * factor;
                            break;
                        case DATA_CHOICE_UPDATED:
                            metric = snapShot.getLinesUpdated() * factor;
                            break;
                        case DATA_CHOICE_REJECTED:
                            metric = snapShot.getLinesRejected() * factor;
                            break;
                        case DATA_CHOICE_INPUT_BUFFER_SIZE:
                            metric = (double) snapShot.getInputBufferSize();
                            break;
                        case DATA_CHOICE_OUTPUT_BUFFER_SIZE:
                            metric = (double) snapShot.getOutputBufferSize();
                            break;
                        default:
                            break;
                        }
                        if (metric != null) {
                            dataset.addValue(metric, dataType, xLabel);

                            if (calcMoving) {
                                movingTotal += metric;
                                movingList.add(metric);
                                if (movingList.size() > movingSize) {
                                    movingTotal -= movingList.get(0);
                                    movingList.remove(0);
                                }
                                double movingAverage = movingTotal / movingList.size();
                                dataset.addValue(movingAverage, dataType + "(Avg)", xLabel);
                                // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m");
                            }
                        }
                    }
                }
            }
        }
    }
    String chartTitle = title;
    if (multiStep) {
        chartTitle += " (" + dataChoices[dataIndices[0]] + ")";
    } else {
        chartTitle += " (" + selectedSteps[0] + ")";
    }
    final JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title
            BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label",
                    Integer.toString(totalTimeInSeconds), Long.toString(timeDifference)), // domain axis label
            BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false); // urls       
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(0.5f);
    plot.setRangeGridlinesVisible(true);

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

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelsVisible(false);

    // Customize the renderer...
    //
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));

    BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height);
    ImageData imageData = ImageUtil.convertToSWT(bufferedImage);

    // dispose previous image...
    //
    if (image != null) {
        image.dispose();
    }
    image = new Image(display, imageData);

    // Draw the image on the canvas...
    //
    canvas.redraw();
}

From source file:ds.monte.carlo.Application.java

private void createLengthGraph(HashMap<Integer, Integer> probability) {
    DefaultCategoryDataset pDataset = new DefaultCategoryDataset();

    for (Integer key : probability.keySet()) {
        pDataset.setValue(probability.get(key), "", "" + key);
    }//from ww w  .  j a v  a  2s. c  om

    JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", pDataset,
            PlotOrientation.VERTICAL, false, false, false);
    growChart.setBackgroundPaint(Color.WHITE);

    CategoryPlot catPlot = growChart.getCategoryPlot();
    catPlot.setRangeGridlinePaint(new Color(92, 184, 92));

    ValueAxis vAxis = catPlot.getRangeAxis();
    CategoryAxis cAxis = catPlot.getDomainAxis();

    cAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    cAxis.setTickLabelsVisible(false);

    Font font = new Font("SansSerif", Font.PLAIN, 12);
    Font fontTitle = new Font("SansSerif", Font.PLAIN, 14);
    vAxis.setTickLabelFont(font);
    growChart.getTitle().setFont(fontTitle);

    LineAndShapeRenderer renderer = (LineAndShapeRenderer) catPlot.getRenderer();
    Color bootstrapGreen = new Color(92, 184, 92);
    renderer.setSeriesPaint(0, bootstrapGreen);

    ChartPanel chartPanel = new ChartPanel(growChart);
    jPanel9.removeAll();
    jPanel9.add(chartPanel, BorderLayout.CENTER);
    jPanel9.validate();
}