Search in sources :

Example 11 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project processdash by dtuma.

the class ScheduleBalancingDialog method addChartToPanel.

private void addChartToPanel(JPanel panel, int gridY) {
    // create a dataset for displaying schedule data
    chartData = new ChartData();
    updateChart();
    // customize a renderer for displaying schedules
    XYBarRenderer renderer = new XYBarRenderer();
    renderer.setUseYInterval(true);
    renderer.setBaseToolTipGenerator(chartData);
    renderer.setDrawBarOutline(true);
    // use an inverted, unadorned numeric Y-axis
    NumberAxis yAxis = new NumberAxis();
    yAxis.setInverted(true);
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setUpperMargin(0);
    // use a Date-based X-axis
    DateAxis xAxis = new DateAxis();
    // create an XY plot to display the data
    XYPlot plot = new XYPlot(chartData, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(false);
    plot.setNoDataMessage(TaskScheduleDialog.resources.getString("Chart.No_Data_Message"));
    // create a chart and a chart panel
    JFreeChart chart = new JFreeChart(plot);
    chart.removeLegend();
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setInitialDelay(50);
    chartPanel.setDismissDelay(60000);
    chartPanel.setMinimumDrawHeight(40);
    chartPanel.setMinimumDrawWidth(40);
    chartPanel.setMaximumDrawHeight(3000);
    chartPanel.setMaximumDrawWidth(3000);
    chartPanel.setPreferredSize(new Dimension(300, gridY * 25));
    // add the chart to the dialog content pane
    GridBagConstraints c = new GridBagConstraints();
    c.gridy = gridY;
    c.gridwidth = 4;
    c.weightx = 2;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(10, 0, 0, 0);
    panel.add(chartPanel, c);
    // colors with the schedule rows so they can act as a legend
    for (int i = scheduleRows.size(); i-- > 0; ) {
        ScheduleTableRow oneRow = scheduleRows.get(i);
        oneRow.addColoredIcon(renderer.lookupSeriesPaint(i));
    }
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) GridBagConstraints(java.awt.GridBagConstraints) NumberAxis(org.jfree.chart.axis.NumberAxis) ChartPanel(org.jfree.chart.ChartPanel) Insets(java.awt.Insets) XYPlot(org.jfree.chart.plot.XYPlot) Dimension(java.awt.Dimension) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint)

Example 12 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project dhis2-core by dhis2.

the class DefaultChartService method getJFreeChart.

/**
     * Returns a JFreeChart of type defined in the chart argument.
     */
private JFreeChart getJFreeChart(BaseChart chart) {
    final CategoryDataset[] dataSets = getCategoryDataSet(chart);
    final CategoryDataset dataSet = dataSets[0];
    final BarRenderer barRenderer = getBarRenderer();
    final LineAndShapeRenderer lineRenderer = getLineRenderer();
    // ---------------------------------------------------------------------
    // Plot
    // ---------------------------------------------------------------------
    CategoryPlot plot = null;
    if (chart.isType(ChartType.LINE)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), lineRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (chart.isType(ChartType.COLUMN)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
    } else if (chart.isType(ChartType.BAR)) {
        plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), barRenderer);
        plot.setOrientation(PlotOrientation.HORIZONTAL);
    } else if (chart.isType(ChartType.AREA)) {
        return getStackedAreaChart(chart, dataSet);
    } else if (chart.isType(ChartType.PIE)) {
        return getMultiplePieChart(chart, dataSets);
    } else if (chart.isType(ChartType.STACKED_COLUMN)) {
        return getStackedBarChart(chart, dataSet, false);
    } else if (chart.isType(ChartType.STACKED_BAR)) {
        return getStackedBarChart(chart, dataSet, true);
    } else if (chart.isType(ChartType.RADAR)) {
        return getRadarChart(chart, dataSet);
    } else if (chart.isType(ChartType.GAUGE)) {
        Number number = dataSet.getValue(0, 0);
        ValueDataset valueDataSet = new DefaultValueDataset(number);
        return getGaugeChart(chart, valueDataSet);
    } else {
        throw new IllegalArgumentException("Illegal or no chart type: " + chart.getType());
    }
    if (chart.isRegression()) {
        plot.setDataset(1, dataSets[1]);
        plot.setRenderer(1, lineRenderer);
    }
    JFreeChart jFreeChart = new JFreeChart(chart.getName(), TITLE_FONT, plot, !chart.isHideLegend());
    setBasicConfig(jFreeChart, chart);
    if (chart.isTargetLine()) {
        plot.addRangeMarker(getMarker(chart.getTargetLineValue(), chart.getTargetLineLabel()));
    }
    if (chart.isBaseLine()) {
        plot.addRangeMarker(getMarker(chart.getBaseLineValue(), chart.getBaseLineLabel()));
    }
    if (chart.isHideSubtitle()) {
        jFreeChart.addSubtitle(getSubTitle(chart));
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // ---------------------------------------------------------------------
    // Category label positions
    // ---------------------------------------------------------------------
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    domainAxis.setLabel(chart.getDomainAxisLabel());
    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setLabel(chart.getRangeAxisLabel());
    return jFreeChart;
}
Also used : DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) NumberAxis(org.jfree.chart.axis.NumberAxis) ValueDataset(org.jfree.data.general.ValueDataset) DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) JFreeChart(org.jfree.chart.JFreeChart) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 13 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project dhis2-core by dhis2.

the class DefaultChartService method getCategoryPlot.

/**
     * Returns a CategoryPlot.
     */
private CategoryPlot getCategoryPlot(CategoryDataset dataSet, CategoryItemRenderer renderer, PlotOrientation orientation, CategoryLabelPositions labelPositions) {
    CategoryPlot plot = new CategoryPlot(dataSet, new CategoryAxis(), new NumberAxis(), renderer);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setOrientation(orientation);
    CategoryAxis xAxis = plot.getDomainAxis();
    xAxis.setCategoryLabelPositions(labelPositions);
    return plot;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis)

Example 14 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project gephi by gephi.

the class ChartUtils method scaleChart.

public static void scaleChart(JFreeChart chart, XYSeries dSeries, boolean normalized) {
    XYPlot plot = (XYPlot) chart.getPlot();
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(1.0);
    domainAxis.setUpperMargin(1.0);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    if (normalized) {
        domainAxis.setRange(-0.05, 1.05);
    } else {
        domainAxis.setRange(dSeries.getMinX() - 1, dSeries.getMaxX() + 1);
    }
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(-0.1 * Math.sqrt(dSeries.getMaxY()), dSeries.getMaxY() + 0.1 * Math.sqrt(dSeries.getMaxY()));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis)

Example 15 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project gephi by gephi.

the class ChartsUtils method buildBoxPlot.

/**
     * Build a new box-plot from an array of numbers using a default title and yLabel.
     * String dataName will be used for xLabel.
     * @param numbers Numbers for building box-plot
     * @param dataName Name of the numbers data
     * @return Prepared box-plot
     */
public static JFreeChart buildBoxPlot(final Number[] numbers, final String dataName) {
    if (numbers == null || numbers.length == 0) {
        return null;
    }
    DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();
    final ArrayList<Number> list = new ArrayList<>();
    list.addAll(Arrays.asList(numbers));
    final String valuesString = getMessage("ChartsUtils.report.box-plot.values");
    dataset.add(list, valuesString, "");
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMeanVisible(false);
    renderer.setFillBox(false);
    renderer.setMaximumBarWidth(0.5);
    final CategoryAxis xAxis = new CategoryAxis(dataName);
    final NumberAxis yAxis = new NumberAxis(getMessage("ChartsUtils.report.box-plot.values-range"));
    yAxis.setAutoRangeIncludesZero(false);
    renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setRenderer(renderer);
    JFreeChart boxPlot = new JFreeChart(getMessage("ChartsUtils.report.box-plot.title"), plot);
    return boxPlot;
}
Also used : BoxAndWhiskerRenderer(org.jfree.chart.renderer.category.BoxAndWhiskerRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) BoxAndWhiskerToolTipGenerator(org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ArrayList(java.util.ArrayList) DefaultBoxAndWhiskerCategoryDataset(org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

NumberAxis (org.jfree.chart.axis.NumberAxis)26 JFreeChart (org.jfree.chart.JFreeChart)21 CategoryAxis (org.jfree.chart.axis.CategoryAxis)12 CategoryPlot (org.jfree.chart.plot.CategoryPlot)11 XYPlot (org.jfree.chart.plot.XYPlot)10 RectangleInsets (org.jfree.ui.RectangleInsets)10 DateAxis (org.jfree.chart.axis.DateAxis)9 Color (java.awt.Color)6 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)6 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)6 Paint (java.awt.Paint)5 CategoryDataset (org.jfree.data.category.CategoryDataset)5 BasicStroke (java.awt.BasicStroke)4 Font (java.awt.Font)4 LocalDate (java.time.LocalDate)4 StackedAreaRenderer (org.jfree.chart.renderer.category.StackedAreaRenderer)4 ShiftedCategoryAxis (hudson.util.ShiftedCategoryAxis)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3