gpt4 book ai didi

java - 在 JFreeChart 堆叠 3D 条形图中更改自定义颜色

转载 作者:行者123 更新时间:2023-12-04 02:45:46 24 4
gpt4 key购买 nike

我已经在网络上搜索了足够多但没有运气。

我创建了一个堆叠的 3d 条形图,其中我无法更改默认颜色。我尝试了所有提供的建议。

下面是我的一小段代码。这是我的意见。

我来自 Db 的数据是:

A   0   2B   15  53C   0   2D   0   2E   0   1F   1   0G   0   1

Somehow I converted this to dataset requirement and also added items and models.

CategoryDataset dataset = DatasetUtilities.createCategoryDataset(item,models, data);
chart = ChartFactory.createStackedBarChart3D(chartDescription, X-axis, Y-axis, dataset,PlotOrientation.VERTICAL, true, true, true);
CategoryPlot plot = chart.getCategoryPlot();
CategoryItemRenderer r = plot.getRenderer();
r.setSeriesPaint(0, Color.GREEN);
r.setSeriesPaint(1, Color.GRAY);
plot.setRenderer(new StackedBarRenderer3D() {

@Override
public Paint getItemPaint(int row, int col) {
System.out.println("row:"+row);
System.out.println("Col:"+col);
return Color.getHSBColor(row / 42f, 1, 1);
}
});
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

StackedBarRenderer3D renderer = (StackedBarRenderer3D)plot.getRenderer();
//renderer.setBarPainter(new StandardBarPainter());
renderer.setSeriesFillPaint(0,Color.BLACK);
renderer.setSeriesFillPaint(1,Color.GREEN);
renderer.setDrawBarOutline(false);
renderer.setShadowVisible(false);
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,TextAnchor.CENTER));
renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setIgnoreZeroValues(true);
renderer.setMaximumBarWidth(.05);
renderer.setBaseItemLabelsVisible(true);
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
renderer.setPositiveItemLabelPositionFallback(new ItemLabelPosition(
ItemLabelAnchor.CENTER, TextAnchor.CENTER_RIGHT));
renderer.setNegativeItemLabelPositionFallback(new ItemLabelPosition(
ItemLabelAnchor.CENTER, TextAnchor.CENTER_RIGHT));
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.CENTER, TextAnchor.TOP_CENTER));
renderer.setBaseNegativeItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.CENTER, TextAnchor.TOP_CENTER));
LegendTitle legend = chart.getLegend(0);
legend.setBackgroundPaint(Color.white);
legend.setFrame(new BlockBorder(Color.green));
StandardChartTheme theme = (StandardChartTheme)org.jfree.chart.StandardChartTheme.createJFreeTheme();
theme.setTitlePaint(Color.decode("#4572a7"));
theme.setExtraLargeFont(new Font("Arial",Font.BOLD, 16) );
theme.setLargeFont(new Font("Arial",Font.BOLD, 15));
theme.setRegularFont( new Font("Arial",Font.PLAIN, 11));
theme.setRangeGridlinePaint(Color.RED);
theme.setPlotBackgroundPaint( Color.white );
theme.setChartBackgroundPaint( Color.white );
theme.setItemLabelPaint(Color.YELLOW);
theme.setShadowVisible(true);
theme.setAxisLabelPaint( Color.decode("#666666") );
theme.apply( chart );

虽然我已经使用了setSeriespaint,但是还是不行。chart,plot,renderer的创建顺序有什么关系吗?

当我打印行和列时,我得到了这个:

row:1Col:0row:0Col:1row:1Col:1row:1Col:2row:1Col:3row:1Col:4row:0Col:5row:1Col:6

最佳答案

您可以覆盖渲染器的getItemPaint(),如图所示here .

plot.setRenderer(new StackedBarRenderer3D() {

@Override
public Paint getItemPaint(int row, int col) {
return Color.getHSBColor(row / 42f, 1, 1);
}
});

plot colors

关于java - 在 JFreeChart 堆叠 3D 条形图中更改自定义颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18866767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com