2017-02-05 72 views
2

DefaultIntervalCategoryDataset中,我想在條內顯示間隔範圍信息。我想丟棄下圖中環繞的信息,只是想顯示間隔值。IntervalBarRenderer:在條內顯示特定信息

image

下面是代碼。如何僅顯示間隔值?

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); 
    } 

} 

回答