use of org.jfree.chart.renderer.category.BarPainter in project jpsonic by tesshucom.
the class UserChartController method createChart.
private JFreeChart createChart(CategoryDataset dataset, HttpServletRequest request) {
JFreeChart chart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, false, false, false);
StandardChartTheme theme = (StandardChartTheme) StandardChartTheme.createJFreeTheme();
Font font = fontLoader.getFont(12F);
theme.setExtraLargeFont(font);
theme.setLargeFont(font);
theme.setRegularFont(font);
theme.setSmallFont(font);
theme.apply(chart);
Color bgColor = getBackground(request);
chart.setBackgroundPaint(bgColor);
CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(bgColor);
Color fgColor = getForeground(request);
plot.setOutlinePaint(fgColor);
plot.setRangeGridlinePaint(fgColor);
plot.setRangeGridlineStroke(new BasicStroke(0.2f));
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
BarRenderer renderer = (BarRenderer) plot.getRenderer();
Color stColor = getStroke(request);
renderer.setBarPainter(new BarPainter() {
@Override
public void paintBarShadow(Graphics2D g2, BarRenderer ren, int row, int col, RectangularShape shape, RectangleEdge base, boolean pegShadow) {
// to be none
}
@Override
public void paintBar(Graphics2D g2, BarRenderer ren, int row, int col, RectangularShape shape, RectangleEdge base) {
int barMaxHeight = 15;
double radius = 10.0;
double barX = shape.getX() - radius;
double barY = barMaxHeight < shape.getHeight() ? shape.getY() + (shape.getHeight() - barMaxHeight) / 2 : shape.getY();
double barHeight = barMaxHeight < shape.getHeight() ? barMaxHeight : shape.getHeight();
double barWidth = shape.getWidth() + radius;
RoundRectangle2D rec = new RoundRectangle2D.Double(barX, barY, barWidth, barHeight, radius, radius);
g2.setPaint(new GradientPaint(0, 0, stColor, 0, 150, stColor));
g2.fill(rec);
}
});
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickLabelPaint(fgColor);
domainAxis.setTickMarkPaint(fgColor);
domainAxis.setAxisLinePaint(fgColor);
LogarithmicAxis rangeAxis = new LogarithmicAxis(null);
rangeAxis.setStrictValuesFlag(false);
rangeAxis.setAllowNegativesFlag(true);
rangeAxis.setTickLabelPaint(fgColor);
rangeAxis.setTickMarkPaint(fgColor);
rangeAxis.setAxisLinePaint(fgColor);
return chart;
}
use of org.jfree.chart.renderer.category.BarPainter in project VideoOptimzer by attdevsupport.
the class FileTypesChartPanel method initializeChart.
private JFreeChart initializeChart() {
JFreeChart chart = ChartFactory.createBarChart(ResourceBundleHelper.getMessageString("chart.filetype.title"), null, ResourceBundleHelper.getMessageString("simple.percent"), null, PlotOrientation.HORIZONTAL, false, false, false);
// chart.setBackgroundPaint(fileTypePanel.getBackground());
chart.setBackgroundPaint(this.getBackground());
chart.getTitle().setFont(AROUIManager.HEADER_FONT);
this.cPlot = chart.getCategoryPlot();
cPlot.setBackgroundPaint(Color.white);
cPlot.setDomainGridlinePaint(Color.gray);
cPlot.setRangeGridlinePaint(Color.gray);
cPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
CategoryAxis domainAxis = cPlot.getDomainAxis();
domainAxis.setMaximumCategoryLabelWidthRatio(.5f);
domainAxis.setLabelFont(AROUIManager.LABEL_FONT);
domainAxis.setTickLabelFont(AROUIManager.LABEL_FONT);
NumberAxis rangeAxis = (NumberAxis) cPlot.getRangeAxis();
rangeAxis.setRange(0.0, 100.0);
rangeAxis.setTickUnit(new NumberTickUnit(10));
rangeAxis.setLabelFont(AROUIManager.LABEL_FONT);
rangeAxis.setTickLabelFont(AROUIManager.LABEL_FONT);
BarRenderer renderer = new StackedBarRenderer();
renderer.setBasePaint(AROUIManager.CHART_BAR_COLOR);
renderer.setAutoPopulateSeriesPaint(false);
renderer.setBaseItemLabelGenerator(new PercentLabelGenerator());
renderer.setBaseItemLabelsVisible(true);
renderer.setBaseItemLabelPaint(Color.black);
// Make second bar in stack invisible
renderer.setSeriesItemLabelsVisible(1, false);
renderer.setSeriesPaint(1, new Color(0, 0, 0, 0));
renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() {
@Override
public String generateToolTip(CategoryDataset dataset, int row, int column) {
FileTypeSummary summary = fileTypeContent.get(column);
return MessageFormat.format(ResourceBundleHelper.getMessageString("chart.filetype.tooltip"), NumberFormat.getIntegerInstance().format(summary.getBytes()));
}
});
ItemLabelPosition insideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.INSIDE3, TextAnchor.CENTER_RIGHT);
renderer.setBasePositiveItemLabelPosition(insideItemlabelposition);
ItemLabelPosition outsideItemlabelposition = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT);
renderer.setPositiveItemLabelPositionFallback(outsideItemlabelposition);
BarPainter painter = new StandardBarPainter();
renderer.setBarPainter(painter);
renderer.setShadowVisible(false);
renderer.setMaximumBarWidth(0.1);
cPlot.setRenderer(renderer);
cPlot.getDomainAxis().setMaximumCategoryLabelLines(2);
return chart;
}
Aggregations