Search code examples
javajfreechartlabel

XYdataset Jfreechart label plots with a third value


I am making a graph that shows me average according to a time. I have built an XYdataset (TimeSeries) where x-axis is time and y-axis is average. I get the average from this query:

select hour, avg(localizations) as avg, count(distinct tag) as cnt from hourly_tag_summaries where hour >= ? and tag in ("+ids+") group by hour;

This is how I created my dataset:

TimeSeries beacons_local = new TimeSeries("beacons-localizations");
String sql= "select hour, avg(localizations) as avg, count(distinct tag) as 
cnt from hourly_tag_summaries where hour >= ? and tag in ("+ids+") group by 
hour;";

    ResultSet rs1 = my_db.selectQuery(sql, Main.NOW - Main.DAYS);


    while (rs1.next()) {
        int avg = rs1.getInt("avg");
        long hour = rs1.getLong("hour");
        int cnt= rs1.getInt("cnt");
        beacons_local.add(new Millisecond(new Date(hour)),avg);

    }

I want to keep the cnt variable so when I mouse-over on the graph I can see the count for each plot. How do I do this?


Solution

  • For each TimeSeries in your TimeSeriesCollection, maintain a List<Integer> of counts. Reference the relevant count in your custom XYToolTipGenerator, as shown here and here. The exact formulation depends on your use case; XYZDataset, and the corresponding XYZToolTipGenerator, are examples that may serve as a guide.