use of org.jfree.chart.axis.CategoryAxis 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.CategoryAxis 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.CategoryAxis in project processdash by dtuma.
the class CGIChartBase method setupCategoryChart.
protected void setupCategoryChart(JFreeChart chart) {
if (!(chart.getPlot() instanceof CategoryPlot))
return;
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));
}
}
use of org.jfree.chart.axis.CategoryAxis in project violations-plugin by jenkinsci.
the class SeverityTypeDataSet method createChart.
/**
* Create a JFree chart for this dataset.
*
* @return the chart.
*/
public JFreeChart createChart() {
CategoryDataset dataset = buildDataSet();
JFreeChart chart = // chart
ChartFactory.createStackedAreaChart(// chart
null, // unused
null, // range axis label
"count", // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
final LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setForegroundAlpha(ALPHA);
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());
if (Boolean.getBoolean(AbstractViolationsBuildAction.VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
rangeAxis.setAutoRange(true);
rangeAxis.setAutoRangeIncludesZero(false);
rangeAxis.setAutoRangeMinimumSize(50);
}
StackedAreaRenderer renderer = new StackedAreaRenderer2();
plot.setRenderer(renderer);
renderer.setSeriesPaint(2, RED);
renderer.setSeriesPaint(1, VIOLET);
renderer.setSeriesPaint(0, YELLOW);
// crop extra space around the graph
plot.setInsets(new RectangleInsets(0, 0, 0, INSET));
return chart;
}
use of org.jfree.chart.axis.CategoryAxis in project violations-plugin by jenkinsci.
the class AbstractViolationsBuildAction method createChart.
// FIXME this should be in a utility class
protected JFreeChart createChart(CategoryDataset dataset) {
final JFreeChart chart = // chart
ChartFactory.createLineChart(// chart
null, // unused
null, // range axis label
"count", // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
final LegendTitle legend = chart.getLegend();
legend.setPosition(RectangleEdge.RIGHT);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = chart.getCategoryPlot();
if (useLog) {
final NumberAxis rangeAxis2 = new LogarithmicAxis("Log(y)");
plot.setRangeAxis(rangeAxis2);
}
// plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
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());
// rangeAxis.setUpperBound(100);
if (Boolean.getBoolean(VIOLATIONS_PLUGIN_CHART_AUTORANGE_PROPERTY)) {
rangeAxis.setAutoRange(true);
rangeAxis.setAutoRangeIncludesZero(false);
rangeAxis.setAutoRangeMinimumSize(50);
} else {
rangeAxis.setLowerBound(0);
}
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setStroke(new BasicStroke(2.0f));
ColorPalette.apply(renderer);
// crop extra space around the graph
plot.setInsets(new RectangleInsets(PADDING, 0, 0, PADDING));
return chart;
}
Aggregations