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));
}
}
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;
}
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;
}
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()));
}
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;
}
Aggregations