问题描述
我正在使用JFreeChart的SpiderWebPlot来生成图表。但我想拥有的是具有价值观的工具提示。我发现我应该将StandardCategoryTooltipGenerator设置为情节,但这似乎不是重点。这是我的示例代码:
I'm using SpiderWebPlot from JFreeChart in order to generate a chart. But what I want to have, is tooltips with values. I've found that I should set StandardCategoryTooltipGenerator to the plot, but that doesn't seem to be the point. Here is my sample code:
private JFreeChart prepareChart() {
Random rnd = new java.util.Random();
DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
String rowKey = "Osobnik";
dataSet.addValue(rnd.nextInt(20), rowKey, "BLUFF");
dataSet.addValue(rnd.nextInt(20), rowKey, "CALL");
dataSet.addValue(rnd.nextInt(20), rowKey, "CHECK");
dataSet.addValue(rnd.nextInt(20), rowKey, "FOLD");
dataSet.addValue(rnd.nextInt(20), rowKey, "RAISE");
SpiderWebPlot plot = new SpiderWebPlot(dataSet);
// CategoryToolTipGenerator generator = new
// StandardCategoryToolTipGenerator();
// generator.generateToolTip(dataSet, 0, 1);
plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
plot.setStartAngle(54D);
plot.setInteriorGap(0.40000000000000002D);
plot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
JFreeChart chart = new JFreeChart(plot);
return chart;
}
以下是我要完成的示例。
Here is the example of what I'm trying to accomplish.
推荐答案
ChartPanel
向图表注册以接收图表任何组件变更的通知。我怀疑你忽略了构建 ChartPanel
;给定静态
版本的 prepareChart()
,以下 main()
适合我。另请参见。
ChartPanel
"registers with the chart to receive notification of changes to any component of the chart." I suspect you have neglected to construct a ChartPanel
; given a static
version of prepareChart()
, the following main()
works for me. See also Initial Threads.
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame("Spider Web Plot");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new ChartPanel(prepareChart()));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}
附录:根据发布的截图,您需要自定义 CategoryItemLabelGenerator
,可以使用 setLabelGenerator()
进行设置。它将从 drawLabel()
调用,显示为。例如,
Addendum: Based on the posted screenshots, you'll need a custom CategoryItemLabelGenerator
, which can be set using setLabelGenerator()
. It will be called from drawLabel()
, shown here. For example,
plot.setLabelGenerator(new StandardCategoryItemLabelGenerator() {
@Override
public String generateColumnLabel(CategoryDataset dataset, int col) {
return dataset.getColumnKey(col) + " " + dataset.getValue(0, col);
}
});
这篇关于使用SpiderWebPlot时带有值的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!