use of org.jfree.chart.renderer.category.StandardBarPainter 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.chart.renderer.category.StandardBarPainter in project adempiere by adempiere.
the class MChart method createStackedBarChart.
private JFreeChart createStackedBarChart() {
JFreeChart chart = ChartFactory.createStackedBarChart(// chart title
getName(), // domain axis label
getDomainLabel(), // range axis label
getRangeLabel(), // data
getCategoryDataset(), X_AD_Chart.CHARTORIENTATION_Horizontal.equals(getChartOrientation()) ? PlotOrientation.HORIZONTAL : // orientation
PlotOrientation.VERTICAL, // include legend
isDisplayLegend(), // tooltips?
true, // URLs?
true);
BarRenderer renderer = new BarRenderer();
renderer.setBarPainter(new StandardBarPainter());
CategoryPlot plot = chart.getCategoryPlot();
plot.setRenderer(renderer);
setupCategoryChart(chart);
return chart;
}
Aggregations