@Override
public CategoryChart getChart() {
// Create Chart
CategoryChart chart =
new CategoryChartBuilder()
.width(1200)
.height(500)
.title("AAA")
.build();
CategoryStyler styler = chart.getStyler();
// Customize Chart
styler.setPlotContentSize(0.8);
styler.setChartPadding(5);
styler.setPlotBackgroundColor(ChartColor.WHITE.getColor());
styler.setChartBackgroundColor(ChartColor.WHITE.getColor());
styler.setChartTitleFont(new Font("宋体", Font.PLAIN, 14));
styler.setChartTitleBoxVisible(false);
styler.setLabelsVisible(true);
styler.setLegendVisible(true);
styler.setStacked(true);
styler.setLegendPosition(Styler.LegendPosition.InsideNE);
styler.setLegendLayout(Styler.LegendLayout.Horizontal);
styler.setLegendFont(new Font("宋体", Font.PLAIN, 14));
styler.setLegendBorderColor(Color.WHITE);
styler.setXAxisLabelRotation(45);
styler.setXAxisLabelAlignment(AxesChartStyler.TextAlignment.Right);
styler.setyAxisTickLabelsFormattingFunction((value) -> {
if (value < 0) {
System.out.println("fuck");
}
System.out.println("format label,before:" + value.longValue() + ",after:" + FileUtils.byteCountToDisplaySize(value.longValue()));
return FileUtils.byteCountToDisplaySize(value.longValue());
});
styler.setXAxisLabelAlignment(AxesChartStyler.TextAlignment.Right);
styler.setSeriesColors(new Color[]{new Color(84, 112, 198), new Color(145, 204, 117), new Color(250, 200, 88),
new Color(238, 102, 102), new Color(115, 192, 222), new Color(59, 162, 114),
new Color(252, 132, 82), new Color(154, 96, 180), new Color(234, 124, 204)});
List<String> x = Arrays.stream(new String[]{"others", "aaaaaaaa", "bbbbbbbb", "ccccccc", "ddddddd", "eeeeeee"}).collect(Collectors.toList());
List<Long> y = Arrays.stream(new Long[]{23073516369L, 1466500686L, 1248980380L, 1248980380L, 60126163L, 60126163L}).collect(Collectors.toList());
styler.setYAxisMin(y.stream().reduce(Long::min).orElse(0L).doubleValue());
CategorySeries series = chart.addSeries("1111111", x, y);
System.out.println("series y min:" + series.getYMin());
return chart;
}