Reputation: 931
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.
Upvotes: 4
Views: 1453
Reputation: 205875
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);
}
});
}
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);
}
});
Upvotes: 3