score:3
Accepted answer
try like this:
var data = [{
//x: 'item 1',
y: 2,
id: 'test-10'
},
{
//x: 'item 2',
y: 4,
id: 'test-20'
},
{
//x: 'item 3',
y: 5,
id: 'test-30'
},
{
//x: 'item 4',
y: 6,
id: 'test-40'
},
{
//x: 'item 5',
y: 8,
id: 'test-50'
},
{
//x: 'item 6',
y: 12,
id: 'test-60'
}];
var ctx = document.getelementbyid('linechart').getcontext('2d');
var mychart = new chart(ctx, {
type: 'line',
data: {
labels: ['item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6'],
datasets: [{
label: 'dataset 1',
data: data,
bordercolor: "#3e95cd",
fill: false
}]
},
options: {
tooltips: {
enabled: true,
mode: 'single',
callbacks: {
label: function (tooltipitems, data) {
var multistringtext = ['value: ' + tooltipitems.ylabel];
multistringtext.push('id: ' + data['datasets'][tooltipitems.datasetindex]['data'][tooltipitems.index].id);
return multistringtext;
}
}
},
}
});
var ctx = document.getelementbyid('radarchart').getcontext('2d');
var mychart = new chart(ctx, {
type: 'radar',
data: {
labels: ['item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6'],
datasets: [{
label: 'dataset 1',
data: data.map(item => item.y),
bordercolor: "#3e95cd",
fill: false
}]
},
options: {
tooltips: {
enabled: true,
mode: 'single',
callbacks: {
label: function (tooltipitems) {
return 'value: ' + data[tooltipitems.index].y + ', id: ' + data[tooltipitems.index].id;
}
}
},
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.7.0/chart.bundle.min.js"></script>
<div style="width: 400px; display: inline-block">
<canvas id="linechart" width="100" height="70"></canvas>
</div>
<div style="width: 300px; display: inline-block">
<canvas id="radarchart" width="50" height="50"></canvas>
</div>
i think the key point is to be aware of how each chart type wants the data to be structured. in the above, a map()
function is used to present the y
values as an array for the radar chart. then, to get the correct tooltip information, the tooltip index is used to retreive that element's values from the full data
array. the label callback seems to return a string rather than an array.
Source: stackoverflow.com
Related Query
- Chart.js How can I embed additional values to each data point in radar chart
- 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 can I create custom tooltips for each data point in a graph?
- How to set data values as labels in Chart.js with a Radar Chart
- line chart with {x, y} point data displays only 2 values
- Why can I not see a data value when hovering over a point on the radar chart?
- How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- 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
- Show point values in Radar Chart using chart.js
- How to commaize the data values provided to a chart in Chart.JS?
- How can I achieve displaying data points on chart but Dotted? Chart.js V3.7.0
- How to disable Chart.js Radar Chart point labels
- How can I show JSON data in Chart.js with Javascript if static values are working but dynamic from mySQL are not?
- How can I have different values for the chart and the tooltip in chart.js?
- How can I re-distribute values within a charts.js pie chart when a legend item is turned off/on?
- How to show the chartjs bar chart data values labels as text?
- Chartjs Radar chart - How to dynamically highlight one of the gridlines at a specific point
- How can i display my data in a chart using chart js
- How can i loop some specific key in each index json data and put it in dataset: data ? (chart.js)
- How to stop displaying the data values from different data objects on Chart JS 2.x?
- how to write labels along with data on top and bottom of each stack in bar chart
- Can chart.js display text associated with each point on a line chart that is permanently visible?
- How can I show "No Data" message in Pie Chart when there is no data using VueJS?
- How do I destroy/update Chart Data in this chart.js code example?
- getting additional value fields from data source for dx.chartjs doughnut chart
- How can I add new data points to an existing chart with chart.js?
- How can I assign dynamic data from service via subscribe to doughnut chart in angular?
- how can I make selected data is highlighted on chart js?
- turn off point values in radar chart
More Query from same tag
- Animating outerRadius and innerRadius
- Combining multiple legend elements in chart.js
- Horizontal gradient for every single bar in group chart js
- Limit numbers of labels on Chart.js in "smaller display only"
- Chart.js how to use scriptable options
- ChartJS custom bar chart
- Chart Js + Angular
- data representation using charts
- how can i use inline plugin inner title for chart js?
- Chart.js: Chart not resizing in iframe
- Why chartJs throws length of undefined although everything seems correct
- Chartjs: How to offset ticks on radarchart?
- ChartJS How to set color to just one bar
- Chart.js Doughnut with rounded edges and text centered
- Implementing Data Decimation in vue chartjs
- ChartJS: Horizontal Bar with multiple datasets not showing Bars
- ChartJs Doughnut parsing datasets
- Display values outside of pie chart in chartjs
- Chart js shows old data on mouse hover
- ChartJS - Different color per data point
- How to fix the distance between horizontal points (x-axis) in chartJS
- ChartJS hover/tooltips: selecting the correct points in the datasets based on x-value
- How to get Data from API to display chart using chartjs in Vuejs
- UndescoreJS - Convert Object Properties Into Arrays
- Possible to hide Chart.js grid lines that extend beyond chart?
- Chart.js shaded regions
- To remove error message when user clicked on legend label
- UnCaught IndexSizeError: ChartJS
- ChartJS Datalabels plugin and negative numbers
- How to push an array into an Object which is inside of another array?