JHeatChart is a simple Java API for generating heat map charts. Very few existing charting APIs seem to contain the facility to create heat maps. So, I wrote JHeatChart as a very simple library for constructing them. It is not intended to be a full featured charting API; it cannot create line charts, bar charts or pie charts. But, it is good at its one job – heat map charting. JHeatChart is released under an LGPL license and is Free to use and modify. The charts generated can be saved directly to an image file (png, jpg, gif supported) or returned as a Java Image object for further processing or use in a GUI.

Downloads, examples and documentation are available from the JHeatChart website.

Example heat maps:

Example heat map with transparent background, and no title

Example heat chart

Example heat map with title and axis labels

An example chart created with JHeatChart

Example heat map with small cell size, title and axis labels

Some example code

13 comments on “JHeatChart
  1. Allie says:

    I was trying out v0.5, and your sample code doesn’t appear to work. Indeed, it seems that any non-square 2d array doesn’t work. Is this the intended functionality (and the sample code is wrong), is the program incorrect, or am I missing something? Thanks in advance!

    • Tom Castle says:

      That is certainly not intended functionality. The problem is within the library itself. I’m not in a position to fix this right now, but as soon as I’m back in front of my development machine tomorrow I’ll release a fix. Thank you for raising this.

      • Tom Castle says:

        This problem has now been fixed as of release 0.51. The example code above should now execute correctly and generate an image file of a heat map chart.

  2. Zong Jie says:

    Very nice api, thank you very much for your work. I think the API is eary to use and I use it draw some beautiful figures.
    I have a small suggestion, could you please add a method so that it can draw a tree near the heatmap?
    just like a clustering heatmap. for example: http://breast-cancer-research.com/content/supplementary/bcr746-s2.bmp

    • Tom Castle says:

      You’re welcome, thank you for the feedback. Thanks also for the suggestion, it is a good idea. I’ll look into the possibility of implementing something for the next version.

  3. Zong Jie says:

    Thank you for your replay. Previous suggestion I proposed may be difficulty. I have another suggestion which may easy to achieve and may have more significance. When we draw a heatmap, sometimes the data were have 2 different directions, for example : -3, -2, -1, 0, 1, 2, 3. At that time I wish using green to display Negative number and red to display positive number. and using white(or black or any other color) to display zero. That means there maybe 3 color and 2 different Color Gradient in one heatmap,

    Using your API, still I think an solution: first, using only positive values to generate a heatmap with white and red. Second using only negative values to generate a heatmap with white and green. Finally, merging the two images and get the 2 different Color Gradient in one heatmap,

    • Tom Castle says:

      That is an interesting problem. I already intend to improve the way that colour gradients are handled in future versions, so I’ll have a think about whether there is an elegant way that this can be incorporated. Again, thank you for the ideas, they will help to improve the library.

  4. isabel says:

    Hey this is awesome. Thank you SO much for posting this, it made things so much easier. And your functions are so easy to use.

    I have one question for you: Heatmaps I generated using your lib are like the red and blue example above, meaning the y axis scale does not start from 0 as the bottom value. How do I make it so that 0 is the bottom value of y axis? Maybe I overlooked the code and am not seeing a function in your lib that allows me to do that. I really appreciate your help. Thank you in advance!

    • Tom Castle says:

      You’re welcome! I’m glad you’re finding it useful.

      You can reverse the y axis in two ways. The easiest of which is to call setYValues(double, double) with a negative interval between each value. In the example above, this means adding the following line:

      map.setYValues(data.length-1, -1.0);

      The other approach is to use setYValues(Object[]) and pass an array of the values to plot along the y axis which you generate yourself.

      • isabel says:

        Hi Thank you for your reply!

        I am using setYValues(Object[]) method, where the argument is an array of doubles starting from 0.0 to 0.9. I am still getting the same type of heatmap. No change. :/

        I tried using setYValue(double, double), but it only works partially. Meaning that numbers are all messed up and are over written over one another. Take a look: http://dl.dropbox.com/u/9008927/aBTLA_5F5_mutant_HC_DTT_IAA_GluC_37C_ON_top10_msmsIT_042308_2_b_vs_y_charge3.png

        • Tom Castle says:

          Try reversing the array that is passed to setYValues(Object[]) so it goes from 0.9 to 0.0. The values are assigned from the top down (which is probably not a great idea so that will likely change in the next version!).

          The problem you’re having with setYValues(double, double) seems to be a rounding issue. I’ll see if that can be handled more cleverly in a future release.

  5. isabel says:

    Reversing the array worked. Thank you SO much for your responses and a great library for heatmaps, this has saved me so much of my time, because there are not that great libraries available specifically for heatmaps. This just does the job! Thank you again!!! :)

  6. Jacopofar says:

    Hello, I made a modified version of JHeatChart, that use a different color depending on the cell value, passing from black to blue, green, yellow and red as the value increase. You can see an example here, the code is on a github repository
    I needed it for my use case, I hope someone will find it useful.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">