React-chartjs-2: Question: multiple data in tooltip

Created on 12 Aug 2016  路  7Comments  路  Source: reactchartjs/react-chartjs-2

Hi,
It is awesome that you guys have a react wrapper for chartjs2. Really appreciate it. :)

I am trying to use the tooltip callbacks in chartjs to get multiple lines (data from external source) in the tooltip. But I am not able to use it in this wrapper. Could you help me out?

Any help is appreciated. Thanks in advance.

Most helpful comment

@maxfarseer in my case, I wanted to show data1, data2, data3 below the "data" (same index) in the tooltip (all the four have same number of elements). So you can modify the graph_data as below

graph_data: {
  labels: [],
  datasets: [{
      label: '',
      data: [],
      data1: [],
      data2: [],
      data3: [],
  }]
}

under tooltips config, you can use callbacks

tooltips: {
    mode: 'label',
    callbacks: {

        title: function(tooltipItem, data) {
            return data.labels[tooltipItem[0].index];
        },

        beforeLabel: function(tooltipItem, data) {
            return 'Data1: ' + data.datasets[tooltipItem.datasetIndex].data1[tooltipItem.index];
        },

        label: function(tooltipItem, data) {
            return 'Data2: ' + data.datasets[tooltipItem.datasetIndex].data2[tooltipItem.index];
        },
    },
}

Hope this helps.

All 7 comments

I was able to figure it out. Thanks anyway :)

@akashrajkn can you show example? Thx!

@maxfarseer in my case, I wanted to show data1, data2, data3 below the "data" (same index) in the tooltip (all the four have same number of elements). So you can modify the graph_data as below

graph_data: {
  labels: [],
  datasets: [{
      label: '',
      data: [],
      data1: [],
      data2: [],
      data3: [],
  }]
}

under tooltips config, you can use callbacks

tooltips: {
    mode: 'label',
    callbacks: {

        title: function(tooltipItem, data) {
            return data.labels[tooltipItem[0].index];
        },

        beforeLabel: function(tooltipItem, data) {
            return 'Data1: ' + data.datasets[tooltipItem.datasetIndex].data1[tooltipItem.index];
        },

        label: function(tooltipItem, data) {
            return 'Data2: ' + data.datasets[tooltipItem.datasetIndex].data2[tooltipItem.index];
        },
    },
}

Hope this helps.

Your amazing!.

could you please help me out while using Angular I need to pass the external array of data to populate at tooltip. If I am using the above it is not reflecting inside the "options" keyword in Chart js

@maxfarseer in my case, I wanted to show data1, data2, data3 below the "data" (same index) in the tooltip (all the four have same number of elements). So you can modify the graph_data as below

graph_data: {
  labels: [],
  datasets: [{
      label: '',
      data: [],
      data1: [],
      data2: [],
      data3: [],
  }]
}

under tooltips config, you can use callbacks

tooltips: {
    mode: 'label',
    callbacks: {

        title: function(tooltipItem, data) {
            return data.labels[tooltipItem[0].index];
        },

        beforeLabel: function(tooltipItem, data) {
            return 'Data1: ' + data.datasets[tooltipItem.datasetIndex].data1[tooltipItem.index];
        },

        label: function(tooltipItem, data) {
            return 'Data2: ' + data.datasets[tooltipItem.datasetIndex].data2[tooltipItem.index];
        },
    },
}

Hope this helps.

It is not working it out is Angular 7 can you please help me out

@perumalprabhu maybe you should try angular based chartjs wrappers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RamonBeast picture RamonBeast  路  4Comments

Pringels picture Pringels  路  4Comments

cbroberg picture cbroberg  路  5Comments

DavidSongzw picture DavidSongzw  路  5Comments

alphakennyn picture alphakennyn  路  3Comments