Heat map with numbers in boxes

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
a579756
Posts: 3
Joined: Thu Oct 29, 2015 9:05 pm
antibot: No, of course not.

Heat map with numbers in boxes

Post by a579756 » Fri Oct 30, 2015 1:36 pm

I am looking make something like this with numbers in boxes. I did look into JFree APIs and couldn't find one which can get me similar.
1. Display z values in the rectangle x,y boxes along with the colors
2. Define colors low and upper bonds for each row

http://www.highcharts.com/demo/heatmap

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Heat map with numbers in boxes

Post by david.gilbert » Sat Oct 31, 2015 8:07 am

There isn't a chart like that supported by JFreeChart yet. It would be a good one to add though (unfortunately I'm not likely to find the time to do it in the near future though).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Heat map with numbers in boxes

Post by paradoxoff » Mon Nov 02, 2015 11:29 am

You can probabaly get quiet close by using the following approach:
1. Stuff your data in a matrix-like dataset. Example here.
2. Replace the two NumberAxes with SymbolAxes that use Strings for the TickLabels instead of Numbers. Example here.
3. Use an XYItemLabelGenerator to show the Numbers as such in the chart. Since a special XYItemLabelGenerator for XYZDatasets is not available, you could use an StandardXYZToolTipGenerator and use the String returned from generateToolTip(XYZDataset dataset, int series, int item) as return value in the generateLabel(XYDataset dataset, int series, int item) method of your new XYItemLabelGenerator. Using an ToolTipGenerator as "backend" for an ItemLabelGenerator is described here.
4. An XYBlockRenderer doesn´t appear to drwa the item labels. You can either add the missing lines to the XYBlockRenderer source, or write a new renderer that extends XYBlockRenderer and overwrites the drawItem method. The missing lines to draw the item labels should be something like

Code: Select all

if (isItemLabelVisible(series, item)) {
    drawItemLabel(g2, orientation, dataset, series, item, xx, yy,
    (y1 < 0.0));
}
where xx and yy are the coordintaes of the data point in Java2D space, and y1 is the y value of the data pointn in data space.

elmo22
Posts: 3
Joined: Fri Jan 23, 2015 10:52 pm
antibot: No, of course not.

Re: Heat map with numbers in boxes

Post by elmo22 » Wed Nov 11, 2015 9:24 pm

1. Display z values in the rectangle x,y boxes along with the colors
2. Define colors low and upper bonds for each row
It looks like createHeatMapImage() in org.jfree.data.general.HeatMapUtilities could easily be modified to do both of these tasks.

a579756
Posts: 3
Joined: Thu Oct 29, 2015 9:05 pm
antibot: No, of course not.

Re: Heat map with numbers in boxes

Post by a579756 » Fri Nov 13, 2015 10:36 pm

@ paradoxoff ,
Thanks for your detailed inputs and the approach works fine. Could you please suggest for the 2nd requirement? It is not a standard heat map as the low and high colors are decided based on low and high values for each row.
Lets say,
row 1 has values from 0 to 10, and min value 0->Red to max 10->Green
row 2 has values from 5 to 18, and min value 5->Red to max 18->Green
...

Any suggestions will be great help.

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Heat map with numbers in boxes

Post by paradoxoff » Mon Nov 16, 2015 5:50 pm

If you really need to implement row-specific min/max values, then use 1 dataset per row. All x values for a specific row will have the same x value. Then, use individual XYBlockRenderer and PaintScales for your rows.

a579756
Posts: 3
Joined: Thu Oct 29, 2015 9:05 pm
antibot: No, of course not.

Re: Heat map with numbers in boxes

Post by a579756 » Tue Nov 17, 2015 10:35 pm

Your inputs are very helpful and all is well. Thank you.

evamgarciap
Posts: 1
Joined: Wed Mar 15, 2017 12:26 pm
antibot: No, of course not.

Re: Heat map with numbers in boxes

Post by evamgarciap » Wed Mar 15, 2017 12:29 pm

Hi, I need the same heatmap that you have explained. Could you tell me how did you create it at last? Could anybody give me an example to create one dataset per row?

Locked