score:0
In the data structure doc (version 3.5.1 at the time of writing this), it is documented objects can be used as data
and parsing option is also available to pick the keys.
Example from the doc:
data: {
datasets: [{
data: [{id: 'Sales', nested: {value: 1500}}, {id: 'Purchases', nested: {value: 500}}]
}]
},
options: {
parsing: {
xAxisKey: 'id',
yAxisKey: 'nested.value'
}
}
score:2
I can confirm that answer @rinogo gave works on latests version. You can add custom properties to dataset and use 'em in tooltip or elsewhere afterwards.
First add data to dataset. On my case I only have one set, so I'm just pushing points.
chartData.datasets[0].data.push({
y: groupedBooking.distinctCount,
distinctUsers: distinctUsers
});
... and finally override callback with chartOptions:
options: {
tooltips: {
callbacks: {
label(tooltipItem, data) {
console.log(data);
return data.datasets[0].data[tooltipItem.index].distinctUsers;
}
}
}
}
If you would happen to have multiple datasets you get datasetIndex from tooltipItem as well... so to confirm, X can be omitted from datapoint and customer properties are preserved within object.
score:10
In short, I think your example should work. The key is to use y
for the y value in the chart, and to add your arbitrary property to the object, as well.
It looks like this is what you're doing, but you've reported it's not working... It works for me, though! ?
Longer answer
According to the docs for Line, data
can be a Number[]
:
data: [20, 10]
...but it can also be a Point[]
:
data: [{
x: 10,
y: 20
}, {
x: 15,
y: 10
}]
This was intended to be used for sparsely-populated data sets. Through experimentation, I've found you can omit the x
property and simply specify the y
property. The x
value will be inferred, as usual.
You can also add in any other arbitrary properties that can be accessed from your label callback. So, you might end up with something like this:
data: [{
y: 20,
myProperty: "Something"
}, {
y: 10,
myProperty: "Something Else"
}]
Source: stackoverflow.com
Related Query
- Chart.js: passing objects instead of int values as data
- How to stop displaying the data values from different data objects on Chart JS 2.x?
- line chart with {x, y} point data displays only 2 values
- Chart.js Timeseries chart - formatting and missing data values
- Chart JS: Ignoring x values and putting point data on first available labels
- How to show data values in top of bar chart and line chart in chart.js 3
- How to commaize the data values provided to a chart in Chart.JS?
- Chart js logarithmic line chart showing NaN values instead of null
- Charts js and laravel: Render chart after passing in json data
- Chart JS how to display an array of data objects as bar chart
- How to show the chartjs bar chart data values labels as text?
- Using number/text input field to set the data values in ChartJs stops the chart from being displayed
- Chartjs - Stacked bar chart data order causes invisible other values
- Chart.js How can I embed additional values to each data point in radar chart
- chart js: when all the values passed to data are zeros, nothing is showing
- How can I get my Chart.JS bar chart to stack two data values together on each bar, and print a calculated value on each bar?
- How to make a chart with a string values instead of data?
- Show Labels on Pie pieces instead of Data values Chart.js
- How do I destroy/update Chart Data in this chart.js code example?
- Chart.js chart by passing data through the controller MVC
- getting additional value fields from data source for dx.chartjs doughnut chart
- Passing data to a chart javascript object and array
- Chart Js , loading data on selection but bar graph displaying old values as well on hovering
- null values for instead of date causes the browser to crash while using chart js
- How to pass dynamic values as objects inside data in line chart?
- Chart JS is using 1,2,3 as y values for my points for the second dataset instead of their passed in labels
- How to set data values as labels in Chart.js with a Radar Chart
- Dynamically update values of a chartjs chart
- How to display data values on Chart.js
- Chartjs Bar Chart showing old data when hovering
More Query from same tag
- Chartjs show seconds on the x axis and volume on the y
- How do I correctly include Moment.js and Chart.js with RequireJS when I want to create charts with time scales?
- React-chartjs-2 gradient fill error on canvas context
- Chart.js - How to offset bars from ZeroLine
- Conditional Series Failing - Chart.js
- Chart.js how to display % on tooltip
- chartJS Horizontal Bar - Hide Stacked Bars But Still Show In Tooltip
- chartjs-vue charts are empty
- how to show only each 15th x-labels in line chart chart.js in angular 6?
- Chart.js doughnut chart tooltip size?
- How to send an array of object as a prop?
- Dotted Line in ChartJS
- Chart.js Increase font size for higher resolution (i.e. monitor-agnostic chart configuration )
- Create ticks at certain time positions on a chartjs cartesian time axis
- Using Chart.js - The X axis labels are not all showing
- ChatJS 2.8 chaning x-Axis font style and color
- Show Count on top of the bar graph - ChartJS
- ChartJS keeps resizing canvas to the default size
- Is it possible to make 3D pie chart using chart.js?
- Zoom and Pan in react-chartjs-2
- angular Chart data-pushing from another javascript
- How to assign variables to data passed through a WEB API in Angular?
- Integrate chartjs-chart-treemap with react-chartjs-2
- Chart.Js radar - hide label numbers
- MYSQL Query and Chart.js and PHP
- i can't create a line vertically with react annotation
- Avoid data resetting when toggling series
- Line Chart with null values: How to keep Lines connected?
- Uncaught TypeError: Cannot set properties of undefined (setting 'render')
- ChartJS automatically scaled chart has undefined min and max