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:ds.monte.carlo.Application.java

private void createGrowthGraph(double[] growthMap) {
    DefaultCategoryDataset growthDataset = new DefaultCategoryDataset();
    double min = 1000000;
    double max = 0;
    int l_100 = growthMap.length;
    int l_40 = (int) Math.round(l_100 * 0.4);
    System.out.print(growthMap.length);
    for (int i = l_40; i < growthMap.length; i++) {
        growthDataset.setValue(growthMap[i], "", "" + i);
        if (growthMap[i] < min) {
            min = growthMap[i];/*from   w w w  .j  a  v a  2 s  . c  om*/
        }
        if (growthMap[i] > max) {
            max = growthMap[i];
        }
    }

    JFreeChart growChart = ChartFactory.createLineChart("Simulated annealing", "", "", growthDataset,
            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);
    vAxis.setRange(min, max);

    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);
    jPanel6.removeAll();
    jPanel6.add(chartPanel, BorderLayout.CENTER);
    jPanel6.validate();
    //jPanel5.setVisible(true);
}

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

private void updateCanvas() {
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;/*from w  w w.  j  av  a2 s. co  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);
    TextTitle title = new TextTitle(chartTitle);
    // title.setExpandToFitSpace(true);
    // org.eclipse.swt.graphics.Color pentahoColor = GUIResource.getInstance().getColorPentaho();
    // java.awt.Color color = new java.awt.Color(pentahoColor.getRed(), pentahoColor.getGreen(),pentahoColor.getBlue());
    // title.setBackgroundPaint(color);
    title.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 12));
    chart.setTitle(title);
    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,
            BufferedImage.TYPE_INT_RGB, null);
    ImageData imageData = ImageUtil.convertToSWT(bufferedImage);

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

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

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

protected void setupCategoryChart(JFreeChart chart) {

    if (!(chart.getPlot() instanceof CategoryPlot))
        return;/*from w  w w  .  j av a2s .co  m*/
    CategoryPlot cp = chart.getCategoryPlot();

    CategoryAxis catAxis = cp.getDomainAxis();
    ValueAxis otherAxis = cp.getRangeAxis();

    if (!chromeless) {
        String catAxisLabel = data.getColName(0);
        if (catAxisLabel == null)
            catAxisLabel = Translator.translate("Project/Task");

        String otherAxisLabel = Translator.translate(getSetting("units"));
        if ((otherAxisLabel == null || otherAxisLabel.length() == 0) && data.numCols() == 1)
            otherAxisLabel = data.getColName(1);
        if (otherAxisLabel == null)
            otherAxisLabel = Translator.translate("Value");

        String catLabels = getParameter("categoryLabels");

        catAxis.setLabel(catAxisLabel);
        otherAxis.setLabel(otherAxisLabel);
        if ("vertical".equalsIgnoreCase(catLabels))
            catAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
        else if ("none".equalsIgnoreCase(catLabels))
            catAxis.setTickLabelsVisible(false);
    }

    if (data.numCols() == 1 && getParameter("noSkipLegend") == null) {
        chart.removeLegend();
        chart.getPlot().setInsets(new RectangleInsets(5, 2, 2, 5));
    }
}

From source file:lucee.runtime.tag.Chart.java

private void setLabelFormat(JFreeChart chart) {
    Plot plot = chart.getPlot();//from w ww.j av a 2s .co  m
    if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        rangeAxis.setAutoTickUnitSelection(true);
        rangeAxis.setStandardTickUnits(new TickUnitsImpl(rangeAxis.getStandardTickUnits(), labelFormat));
        CategoryItemRenderer r = cp.getRenderer();
        r.setBaseItemLabelsVisible(false);

        CategoryAxis da = cp.getDomainAxis();
        if (!showXLabel)
            da.setTickLabelsVisible(false);
        da.setCategoryLabelPositions(labelPosition);
        da.setMaximumCategoryLabelWidthRatio(100);
        //da.setVisible(false);
    }
    if (plot instanceof XYPlot) {
        XYPlot cp = (XYPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        rangeAxis.setAutoTickUnitSelection(true);
        rangeAxis.setStandardTickUnits(new TickUnitsImpl(rangeAxis.getStandardTickUnits(), labelFormat));
        XYItemRenderer r = cp.getRenderer();
        r.setBaseItemLabelsVisible(false);
        ValueAxis da = cp.getDomainAxis();
        if (!_plotItemLables.isEmpty()) {
            _plotItemLables.add(0, "");
            String[] cols = _plotItemLables.toArray(new String[_plotItemLables.size()]);
            SymbolAxis sa = new SymbolAxis(da.getLabel(), cols);
            sa.setRange(da.getRange());
            if (labelPosition == LABEL_VERTICAL) {
                sa.setVerticalTickLabels(true);
            }
            cp.setDomainAxis(sa);
        }
        if (!showXLabel)
            cp.getDomainAxis().setTickLabelsVisible(false);
        //da.setVisible(false);
    }
}

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

private JFreeChart createChart() {
    if (data.getItemCount() > 0) {
        // get cumulative percentages
        KeyedValues cumulative = DataUtilities.getCumulativePercentages(data);

        CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset(
                "Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data);

        // create the chart...
        final JFreeChart chart = ChartFactory.createBarChart(null, // chart title
                this.dataTable.getColumnName(this.groupByColumn), // domain axis label
                "Count", // range axis label
                categoryDataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, false);/*  ww w  . jav  a2  s.  c  o  m*/

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.WHITE);

        // get a reference to the plot for further customization...
        CategoryPlot plot = chart.getCategoryPlot();

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setLowerMargin(0.02);
        domainAxis.setUpperMargin(0.02);
        domainAxis.setLabelFont(LABEL_FONT_BOLD);
        domainAxis.setTickLabelFont(LABEL_FONT);

        // set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US));
        rangeAxis.setLabelFont(LABEL_FONT_BOLD);
        rangeAxis.setTickLabelFont(LABEL_FONT);

        // second data set (cumulative percentages)
        CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative);

        LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
        renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker());

        NumberAxis axis2 = new NumberAxis("Percent of " + countValue);
        axis2.setNumberFormatOverride(NumberFormat.getPercentInstance());
        axis2.setLabelFont(LABEL_FONT_BOLD);
        axis2.setTickLabelFont(LABEL_FONT);

        plot.setRangeAxis(1, axis2);
        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.mapDatasetToRangeAxis(1, 1);

        axis2.setTickUnit(new NumberTickUnit(0.1));

        // show grid lines
        plot.setRangeGridlinesVisible(true);

        // bring cumulative line to front
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

        if (isLabelRotating()) {
            domainAxis.setTickLabelsVisible(true);
            domainAxis.setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d));
        }

        return chart;
    } else {
        return null;
    }
}