use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.
the class DefaultChartService method getStackedAreaChart.
private JFreeChart getStackedAreaChart(BaseChart chart, CategoryDataset dataSet) {
JFreeChart stackedAreaChart = ChartFactory.createStackedAreaChart(chart.getName(), chart.getDomainAxisLabel(), chart.getRangeAxisLabel(), dataSet, PlotOrientation.VERTICAL, !chart.isHideLegend(), false, false);
setBasicConfig(stackedAreaChart, chart);
CategoryPlot plot = (CategoryPlot) stackedAreaChart.getPlot();
plot.setOrientation(PlotOrientation.VERTICAL);
plot.setRenderer(getStackedAreaRenderer());
CategoryAxis xAxis = plot.getDomainAxis();
xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
xAxis.setLabelFont(LABEL_FONT);
return stackedAreaChart;
}
use of org.jfree.chart.JFreeChart in project dhis2-core by dhis2.
the class DefaultChartService method getGaugeChart.
private JFreeChart getGaugeChart(BaseChart chart, ValueDataset dataSet) {
MeterPlot meterPlot = new MeterPlot(dataSet);
meterPlot.setUnits("");
meterPlot.setRange(new Range(0.0d, 100d));
for (int i = 0; i < 10; i++) {
double start = i * 10;
double end = start + 10;
String label = String.valueOf(start);
meterPlot.addInterval(new MeterInterval(label, new Range(start, end), COLOR_LIGHT_GRAY, null, COLOR_LIGHT_GRAY));
}
meterPlot.setMeterAngle(180);
meterPlot.setDialBackgroundPaint(COLOR_LIGHT_GRAY);
meterPlot.setDialShape(DialShape.CHORD);
meterPlot.setNeedlePaint(COLORS[0]);
meterPlot.setTickLabelsVisible(true);
meterPlot.setTickLabelFont(LABEL_FONT);
meterPlot.setTickLabelPaint(Color.BLACK);
meterPlot.setTickPaint(COLOR_LIGHTER_GRAY);
meterPlot.setValueFont(TITLE_FONT);
meterPlot.setValuePaint(Color.BLACK);
JFreeChart meterChart = new JFreeChart(chart.getName(), meterPlot);
setBasicConfig(meterChart, chart);
meterChart.removeLegend();
return meterChart;
}
use of org.jfree.chart.JFreeChart 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.JFreeChart in project uncommons-maths by dwdyer.
the class GraphPanel method generateGraph.
public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues, double expectedMean, double expectedStandardDeviation, boolean discrete) {
XYSeriesCollection dataSet = new XYSeriesCollection();
XYSeries observedSeries = new XYSeries("Observed");
dataSet.addSeries(observedSeries);
XYSeries expectedSeries = new XYSeries("Expected");
dataSet.addSeries(expectedSeries);
for (Map.Entry<Double, Double> entry : observedValues.entrySet()) {
observedSeries.add(entry.getKey(), entry.getValue());
}
for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) {
expectedSeries.add(entry.getKey(), entry.getValue());
}
JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet, PlotOrientation.VERTICAL, true, false, false);
XYPlot plot = (XYPlot) chart.getPlot();
if (discrete) {
// Render markers at each data point (these discrete points are the
// distibution, not the lines between them).
plot.setRenderer(new XYLineAndShapeRenderer());
} else {
// Render smooth lines between points for a continuous distribution.
XYSplineRenderer renderer = new XYSplineRenderer();
renderer.setBaseShapesVisible(false);
plot.setRenderer(renderer);
}
chartPanel.setChart(chart);
}
use of org.jfree.chart.JFreeChart in project processdash by dtuma.
the class AbstractEVTimeSeriesChart method createEVReportChart.
/**
* Temporary method used by EVReport to build a chart
*/
public static JFreeChart createEVReportChart(XYDataset data) {
JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, data, true, true, false);
RangeXYItemRenderer renderer = new RangeXYItemRenderer();
renderer.putAllSeriesPaints(SERIES_PAINTS);
renderer.putAllSeriesStrokes(SERIES_STROKES);
renderer.setLegendItemLabelGenerator(new SeriesNameGenerator());
renderer.setBaseToolTipGenerator(new EVTimeSeriesTooltipGenerator());
chart.getXYPlot().setRenderer(renderer);
return chart;
}
Aggregations