Search in sources :

Example 1 with BarPainter

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;
}
Also used : BasicStroke(java.awt.BasicStroke) StandardChartTheme(org.jfree.chart.StandardChartTheme) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) GradientPaint(java.awt.GradientPaint) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font) CategoryPlot(org.jfree.chart.plot.CategoryPlot) GradientPaint(java.awt.GradientPaint) BarPainter(org.jfree.chart.renderer.category.BarPainter) Graphics2D(java.awt.Graphics2D) LogarithmicAxis(org.jfree.chart.axis.LogarithmicAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) RectangularShape(java.awt.geom.RectangularShape) RectangleEdge(org.jfree.chart.ui.RectangleEdge)

Example 2 with BarPainter

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;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) Color(java.awt.Color) StackedBarRenderer(org.jfree.chart.renderer.category.StackedBarRenderer) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) FileTypeSummary(com.att.aro.ui.model.overview.FileTypeSummary) JFreeChart(org.jfree.chart.JFreeChart) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) BarPainter(org.jfree.chart.renderer.category.BarPainter) CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryToolTipGenerator(org.jfree.chart.labels.CategoryToolTipGenerator) CategoryDataset(org.jfree.data.category.CategoryDataset) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition)

Aggregations

Color (java.awt.Color)2 JFreeChart (org.jfree.chart.JFreeChart)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 BarPainter (org.jfree.chart.renderer.category.BarPainter)2 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)2 FileTypeSummary (com.att.aro.ui.model.overview.FileTypeSummary)1 BasicStroke (java.awt.BasicStroke)1 Font (java.awt.Font)1 GradientPaint (java.awt.GradientPaint)1 Graphics2D (java.awt.Graphics2D)1 RectangularShape (java.awt.geom.RectangularShape)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 StandardChartTheme (org.jfree.chart.StandardChartTheme)1 LogarithmicAxis (org.jfree.chart.axis.LogarithmicAxis)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 NumberTickUnit (org.jfree.chart.axis.NumberTickUnit)1 CategoryToolTipGenerator (org.jfree.chart.labels.CategoryToolTipGenerator)1 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)1 CategoryPlot (org.jfree.chart.plot.CategoryPlot)1 StackedBarRenderer (org.jfree.chart.renderer.category.StackedBarRenderer)1