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

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

Introduction

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

Prototype

public void setCategoryLabelPositions(CategoryLabelPositions positions) 

Source Link

Document

Sets the category label position specification for the axis and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:nl.strohalm.cyclos.controls.reports.statistics.graphs.ChartPostProcessorImpl.java

/**
 * This method sets the x-axis labels in a rotated position. Use this only if there are a lot of bars in the graph, so there is very limited space
 * for eacht label on the x-axis. By rotating the labels, they wont overlap each other, and there will be more space per label. Set this in the
 * jsp via the param tag, using the keyword "xlabelRotation": <cewolf:chartpostprocessor id="chartPostProcessorImpl" > <cewolf:param
 * name="xlabelRotation" value="<%= new Double(0.60)%>"/> </cewolf:chartpostprocessor> The parameter is a double, indicating the rotation angle in
 * radials. <b>NOTE:</b> the rotation is set to 0.60 by default if the number of categories > 14; otherwise, the default rotation is 0. Setting
 * the parameter overrides this default.
 * @param plot/*from   w w  w . j  ava2s.co  m*/
 * @param params
 */
@SuppressWarnings("rawtypes")
private void setRotatedXaxisLabels(final CategoryPlot plot, final Map params) {
    Double rotation = (Double) params.get("xlabelRotation");
    final int numberOfCategories = plot.getCategories().size();
    if (rotation == null && numberOfCategories > ROTATE_XLABELS_IF_MORE_THAN) {
        rotation = new Double(0.60);
    }
    if (rotation != null && rotation != 0) {
        final CategoryAxis axis = plot.getDomainAxis();
        axis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(rotation.doubleValue()));
    }
}

From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotWindow.java

public IntensityPlotWindow(ParameterSet parameters) {

    PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue()
            .getMatchingPeakLists()[0];/*from   w  ww.  ja v a2  s. c  om*/

    String title = "Intensity plot [" + peakList + "]";
    String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString();
    String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString();

    // create dataset
    dataset = new IntensityPlotDataset(parameters);

    // create new JFreeChart
    logger.finest("Creating new chart instance");
    Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue();
    boolean isCombo = (xAxisValueSource instanceof ParameterWrapper)
            && (!(((ParameterWrapper) xAxisValueSource).getParameter() instanceof DoubleParameter));
    if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) {

        chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);

        CategoryPlot plot = (CategoryPlot) chart.getPlot();

        // set renderer
        StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true);
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

        CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis();
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);

    } else {

        chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
                true, true, false);

        XYPlot plot = (XYPlot) chart.getPlot();

        XYErrorRenderer renderer = new XYErrorRenderer();
        renderer.setBaseStroke(new BasicStroke(2));
        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        // set tooltip generator
        XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator();
        renderer.setBaseToolTipGenerator(toolTipGenerator);

    }

    chart.setBackgroundPaint(Color.white);

    // create chart JPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);

    IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this);
    add(toolBar, BorderLayout.EAST);

    // disable maximum size (we don't want scaling)
    chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE);
    chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE);

    // set title properties
    TextTitle chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    LegendTitle legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setBorder(0, 0, 0, 0);

    Plot plot = chart.getPlot();

    // set shape provider
    IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier();
    plot.setDrawingSupplier(shapeSupplier);

    // set y axis properties
    NumberAxis yAxis;
    if (plot instanceof CategoryPlot)
        yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis();
    else
        yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis();
    NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat();
    if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT)
        yAxisFormat = MZmineCore.getConfiguration().getRTFormat();
    yAxis.setNumberFormatOverride(yAxisFormat);

    setTitle(title);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBackground(Color.white);

    // Add the Windows menu
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(new WindowsMenu());
    setJMenuBar(menuBar);

    pack();

    // get the window settings parameter
    ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(IntensityPlotModule.class);
    WindowSettingsParameter settings = paramSet.getParameter(IntensityPlotParameters.windowSettings);

    // update the window and listen for changes
    settings.applySettingsToWindow(this);
    this.addComponentListener(settings);

}

From source file:com.google.jenkins.flakyTestHandler.plugin.TestFlakyStatsOverRevision.java

private JFreeChart createChart(CategoryDataset dataset) {

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart title
            null, // unused
            "count", // range axis label*/master
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*  w  ww. j  a  v  a 2  s .  c o m*/

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    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);

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

    StackedAreaRenderer ar = new StackedAreaRenderer2() {

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            RevisionLabel label = (RevisionLabel) dataset.getColumnKey(column);
            Number value = dataset.getValue(row, column);
            switch (row) {
            case 0:
                return label.revision + ": " + value + " fails";
            case 1:
                return label.revision + ": " + value + " passes";
            default:
                return label.revision;
            }
        }
    };
    plot.setRenderer(ar);
    ar.setSeriesPaint(0, ColorPalette.RED); // Fails.
    ar.setSeriesPaint(1, ColorPalette.BLUE); // Passes.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet.java

public JFreeChart getChart(CategoryDataset dataset) {
    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart3D(" ", // chart title
            "", // domain axis label
            " (.)", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//  w w  w. j  av  a  2 s .  co  m

    //      #44639C;

    TextTitle title = new TextTitle("  ", labelFont);
    //      Paint paint = title.getPaint();
    title.setPaint(new Color(68, 99, 156));
    chart.setTitle(title);

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

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

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    // final IntervalMarker target = new IntervalMarker(2000000, 3000000);
    // target.setLabel(" ");
    // target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    // target.setLabelAnchor(RectangleAnchor.LEFT);
    // target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    // target.setPaint(new Color(222, 222, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setTickLabelFont(labelFont);

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0)
    // CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
    );
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;
}

From source file:hudson.plugins.measurement_plots.Graph.java

protected org.jfree.chart.JFreeChart createGraph() {
    final org.jfree.data.category.CategoryDataset dataset = getDataSetBuilder().build();

    final org.jfree.chart.JFreeChart chart = org.jfree.chart.ChartFactory.createStackedAreaChart(title, // chart title
            null, // unused
            null, // range axis label
            dataset, // data
            org.jfree.chart.plot.PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/*from  w  w w .  j  av  a  2 s.  c om*/

    chart.setBackgroundPaint(java.awt.Color.white);

    final org.jfree.chart.plot.CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(java.awt.Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(java.awt.Color.black);

    org.jfree.chart.axis.CategoryAxis domainAxis = new hudson.util.ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(org.jfree.chart.axis.CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final org.jfree.chart.axis.NumberAxis rangeAxis = (org.jfree.chart.axis.NumberAxis) plot.getRangeAxis();
    hudson.util.ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(org.jfree.chart.axis.NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    org.jfree.chart.renderer.category.StackedAreaRenderer areaRenderer = new hudson.util.StackedAreaRenderer2() {

        @Override
        public java.awt.Paint getItemPaint(int row, int column) {
            GraphLabel key = (GraphLabel) dataset.getColumnKey(column);
            if (key.getColor() != null) {
                return key.getColor();
            }
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
            GraphLabel label = (GraphLabel) dataset.getColumnKey(column);
            return label.getUrl();
        }

        @Override
        public String generateToolTip(org.jfree.data.category.CategoryDataset dataset, int row, int column) {
            GraphLabel label = (GraphLabel) dataset.getColumnKey(column);
            return label.getToolTip();
        }
    };
    plot.setRenderer(areaRenderer);
    areaRenderer.setSeriesPaint(2, hudson.util.ColorPalette.BLUE);

    // crop extra space around the graph
    plot.setInsets(new org.jfree.ui.RectangleInsets(0, 0, 0, 5.0));

    return chart;
}

From source file:virgil.meanback.HistoryInfo.java

public void printChart(Stock stock, List<String[]> list, int days) throws Exception {
    //?/*from   w w  w. java  2 s .co m*/
    StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
    //
    standardChartTheme.setExtraLargeFont(new Font("", Font.BOLD, 20));
    //
    standardChartTheme.setRegularFont(new Font("", Font.BOLD, 12));
    //?
    standardChartTheme.setLargeFont(new Font("", Font.BOLD, 18));
    //?
    ChartFactory.setChartTheme(standardChartTheme);
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    for (int i = list.size() - 1; i >= 0; i--) {
        String[] s = (String[]) list.get(i);
        dataSet.addValue(Double.parseDouble(s[1]), days + "", s[0]);
        dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "", s[0]);
        float sub = Float.parseFloat(s[2]);
        float error = Float.parseFloat(s[3]);
        if (sub > error * 2) {
            dataSet.addValue(Double.parseDouble(stock.getList().get(i).getClose()), "??", s[0]);
        }
    }

    //?????Legend
    //????
    //??URL
    JFreeChart chart = ChartFactory.createLineChart(
            stock.getName() + "(" + stock.getCode() + ") ", "", "", dataSet,
            PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot cp = chart.getCategoryPlot();
    cp.setBackgroundPaint(ChartColor.WHITE); // 
    CategoryAxis categoryAxis = cp.getDomainAxis();
    //  Lable 90 
    Font labelFont = new Font("SansSerif", Font.TRUETYPE_FONT, 10);
    categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    categoryAxis.setTickLabelFont(labelFont);//X?? 
    ValueAxis yAxis = cp.getRangeAxis();
    yAxis.setAutoRange(true);
    double[] d = getAxiasThresold(stock, list);
    yAxis.setLowerBound(d[0] - 0.15);
    yAxis.setUpperBound(d[1] + 0.15);
    LineAndShapeRenderer lasp = (LineAndShapeRenderer) cp.getRenderer();
    lasp.setBaseFillPaint(ChartColor.RED);
    lasp.setDrawOutlines(true);
    lasp.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) cp.getRenderer(1);//?
    DecimalFormat decimalformat1 = new DecimalFormat("##.##");//???
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", decimalformat1));
    //????
    renderer.setItemLabelsVisible(true);//
    renderer.setBaseItemLabelsVisible(true);//
    //?????
    renderer.setShapesFilled(Boolean.TRUE);//??
    renderer.setShapesVisible(true);//?
    ChartFrame chartFrame = new ChartFrame("??", chart, true);
    //chart?JavaChartFramejavaJframe????
    chartFrame.pack(); //??
    chartFrame.setVisible(true);//???
}

From source file:biz.ixnay.pivot.charts.skin.jfree.BarChartViewSkin.java

@Override
protected JFreeChart createChart() {
    BarChartView chartView = (BarChartView) getComponent();

    String title = chartView.getTitle();
    String horizontalAxisLabel = chartView.getHorizontalAxisLabel();
    String verticalAxisLabel = chartView.getVerticalAxisLabel();
    boolean showLegend = chartView.getShowLegend();

    String seriesNameKey = chartView.getSeriesNameKey();
    List<?> chartData = chartView.getChartData();

    // TODO Make plot orientation a style property

    JFreeChart chart;/*w  w w . jav  a 2s .com*/
    ChartView.CategorySequence categories = chartView.getCategories();
    if (categories.getLength() > 0) {
        CategorySeriesDataset dataset = new CategorySeriesDataset(categories, seriesNameKey, chartData);

        if (stacked && threeDimensional) {
            chart = ChartFactory.createStackedBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (stacked) {
            chart = ChartFactory.createStackedBarChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else if (threeDimensional) {
            chart = ChartFactory.createBarChart3D(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        } else {
            chart = ChartFactory.createBarChart(title, horizontalAxisLabel, verticalAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, false, false);
        }

        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        CategoryAxis domainAxis = plot.getDomainAxis();
        CategoryLabelPositions categoryLabelPositions = CategoryLabelPositions
                .createUpRotationLabelPositions(categoryLabelRotation);
        domainAxis.setCategoryLabelPositions(categoryLabelPositions);
    } else {
        // TODO Make the dateAxis argument a style property
        chart = ChartFactory.createXYBarChart(title, horizontalAxisLabel, false, verticalAxisLabel,
                new IntervalSeriesDataset(seriesNameKey, chartData), PlotOrientation.VERTICAL, showLegend,
                false, false);
    }

    return chart;
}

From source file:org.testeditor.dashboard.TableDurationTrend.java

/**
 * designs and creates graph from data sets.
 * /*from   w w  w .j av  a 2s  . c  o m*/
 * @param objektList
 *            list of all suite GoogleSucheSuite runs <AllRunsResult>
 * @param parent
 *            composite parent
 * @param modelService
 *            to find part label
 * @param window
 *            trimmed window
 * @param app
 *            org.eclipse.e4.ide.application
 */
@SuppressWarnings({ "serial" })
@Inject
@Optional
public void createControls(@UIEventTopic("Testobjektlist") List<AllRunsResult> objektList, Composite parent,
        EModelService modelService, MWindow window, MApplication app) {
    MPart mPart = (MPart) modelService.find("org.testeditor.ui.part.2", app);
    String[] arr = objektList.get(0).getFilePath().getName().split("\\.");
    String filenameSplitted = arr[arr.length - 1];
    mPart.setLabel(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " "
            + filenameSplitted);
    mPart.setTooltip(translationService.translate("%dashboard.table.label.duration", CONTRIBUTOR_URI) + " "
            + objektList.get(0).getFilePath().getName());
    parent.setLayout(new FillLayout());

    // create the chart...
    chart = ChartFactory.createBarChart3D(null, // chart
            // title
            translationService.translate("%dashboard.table.label.duration.axis.dates", CONTRIBUTOR_URI), // domain
            // X axis
            // label
            translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI)
                    + " h:m:s:ms", // range
            // Y axis
            // label
            createDataset(objektList), // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    // y axis right
    plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_RIGHT);
    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setNumberFormatOverride(new NumberFormat() { // show duration
        // values in
        // h:m:s:ms
        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            // return new StringBuffer(String.format("%f", number));
            return new StringBuffer(String.format(formatDuration(number)));
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            // return new StringBuffer(String.format("%f", number));
            return new StringBuffer(String.format(formatDuration(number)));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1} "
            + translationService.translate("%dashboard.table.label.duration.axis.duration", CONTRIBUTOR_URI)
            + ": {2}ms", NumberFormat.getInstance()));
    renderer.setDrawBarOutline(false);
    renderer.setMaximumBarWidth(.15);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(1.57));

    Color color = toAwtColor(ColorConstants.COLOR_BLUE);
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, color, 0, 0, color);
    renderer.setSeriesPaint(0, gp0);

    chartComposite = new ChartComposite(parent, SWT.EMBEDDED);
    chartComposite.setSize(800, 800);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    chartComposite.setLayoutData(data);
    chartComposite.setHorizontalAxisTrace(false);
    chartComposite.setVerticalAxisTrace(false);
    chartComposite.setChart(chart);
    chartComposite.pack(true);
    chartComposite.setVisible(true);
    chartComposite.forceRedraw();
    parent.layout();
}

From source file:gg.view.overview.IncomeExpensesTopComponent.java

/** Displays the total income vs expenses for the current month */
public void displayData() {
    log.info("Income vs Expenses graph computed and displayed");

    // Display hourglass cursor
    Utilities.changeCursorWaitStatus(true);

    // Create a dataset (the dataset will contain the plotted values)
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    // Create an empty chart
    JFreeChart chart = ChartFactory.createBarChart("", // chart title
            "", // x axis label
            NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Amount"), // y axis label
            dataset, // data displayed in the chart
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );/*  w w w  . j a  va 2s .  com*/

    // Update the chart color
    chart.setBackgroundPaint(jPanelIncomeExpenses.getBackground());
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);

    // Set the orientation of the categories on the domain axis (X axis)
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.STANDARD);

    // Set the range axis (Y axis) to display integers only
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Set the bar renderer
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setMaximumBarWidth(0.1);

    GradientPaint gradientPaint = new GradientPaint(0.0f, 0.0f, new Color(49, 106, 196), 0.0f, 0.0f,
            Color.LIGHT_GRAY);
    renderer.setSeriesPaint(0, gradientPaint);

    // Create a period for the current month
    LocalDate today = new LocalDate();
    Period currentMonth = new Period(Periods.getAdjustedStartDate(today, PeriodType.MONTH),
            Periods.getAdjustedEndDate(today, PeriodType.MONTH), PeriodType.MONTH);

    // Fill the dataset
    List<Currency> currencies = Wallet.getInstance().getActiveCurrencies();
    for (Currency currency : currencies) {
        // Filter on the currency and on the current month
        SearchCriteria searchCriteria = new SearchCriteria(currency, null, currentMonth, null, null, null,
                false);

        // Get income
        BigDecimal currencyIncome = Datamodel.getIncome(searchCriteria);
        currencyIncome = currencyIncome.setScale(2, RoundingMode.HALF_EVEN);

        // Get expenses
        BigDecimal currencyExpenses = Datamodel.getExpenses(searchCriteria).abs();
        currencyExpenses = currencyExpenses.setScale(2, RoundingMode.HALF_EVEN);

        // Plot income and expenses for the current month and for the current currency on the chart
        dataset.addValue(currencyIncome, currency.getName(),
                NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Income",
                        new Object[] { currency }));

        dataset.addValue(currencyExpenses, currency.getName(),
                NbBundle.getMessage(IncomeExpensesTopComponent.class, "IncomeExpensesTopComponent.Expenses",
                        new Object[] { currency }));
    }

    // Create the chart panel that contains the chart
    ChartPanel chartPanel = new ChartPanel(chart);

    // Display the chart
    jPanelIncomeExpenses.removeAll();
    jPanelIncomeExpenses.add(chartPanel, BorderLayout.CENTER);

    // Display the normal cursor
    Utilities.changeCursorWaitStatus(false);
}

From source file:hudson.plugins.labeledgroupedtests.TrendGraph.java

protected JFreeChart createGraph() {
    final CategoryDataset dataset = createDataSet().build();

    final JFreeChart chart = ChartFactory.createStackedAreaChart(null, // chart
            // title
            null, // unused
            yLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips
            false // urls
    );/* ww w  .  j  av a  2  s .c o m*/

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setForegroundAlpha(0.8f);
    // plot.setDomainGridlinesVisible(true);
    // plot.setDomainGridlinePaint(Color.white);
    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);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    ChartUtil.adjustChebyshev(dataset, rangeAxis);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRange(true);

    StackedAreaRenderer ar = new StackedAreaRenderer2() {
        @Override
        public Paint getItemPaint(int row, int column) {
            ChartLabel key = (ChartLabel) dataset.getColumnKey(column);
            if (key.getColor() != null)
                return key.getColor();
            return super.getItemPaint(row, column);
        }

        @Override
        public String generateURL(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getURL() + relativeUrl;
        }

        @Override
        public String generateToolTip(CategoryDataset dataset, int row, int column) {
            ChartLabel label = (ChartLabel) dataset.getColumnKey(column);
            return label.getToolTipText();
        }
    };
    plot.setRenderer(ar);

    ar.setSeriesPaint(0, ColorPalette.RED); // Skips.
    ar.setSeriesPaint(1, ColorPalette.YELLOW); // Failures.
    ar.setSeriesPaint(2, ColorPalette.BLUE); // Total.

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    return chart;
}