use of org.jfree.data.category.DefaultCategoryDataset in project EnrichmentMapApp by BaderLab.
the class ChartUtil method createHeatMapLegend.
@SuppressWarnings("serial")
public static JFreeChart createHeatMapLegend(List<EMDataSet> dataSets, ChartOptions options) {
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (EMDataSet ds : dataSets) dataset.addValue(1, options.getData().toString(), ds.getName());
final JFreeChart chart = ChartFactory.createBarChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, PlotOrientation.HORIZONTAL, // include legend
false, // tooltips
true, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(UIManager.getColor("Table.background"));
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 20.0));
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setBackgroundPaint(UIManager.getColor("Table.background"));
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(true);
domainAxis.setAxisLineVisible(false);
domainAxis.setTickMarksVisible(false);
domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
domainAxis.setTickLabelPaint(UIManager.getColor("Label.foreground"));
domainAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 15.0));
domainAxis.setCategoryMargin(0.0);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(false);
ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
if (// UP, ZERO, DOWN:
colors == null || colors.size() < 3)
colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
List<Color> itemColors = new ArrayList<>();
int total = dataSets.size();
int v = total / 2;
for (int i = 0; i < total; i++) itemColors.add(ColorUtil.getColor(v--, -total, total, colors.get(2), colors.get(1), colors.get(0)));
final BarRenderer renderer = new BarRenderer() {
@Override
public Paint getItemPaint(int row, int column) {
return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
}
};
plot.setRenderer(renderer);
renderer.setBarPainter(new StandardBarPainter());
renderer.setDrawBarOutline(true);
renderer.setShadowVisible(false);
renderer.setItemMargin(0.0);
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
return chart;
}
use of org.jfree.data.category.DefaultCategoryDataset in project libresonic by Libresonic.
the class UserChartController method createDataset.
private CategoryDataset createDataset(String type) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
List<User> users = securityService.getAllUsers();
for (User user : users) {
double value;
if ("stream".equals(type)) {
value = user.getBytesStreamed();
} else if ("download".equals(type)) {
value = user.getBytesDownloaded();
} else if ("upload".equals(type)) {
value = user.getBytesUploaded();
} else if ("total".equals(type)) {
value = user.getBytesStreamed() + user.getBytesDownloaded() + user.getBytesUploaded();
} else {
throw new RuntimeException("Illegal chart type: " + type);
}
value /= BYTES_PER_MB;
dataset.addValue(value, "Series", user.getUsername());
}
return dataset;
}
use of org.jfree.data.category.DefaultCategoryDataset in project opennms by OpenNMS.
the class ChartUtils method buildCategoryDataSet.
/**
* @param chartConfig
* @param baseDataSet
* @throws SQLException
*/
private static DefaultCategoryDataset buildCategoryDataSet(BarChart chartConfig) throws SQLException {
DefaultCategoryDataset baseDataSet = new DefaultCategoryDataset();
/*
* Configuration can contain more than one series. This loop adds
* single series data sets returned from sql query to a base data set
* to be displayed in a the chart.
*/
Connection conn = null;
try {
conn = DataSourceFactory.getInstance().getConnection();
Iterator<SeriesDef> it = chartConfig.getSeriesDefCollection().iterator();
while (it.hasNext()) {
SeriesDef def = it.next();
JDBCCategoryDataset dataSet = new JDBCCategoryDataset(conn, def.getJdbcDataSet().getSql());
for (int i = 0; i < dataSet.getRowCount(); i++) {
for (int j = 0; j < dataSet.getColumnCount(); j++) {
baseDataSet.addValue(dataSet.getValue(i, j), def.getSeriesName(), dataSet.getColumnKey(j));
}
}
}
} finally {
if (conn != null) {
conn.close();
}
}
return baseDataSet;
}
use of org.jfree.data.category.DefaultCategoryDataset in project cubrid-manager by CUBRID.
the class CombinedBarTimeSeriesChart method createBarChart.
/**
* Create a bar chart instance.
*
* @return a bar chart instance
*/
private JFreeChart createBarChart() {
bardataset = new DefaultCategoryDataset();
if (valueMap != null) {
for (String key : valueMap.keySet()) {
bardataset.addValue(0D, key, "");
}
}
bardataset.addValue(barMax, "100", "");
JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", bardataset, PlotOrientation.VERTICAL, false, false, false);
chart.setBorderVisible(false);
chart.setBorderStroke(new BasicStroke(0.0f));
chart.setBackgroundPaint(Color.BLACK);
//plot
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
categoryplot.setOutlineVisible(false);
RectangleInsets rectangleInsets = new RectangleInsets();
categoryplot.setAxisOffset(rectangleInsets);
categoryplot.setBackgroundPaint(Color.BLACK);
categoryplot.setDomainGridlinesVisible(false);
categoryplot.setRangeGridlinesVisible(false);
//renderer
StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer(0);
stackedbarrenderer.setDrawBarOutline(false);
stackedbarrenderer.setMaximumBarWidth(0.6);
stackedbarrenderer.setItemMargin(0);
//painter
StandardBarPainter painter = new StandardBarPainter() {
private static final long serialVersionUID = -3124115075260902181L;
public void paintBar(Graphics2D g2, BarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {
Paint itemPaint = renderer.getItemPaint(row, column);
GradientPaintTransformer t = renderer.getGradientPaintTransformer();
if (t != null && itemPaint instanceof GradientPaint) {
itemPaint = t.transform((GradientPaint) itemPaint, bar);
}
g2.setPaint(itemPaint);
double height = bar.getHeight();
double width = bar.getWidth();
double x = bar.getBounds2D().getX();
double y = bar.getBounds2D().getY();
int barNumber = (int) (height / 2 + 0.5);
if (height < 1 && height > 0.5) {
barNumber = 1;
}
for (int i = 0; i < barNumber; i++) {
RectangularShape subBarLeft = new Rectangle2D.Double(x, y, width / 2, 0.8);
g2.fill(subBarLeft);
RectangularShape subBarRight = new Rectangle2D.Double(x + width / 2 + 1, y, width / 2, 0.8);
g2.fill(subBarRight);
y += 2;
}
if (renderer.isDrawBarOutline()) {
Stroke stroke = renderer.getItemOutlineStroke(row, column);
Paint paint = renderer.getItemOutlinePaint(row, column);
if (stroke != null && paint != null) {
g2.setStroke(stroke);
g2.setPaint(paint);
g2.draw(bar);
}
}
}
};
stackedbarrenderer.setBarPainter(painter);
stackedbarrenderer.setSeriesPaint(0, Color.GREEN);
stackedbarrenderer.setSeriesPaint(1, Color.RED);
int backPaintOrder = 1;
if (valueMap != null) {
backPaintOrder = valueMap.size();
}
stackedbarrenderer.setSeriesPaint(backPaintOrder, new Color(136, 200, 135));
stackedbarrenderer.setShadowVisible(false);
stackedbarrenderer.setDrawBarOutline(false);
//categoryAxis
categoryAxis = categoryplot.getDomainAxis();
categoryAxis.setAxisLineVisible(false);
// categoryAxis.setCategoryMargin(0);
categoryAxis.setMinorTickMarksVisible(false);
categoryAxis.setTickLabelsVisible(false);
categoryAxis.setTickMarksVisible(false);
categoryAxis.setLabelPaint(Color.GREEN);
categoryAxis.setLabelFont(new Font("", 0, 10));
//valueAxis
ValueAxis valueAxis = categoryplot.getRangeAxis();
valueAxis.setVisible(false);
return chart;
}
use of org.jfree.data.category.DefaultCategoryDataset in project adempiere by adempiere.
the class MChart method getCategoryDataset.
public CategoryDataset getCategoryDataset() {
dataset = new DefaultCategoryDataset();
loadData();
return (CategoryDataset) dataset;
}
Aggregations