use of org.jfree.data.category.CategoryDataset in project adempiere by adempiere.
the class VCRP method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
Timestamp date = null;
if (dateFrom.getValue() != null)
date = (Timestamp) dateFrom.getValue();
int S_Resource_ID = 0;
if (resource.getValue() != null)
S_Resource_ID = ((Integer) resource.getValue()).intValue();
if (date != null && S_Resource_ID != 0) {
MResource r = MResource.get(Env.getCtx(), S_Resource_ID);
int uom_id = r.getResourceType().getC_UOM_ID();
MUOM uom = MUOM.get(Env.getCtx(), uom_id);
CategoryDataset dataset = null;
if (uom.isHour()) {
dataset = createDataset(date, r);
} else {
dataset = createWeightDataset(date, r);
}
String title = r.getName() != null ? r.getName() : "";
title = title + " " + r.getDescription() != null ? r.getDescription() : "";
JFreeChart jfreechart = createChart(dataset, title, uom);
centerPanel.removeAll();
chartPanel = new ChartPanel(jfreechart, false);
centerPanel.add(chartPanel, BorderLayout.CENTER);
centerPanel.setVisible(true);
m_frame.pack();
}
}
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
dispose();
}
}
use of org.jfree.data.category.CategoryDataset in project adempiere by adempiere.
the class WCRP method onEvent.
@Override
public void onEvent(Event event) throws Exception {
String cmd = event.getTarget().getId();
if (cmd.equals(ConfirmPanel.A_OK)) {
Timestamp date = null;
if (dateFrom.getValue() != null)
date = (Timestamp) dateFrom.getValue();
int S_Resource_ID = 0;
if (resource.getValue() != null)
S_Resource_ID = ((Integer) resource.getValue()).intValue();
if (date != null && S_Resource_ID != 0) {
MResource r = MResource.get(Env.getCtx(), S_Resource_ID);
int uom_id = r.getResourceType().getC_UOM_ID();
MUOM uom = MUOM.get(Env.getCtx(), uom_id);
CategoryDataset dataset = null;
if (uom.isHour()) {
dataset = createDataset(date, r);
} else {
dataset = createWeightDataset(date, r);
}
String title = r.getName() != null ? r.getName() : "";
title = title + " " + r.getDescription() != null ? r.getDescription() : "";
JFreeChart jfreechart = createChart(dataset, title, uom);
renderChart(jfreechart);
}
}
if (cmd.equals(ConfirmPanel.A_CANCEL)) {
dispose();
}
}
use of org.jfree.data.category.CategoryDataset 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.data.category.CategoryDataset in project processdash by dtuma.
the class DiscChart method createDiscChart.
public static JFreeChart createDiscChart(ResultSet data, Map parameters) {
// data.sortBy(1, true);
CategoryDataset catData = data.catDataSource();
PieDataset pieData = null;
if (catData.getColumnCount() == 1)
pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
else
pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
DiscPlot plot = new DiscPlot(pieData);
plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
plot.setDrawingSupplier(DRAWING_SUPPLIER_FACTORY.newDrawingSupplier());
JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
if (parameters.get("skipItemLabels") != null || parameters.get("skipDiscLabels") != null)
plot.setLabelGenerator(null);
else if (parameters.get("discLabelFontSize") != null)
try {
float fontSize = Float.parseFloat((String) parameters.get("discLabelFontSize"));
plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
if (parameters.get("ellipse") != null)
((StandardDiscItemDistributor) plot.getDiscDistributor()).setCircular(false);
String interiorGap = (String) parameters.get("interiorGap");
if (interiorGap != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
} catch (NumberFormatException e) {
}
String interiorSpacing = (String) parameters.get("interiorSpacing");
if (interiorSpacing != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
} catch (NumberFormatException e) {
}
return chart;
}
use of org.jfree.data.category.CategoryDataset in project processdash by dtuma.
the class PieChart method createChart.
/** Create a line chart. */
@Override
public JFreeChart createChart() {
CategoryDataset catData = data.catDataSource();
PieDataset pieData = null;
if (catData.getColumnCount() == 1)
pieData = DatasetUtilities.createPieDatasetForColumn(catData, 0);
else
pieData = DatasetUtilities.createPieDatasetForRow(catData, 0);
JFreeChart chart = null;
if (get3DSetting()) {
chart = ChartFactory.createPieChart3D(null, pieData, true, true, false);
chart.getPlot().setForegroundAlpha(ALPHA);
} else {
chart = ChartFactory.createPieChart(null, pieData, true, true, false);
}
PiePlot plot = (PiePlot) chart.getPlot();
if (parameters.get("skipItemLabels") != null || parameters.get("skipWedgeLabels") != null)
plot.setLabelGenerator(null);
else if (parameters.get("wedgeLabelFontSize") != null)
try {
float fontSize = Float.parseFloat((String) parameters.get("wedgeLabelFontSize"));
plot.setLabelFont(plot.getLabelFont().deriveFont(fontSize));
} catch (Exception lfe) {
}
if (parameters.get("ellipse") != null)
plot.setCircular(true);
else
plot.setCircular(false);
Object colorScheme = parameters.get("colorScheme");
if ("byPhase".equals(colorScheme))
maybeConfigurePhaseColors(plot, pieData);
else if ("consistent".equals(colorScheme))
// since 2.0.9
configureConsistentColors(plot, pieData);
else if (parameters.containsKey("c1"))
configureIndividualColors(plot, pieData);
String interiorGap = (String) parameters.get("interiorGap");
if (interiorGap != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorGap) / 100.0);
} catch (NumberFormatException e) {
}
String interiorSpacing = (String) parameters.get("interiorSpacing");
if (interiorSpacing != null)
try {
plot.setInteriorGap(Integer.parseInt(interiorSpacing) / 200.0);
} catch (NumberFormatException e) {
}
if (!parameters.containsKey("showZeroValues")) {
plot.setIgnoreZeroValues(true);
plot.setIgnoreNullValues(true);
}
return chart;
}
Aggregations