In a DefaultIntervalCategoryDataset
, I want to display the interval range information inside the bar. I want to discard information encircled in the following figure, and just want to display the interval value.
Below is the code. How to display interval values only?
public class IntervalBarChartTest0 extends ApplicationFrame {
public IntervalBarChartTest0(String title) {
super(title);
JPanel chartPanel = createDemoPanel();
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}
private static DefaultIntervalCategoryDataset createDataset1() {
Number[] series1_Start = new Number[] {25,50};
Number[] series1_End = new Number[] {50,75};
Number[][] starts = new Number[][]{series1_Start};
Number[][] ends = new Number[][] {series1_End};
String[] categoryKeys = {"50th%ile", "90th%ile"};
String[] seriesKeys = {"Series1"};
DefaultIntervalCategoryDataset dataset= new DefaultIntervalCategoryDataset(seriesKeys,categoryKeys,starts, ends);
return dataset;
}
private static JFreeChart createChart(DefaultIntervalCategoryDataset dataset) {
CategoryAxis domainAxis = new CategoryAxis("Percentiles");
NumberAxis rangeAxis = new NumberAxis("ms1");
IntervalBarRenderer renderer = new IntervalBarRenderer();
rendererSettings(renderer);
CategoryPlot plot = new CategoryPlot(dataset, domainAxis, rangeAxis,renderer);
JFreeChart chart = new JFreeChart("Percentiles", plot);
ChartUtilities.applyCurrentTheme(chart);
return chart;
}
private static void rendererSettings(IntervalBarRenderer renderer){
renderer.setItemLabelFont(new Font("Verdana",Font.PLAIN,8));
renderer.setBaseItemLabelGenerator(new IntervalCategoryItemLabelGenerator());
renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE6, TextAnchor.BOTTOM_CENTER));
renderer.setItemMargin(0.1);
renderer.setBaseItemLabelsVisible(true);
}
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset1());
return new ChartPanel(chart);
}
public static void main(String[] args) {
JFrame demo = new IntervalBarChartTest0(
"Testing");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
This is a feature of the default IntervalCategoryItemLabelGenerator
. The DEFAULT_LABEL_FORMAT_STRING
specifies the following MesageFormat
values:
`"({0}, {1}) = {3} - {4}"`
The meanings are defined by createItemArray()
, seen here. Instead of the default, you probably want something like this:
renderer.setBaseItemLabelGenerator(
new IntervalCategoryItemLabelGenerator(
"{2}", NumberFormat.getNumberInstance()));