use of org.jfree.data.category.DefaultCategoryDataset in project adempiere by adempiere.
the class GraphBuilder method loadData.
/**
*
* @return graph column list
*/
public ArrayList<GraphColumn> loadData() {
// Calculated
MMeasure measure = getMGoal().getMeasure();
if (measure == null) {
log.warning("No Measure for " + getMGoal());
return null;
}
ArrayList<GraphColumn> list = measure.getGraphColumnList(getMGoal());
pieDataset = new DefaultPieDataset();
dataset = new DefaultCategoryDataset();
for (int i = 0; i < list.size(); i++) {
String series = m_X_AxisLabel;
if (list.get(i).getDate() != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(list.get(i).getDate());
series = Integer.toString(cal.get(Calendar.YEAR));
}
dataset.addValue(list.get(i).getValue(), series, list.get(i).getLabel());
linearDataset.addValue(list.get(i).getValue(), m_X_AxisLabel, list.get(i).getLabel());
pieDataset.setValue(list.get(i).getLabel(), list.get(i).getValue());
}
return list;
}
use of org.jfree.data.category.DefaultCategoryDataset in project adempiere by adempiere.
the class WCRP method jbInit.
private void jbInit() throws Exception {
resourceLabel.setText(Msg.translate(Env.getCtx(), "S_Resource_ID"));
dateFromLabel.setText(Msg.translate(Env.getCtx(), "DateFrom"));
Rows rows = new Rows();
Row row = null;
rows.setParent(northPanel);
row = rows.newRow();
row.appendChild(resourceLabel.rightAlign());
row.appendChild(resource.getComponent());
row.appendChild(dateFromLabel.rightAlign());
row.appendChild(dateFrom.getComponent());
centerPanel.appendChild(chartPanel);
JFreeChart jchart = ChartFactory.createBarChart3D("", // X-Axis label
Msg.translate(Env.getCtx(), "Days"), // Y-Axis label
Msg.translate(Env.getCtx(), "Hours"), // Dataset
new DefaultCategoryDataset(), // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips?
true, // URLs?
false);
renderChart(jchart);
confirmPanel.addActionListener(this);
}
use of org.jfree.data.category.DefaultCategoryDataset in project bamboobsc by billchen198318.
the class CommonBarChartAction method fillChart.
private void fillChart(String title, String categoryLabel, String valueLabel, List<String> names, List<Float> values, List<String> colors, boolean horizontal) throws Exception {
DefaultCategoryDataset data = new DefaultCategoryDataset();
for (int ix = 0; ix < names.size(); ix++) {
data.addValue(values.get(ix), "", names.get(ix));
}
this.chart = ChartFactory.createBarChart3D(// title
title, categoryLabel, valueLabel, data, (horizontal ? PlotOrientation.HORIZONTAL : PlotOrientation.VERTICAL), false, false, false);
CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
CategoryAxis categoryAxis = plot.getDomainAxis();
categoryAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
categoryAxis.setTickLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
numberAxis.setLabelFont(new Font("", Font.TRUETYPE_FONT, 9));
this.setPlotColor(plot, names, colors);
this.chart.setTitle(new TextTitle(title, new Font("", Font.TRUETYPE_FONT, 9)));
}
use of org.jfree.data.category.DefaultCategoryDataset 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.DefaultCategoryDataset in project dhis2-core by dhis2.
the class DefaultChartService method getJFreeChart.
@Override
public JFreeChart getJFreeChart(String name, PlotOrientation orientation, CategoryLabelPositions labelPositions, Map<String, Double> categoryValues) {
DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
for (Entry<String, Double> entry : categoryValues.entrySet()) {
dataSet.addValue(entry.getValue(), name, entry.getKey());
}
CategoryPlot plot = getCategoryPlot(dataSet, getBarRenderer(), orientation, labelPositions);
JFreeChart jFreeChart = getBasicJFreeChart(plot);
jFreeChart.setTitle(name);
return jFreeChart;
}
Aggregations