score:3
react-chartjs currently depends on Chart.js v1.1.1 - which does not allow the multiple lines in tooltip.
- Tweaking the Chart.js file
(this method is not recommended, its only a hack)If you 'have' to use react-chartjs, you can do the following. You can send a custom tooltip template as an option (they use John Resig's micro templating: see it here)
options = {
tooltipTemplate: "<%=label%>:<%= value %><%\n%><%=value1string%>:<%= value1%><%\n%><%=value2string%>:<%= value2 %>",
}
But wait, for this method, there are many catches (:P and you follow them all to get it working).
The data value1, value1string, value2, value2string have to be global variables for the function in the file Chart.js to access them.
If you look at the micro templating engine in the above mentioned blog, you can see that '\n' character is replaced by a " " (space). So the above tooltip template will give all the data in one line. To get the intended behaviour, you need to modify the code in the source file from
(in Chart.js file)
.replace(/[\r\t\n]/g, ” “)
to
.replace(/[\r\t]/g, ” “)
- Other third-party libraries
There are many other third-party libraries that do what is required.
Using react-chartjs-2. This is a wrapper on Chart.js v2.x. You can use the callbacks in option provided by Chart.js to achieve it. See this example for usage.
var options={
tooltips: {
mode: 'label',
callbacks: {
afterLabel: function() {
return 'whatever you want to display';
},
},
},
}
Using fusioncharts. The library is actually pretty neat and give a very good control over the elements in a plot. You can easily configure the tooltip to act as you want. The only downside of this library is, it's free only for person use.
Using react-d3-tooltip. This library also gives a good amount of control over the elements, go through the docs. You can customize the tooltip as you want.
Hope it helps!
Source: stackoverflow.com
Related Query
- Allow display of multiple data attributes in tooltip of Chart.js
- Chart JS: Donut/Doughnut Chart: Tooltip to be shown always for all the data. All tooltip is not shown when multiple data are with 0 data
- JavaScript Chart.js - Custom data formatting to display on tooltip
- Chartjs v2 - format tooltip for multiple data sets (bar and line)
- chart js tooltip how to control the data that show
- Chart JS show multiple data points for the same label
- Add all data in the tooltip of Chart JS
- How to display data labels outside in pie chart with lines in ionic
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- ChartJs line chart - display permanent icon above some data points with text on hover
- How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- Chart JS display Data Value on the top of the Bar
- Chartjs - Insert additional data into chart tooltip
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Beginner using chart.js: having trouble display state full of data into a column chart using variables
- ChartJS v2 - Keep tooltip open when user click on a point of a multiple lines chart
- react-chartjs-2 line chart with time on X-axes with multiple data sets plotted wrong
- how to display chart data as html table chartjs
- Display data labels on a pie chart in angular-chart.js
- How to display chart using Chartjs with JSON data in Laravel
- How do I get a chart.js chart to display data in a Node/React web application?
- how to display multiple sum with chart js and laravel?
- How do I display chart on my HTML page based on JSON data sent by Node JS
- Chart JS how to display an array of data objects as bar chart
- How to get Data from API to display chart using chartjs in Vuejs
- How to show tooltip value of all data falling on the same axis in chart js?
- Display legend of grouped data (different colors) in chart
- ng2-Chart: can we show the tooltip data of pie chart on load?
- The chart doesn't display the data from my call to the API with Axios
- Display chart data based on API call
More Query from same tag
- Is there any way to change the font size of labels in bar chart in Chart.js v3?
- chart.js v2 - how to 'fill' the graph when using time scale
- Adding caret/arrow to a Chart.js custom html tooltip
- increasing php variable in javascript loop
- Change Vertical Line and Color bar chart in bar chart.js
- Multiple line labels for chart js
- Chart.js: chart not displayed from modules despite no errors - JS
- Making my website interactive with the size of the screen/browser
- Want to show small part of js Bar Chart when value is zero
- Chartjs - make line start at ... but maintain x-axis data
- chart.js set one bar as different colour?
- Cant pass variable for some reason? PHP
- ng2-charts access chartjs object to apply chartjs functions
- Styling background (fill) with ChartJs and React
- ChartJS changing graphs based upon Drop Down selection
- lazy loaded modules share same dependencies?
- Chart.js Using A JavaScript Object
- Angular ChartJS 2.9.4 issue updating chart
- Do I need a new dataset each time that I filter by a new date range in Charts.js?
- Chart.js Example Isn't working
- How can I add some text in the middle of a half doughnut chart in Chart.JS?
- How do I display a chart with chart.js?
- Chartjs in format Line is full points
- Timeline on Y axis, with chart.js
- Select missing dates from a table in MySQL
- Mixed chart barchart won't show
- chart.js-plugin-annotations multiple horizontal lines in one chart
- How to use chart.js in Angular2?
- Provide Chart.js with data via AJAX JSON not working?
- Chart.JS format date in label