Dynamic tool tip generator - Jfreechart

后端 未结 2 409
终归单人心
终归单人心 2021-01-15 05:14

I am generating a dynamic chart (XYLineChart) using jFreeChart and I have a field which is not included in the dataset. The field is generated dynamically. I want to include

2条回答
  •  清酒与你
    2021-01-15 05:37

    You don't have to care about data added dynamically to the dataset. Tooltips are created on the fly using the data from the dataset. The individual XYToolTipGenerator just needs to be assigned to the renderer instance.

    As an example, start with the TimeSeriesChartDemo1 class from JFreeChart, and add an individual XYToolTipGenerator as shown below.

    XYItemRenderer r = plot.getRenderer();
    …    
    // define your own tooltip generator   
    StandardXYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator()
    {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item)
        {
            return "Series " + series + " Item: " + item + " Value: "
                + dataset.getXValue(series, item) + ";"
                + dataset.getYValue(series, item);
        }
    };
    // and assign it to the renderer
    r.setBaseToolTipGenerator(tooltipGenerator);
    

提交回复
热议问题