Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Chart Type] Heatmap #4627

Closed
andreladocruz opened this issue Aug 8, 2017 · 27 comments
Closed

[New Chart Type] Heatmap #4627

andreladocruz opened this issue Aug 8, 2017 · 27 comments

Comments

@andreladocruz
Copy link

Just to ask you guys to add the type heatmap to the graphs.
The bubble one is not the same thing.
Thanks

@panzarino
Copy link
Contributor

There is currently a Chart.js heatmap plugin that is available: https://github.com/tmroyal/Chart.HeatMap

@etimberg
Copy link
Member

etimberg commented Aug 8, 2017

I think this would better live in an external repository so that the core doesn't get larger

@panzarino
Copy link
Contributor

Closing as this has been implemented in an external library and should not be included in the core.

@andreladocruz
Copy link
Author

@panzarino, the plugin https://github.com/tmroyal/Chart.HeatMap does not work with the current version of Chart.js

@panzarino
Copy link
Contributor

@andreladocruz Maybe try contacting @tmroyal to see if he is willing to update it. Someone else could also make a new plugin, but at this time there are no plans for adding this chart type to the core library.

@andreladocruz
Copy link
Author

Well, lets see if @tmroyal has to say about this. I'll inspect his code and see if I can upgrade it. :)

@csecker
Copy link

csecker commented Mar 3, 2018

Did you manage to update the Chart.HeatMap plugin to work with the current version of Chart.js. Or anyone know about an alternative plugin/heatmap?

@gbordoni
Copy link

The Chart.Heatmap plugin it's outdated, it does not work with the current version of Chart.js

@prabhpahul
Copy link

Is there any other library which support the HeatMap charts or is there any update upon @tmroyal library.?

@FinnLawrence
Copy link

I just wanted to post for anyone following this issue, since finding out that Chart.HeatMap doesn't work anymore, I've managed to quite successfully create a heat map using a Stacked Bar Chart and being clever with the colors and tooltips:

Heat Map Chart

How to

Grid Structure

For each of the graph's 7 datasets (in my case, one for each day of the week) I pass in a scaffold array as the data component:

var scaffold = new Array(24).fill(1);

This fills the stacked bars so that all the data points are the same size - and form a grid. Then you can color them and edit the tooltips to make it appear like a heat map.

Coloring

Example function includes a scale variable, above which values are at full opacity:

generateDatasetColors: function(valuesArray, scale) {
  var colors = [];
  var rgb = 0, 175, 221; // You should probably define this elsewhere

  for (var i in valuesArray) {
    var value = valuesArray[i];
    var opacity = value / scale;
    if (opacity > 1) {opacity = 1};

    colors.push("rgba(" + rgb + ", " + opacity + ")");
  }

  return colors;
}

Then you can just generate an array of colors for each dataset using this function and pass it in as the backgroundColor.

Tooltips

Here is what I am passing to the Chart's options object for the tooltips:

tooltips: {
  callbacks: {
    title: function(tooltipItems, data) {
      return data.datasets[tooltipItems[0].datasetIndex].label + ", " + tooltipItems[0].xLabel;
    },
    label: function(tooltipItem, data) {
      var weekDayIndex = 7 - tooltipItem.datasetIndex;
      if (weekDayIndex > 6) { weekDayIndex = 0 }
      return weekByHour[weekDayIndex][tooltipItem.index] + "%";
    }
  }
}

Where weekByHour is my 2d array of values.

This basically gets and concatenates the values for the dataset names and the axis labels for the title. The label function gets the indices from the datasets to access the 2d array of values correctly and display the value in the body of the tooltip.


Hopefully, that helps someone! Good luck 👍

@Hedva
Copy link

Hedva commented Jun 28, 2018

Clever. Can you create a fiddle of this example?

@nukec
Copy link

nukec commented Jul 31, 2018

this library should be simple for angular users(tested in ang5):
https://ej2.syncfusion.com/angular/documentation/heatmap/getting-started.html

@manhar-developer
Copy link

Hi @FinnLawrence ,
Could you please share snippet/fiddle for this example

@jchao12
Copy link

jchao12 commented Feb 28, 2019

@FinnLawrence
Thanks a ton for the example, was able to get the heatmap up by following it! Tremendous!

@cljk
Copy link

cljk commented Sep 3, 2019

I thought about the same - I need a kind of headmap... or grouped scatter plot.

I thought about using the Bubble chart. Perhaps I´ll find an easy way to replace the circles with squares...

@benmccann
Copy link
Contributor

You might be interested in these:
https://github.com/kurkle/chartjs-chart-matrix
https://github.com/kurkle/chartjs-chart-treemap

@cljk
Copy link

cljk commented Sep 4, 2019

YES

Matrix seems to be exactly the one.
Thanks.

@tmroyal
Copy link

tmroyal commented Oct 9, 2019

@tmroyal here, the author of the chart.js plugin available at https://github.com/tmroyal/Chart.HeatMap/. As is probably apparent, I've abandoned the plugin, and it probably should not be used. @benmccann above has some good suggestions that I would recommend adopting if you need this kind of chart type for chart.js.

@rmpt
Copy link

rmpt commented Jul 1, 2020

https://github.com/kurkle/chartjs-chart-matrix

This one is really cool, but doesn't accept x and y as strings, only numbers. That's a bummer

@mbonaci
Copy link

mbonaci commented Jul 4, 2020

https://github.com/kurkle/chartjs-chart-matrix

This one is really cool, but doesn't accept x and y as strings, only numbers. That's a bummer

What do you mean? Aren't x and y square coordinates?

@rmpt
Copy link

rmpt commented Jul 5, 2020 via email

@0xDaksh
Copy link

0xDaksh commented Jul 31, 2020

https://github.com/kurkle/chartjs-chart-matrix

This one is really cool, but doesn't accept x and y as strings, only numbers. That's a bummer

What do you mean? Aren't x and y square coordinates?

Yeah but what about categories?

@kurkle
Copy link
Member

kurkle commented Jul 31, 2020

https://github.com/kurkle/chartjs-chart-matrix

This one is really cool, but doesn't accept x and y as strings, only numbers. That's a bummer

It does, you need to use category scales for those.
Example: https://codepen.io/kurkle/pen/qBbeOZN

@0xDaksh
Copy link

0xDaksh commented Jul 31, 2020

Thanks @kurkle, although i already made the heatmap with plotly but still this looks good!

@pfeatherstone
Copy link

Is chartjs-chart-matrix the recommended chart type to plot spectrograms?

@bondgeek
Copy link

bondgeek commented Apr 21, 2023

How to create histogram / heat map chart like the snapshot in ng2-charts valor-software/ng2-charts#1022

The examples below seem to blow the argument that adding heatmaps would make the library too large out of the water.

@julia-okuniewska
Copy link

julia-okuniewska commented Sep 16, 2023

https://github.com/kurkle/chartjs-chart-matrix

This one is really cool, but doesn't accept x and y as strings, only numbers. That's a bummer

It does, you need to use category scales for those. Example: https://codepen.io/kurkle/pen/qBbeOZN

Update for anyone using this awesome example:
if you want to override callback for tooltip's title and label, you need to rename key tooltips into tooltip and move it inside plugins

https://www.chartjs.org/docs/latest/configuration/tooltip.html#label-callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests