use of org.jfree.data.category.CategoryDataset in project libresonic by Libresonic.
the class UserChartController method handleRequest.
@RequestMapping(method = RequestMethod.GET)
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
String type = request.getParameter("type");
CategoryDataset dataset = createDataset(type);
JFreeChart chart = createChart(dataset, request);
int imageHeight = Math.max(IMAGE_MIN_HEIGHT, 15 * dataset.getColumnCount());
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, imageHeight);
return null;
}
use of org.jfree.data.category.CategoryDataset in project adempiere by adempiere.
the class MChart method getCategoryDataset.
public CategoryDataset getCategoryDataset() {
dataset = new DefaultCategoryDataset();
loadData();
return (CategoryDataset) dataset;
}
use of org.jfree.data.category.CategoryDataset in project dhis2-core by dhis2.
the class DefaultChartService method getCategoryDataSet.
private CategoryDataset[] getCategoryDataSet(BaseChart chart) {
Map<String, Object> valueMap = new HashMap<>();
if (chart.isAnalyticsType(AnalyticsType.AGGREGATE)) {
valueMap = analyticsService.getAggregatedDataValueMapping(chart);
} else if (chart.isAnalyticsType(AnalyticsType.EVENT)) {
Grid grid = eventAnalyticsService.getAggregatedEventData(chart);
chart.setDataItemGrid(grid);
valueMap = GridUtils.getMetaValueMapping(grid, (grid.getWidth() - 1));
}
DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();
SimpleRegression regression = new SimpleRegression();
BaseAnalyticalObject.sortKeys(valueMap);
List<NameableObject> seriez = new ArrayList<>(chart.series());
List<NameableObject> categories = new ArrayList<>(chart.category());
if (chart.hasSortOrder()) {
categories = getSortedCategories(categories, chart, valueMap);
}
for (NameableObject series : seriez) {
double categoryIndex = 0;
for (NameableObject category : categories) {
categoryIndex++;
String key = getKey(series, category, chart.getAnalyticsType());
Object object = valueMap.get(key);
Number value = object != null && object instanceof Number ? (Number) object : null;
regularDataSet.addValue(value, series.getShortName(), category.getShortName());
if (chart.isRegression() && value != null && value instanceof Double && !MathUtils.isEqual((Double) value, MathUtils.ZERO)) {
regression.addData(categoryIndex, (Double) value);
}
}
if (// Period must be category
chart.isRegression()) {
categoryIndex = 0;
for (NameableObject category : chart.category()) {
final double value = regression.predict(categoryIndex++);
if (!Double.isNaN(value)) {
regressionDataSet.addValue(value, TREND_PREFIX + series.getShortName(), category.getShortName());
}
}
}
}
return new CategoryDataset[] { regularDataSet, regressionDataSet };
}
use of org.jfree.data.category.CategoryDataset in project processdash by dtuma.
the class AreaChart method createChart.
/** Create a line chart. */
public JFreeChart createChart() {
JFreeChart chart;
CategoryDataset catData = data.catDataSource();
Object stacked = parameters.get("stacked");
if (stacked != null) {
chart = ChartFactory.createStackedAreaChart(null, null, null, catData, PlotOrientation.VERTICAL, true, true, false);
if ("pct".equals(stacked)) {
((StackedAreaRenderer) chart.getCategoryPlot().getRenderer()).setRenderAsPercentages(true);
DecimalFormat fmt = new DecimalFormat();
fmt.setMultiplier(100);
((NumberAxis) chart.getCategoryPlot().getRangeAxis()).setNumberFormatOverride(fmt);
if (parameters.get("units") == null)
parameters.put("units", "%");
}
} else {
chart = ChartFactory.createAreaChart(null, null, null, catData, PlotOrientation.VERTICAL, true, true, false);
}
setupCategoryChart(chart);
Object colorScheme = parameters.get("colorScheme");
if ("consistent".equals(colorScheme))
configureConsistentColors(chart.getCategoryPlot(), catData);
else if (parameters.containsKey("c1"))
configureIndividualColors(chart.getCategoryPlot(), catData);
return chart;
}
use of org.jfree.data.category.CategoryDataset in project processdash by dtuma.
the class RadarChart method createChart.
/** Create a radar chart. */
@Override
public JFreeChart createChart() {
maybeScaleDataAxes();
CategoryDataset catData = data.catDataSource();
PieDataset pieData = null;
if (catData.getRowCount() == 1)
pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
else
pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
RadarPlot plot = new RadarPlot(pieData);
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
if (parameters.get("skipAxisLabels") != null)
plot.setShowAxisLabels(false);
String interiorGap = getParameter("interiorGap");
if (interiorGap != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
} catch (NumberFormatException e) {
}
String interiorSpacing = getParameter("interiorSpacing");
if (interiorSpacing != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
} catch (NumberFormatException e) {
}
return chart;
}
Aggregations