这听起来可能很愚蠢,但我只想在 JfreeChart 和透明背景中显示条形图。所有示例都显示了如何创建具有透明背景的 PNG,但这不是我想要的,我只是想显示它,不需要创建它。
此外,我找不到在水平和垂直轴上“禁用”文本的方法。我只想要轴和条的线,就这么简单。这是代码:
private static JFreeChart createActivityBarGraph(CategoryDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createBarChart(
null, // chart title
null, // domain axis label
null, // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
false, // include legend
false, // tooltips?
false // URLs?
);
// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
// set the background color for the chart to be transparent
chart.setBackgroundPaint( new Color(255,255,255,0) );
chart.setBorderVisible(false);
CategoryPlot cPlot = chart.getCategoryPlot();
cPlot.setBackgroundPaint( new Color(255,255,255,0) );
cPlot.setBackgroundAlpha(0.0f);
cPlot.setDomainGridlinePaint(Color.white);
cPlot.setDomainGridlinesVisible(false);
cPlot.setRangeGridlinePaint(Color.white);
cPlot.setOutlineVisible(false);
// set the range axis to display integers only...
final NumberAxis rangeAxis = (NumberAxis) cPlot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// disable bar outlines...
BarRenderer renderer = (BarRenderer) cPlot.getRenderer();
renderer.setDrawBarOutline(true);
// set up gradient paints for series...
GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.blue,
0.0f, 0.0f, new Color(0, 0, 64)
);
renderer.setSeriesPaint(0, gp0);
CategoryAxis domainAxis = cPlot.getDomainAxis();
domainAxis.setCategoryLabelPositions(
CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)
);
// OPTIONAL CUSTOMISATION COMPLETED.
return chart;
}
也就是说,我们将不胜感激。
最佳答案
您可以使用 setTickLabelsVisible(false)
和 setTickMarksVisible(false)
隐藏轴上的文本。
关于java - JfreeChart 图中只有条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8850317/