如何在JFreeChart中更改一个磅值并显示标签

时间:2018-05-17 02:44:51

标签: java swing jfreechart

如何在JFreeChart中更改一个磅值/颜色并显示标签?通过这个ChartMouseListener,我可以让用户选择女巫点,我想要设置特殊风格的点,如更大或改变颜色等。请帮我如何做到这一点。

       chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseMoved(ChartMouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void chartMouseClicked(ChartMouseEvent arg0) {
            // TODO Auto-generated method stub
            JFreeChart chart = arg0.getChart(); 


            if (chart == null) 
                return; 

            XYItemEntity ce = (XYItemEntity) arg0.getEntity(); 
            if (ce == null) 
                return; 
            IntervalXYDataset my = (IntervalXYDataset) ce.getDataset(); 

            int sindex = ce.getSeriesIndex(); 
            int iindex = ce.getItem(); 

            //i want make change the selectted point in here. how to do this
            System.out.println("x = " + my.getXValue(sindex, iindex)); 
            System.out.println("y = " + my.getYValue(sindex, iindex)); 
        }
    });

enter image description here

1 个答案:

答案 0 :(得分:1)

根据您选择的渲染器,应用合适的标签生成器并覆盖相关方法,以便在行和列与ChartMouseListener记录的相应系列和项目索引匹配时返回所需的形状和绘制属性。在XYLineAndShapeRenderer的特定情况下,您可以

  • 指定XYItemLabelGenerator,如图所示here

  • 覆盖getItemShape()方法,如图here所示,

  • 覆盖getItemFillPaint()方法,如图here所示,