score:0
a bit late, but hope it helps someone:
datasets: [
{
yAxisID: 'TOGGLE_yaxis1',
label: 'dataset 1',
fill: false,
backgroundColor: 'rgb(255, 99, 132)',
data: [72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72, 72]
},
{
yAxisID: 'yaxis2',
label: 'dataset 2',
fill: false,
backgroundColor: 'rgb(54, 162, 235)',
data: [70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70]
}
]
options:
{
responsive: true,
legend:{
display: true,
onClick: function(event, legendItem) {
var y_axis_id = MYCHART.data.datasets[legendItem.datasetIndex].yAxisID;
if(y_axis_id.startsWith('TOGGLE')){
//find by name yaxis
for(i=0;i<MYCHART.options.scales.yAxes.length;i++){
if(MYCHART.options.scales.yAxes[i].id==y_axis_id){
MYCHART.options.scales.yAxes[i].display = !MYCHART.options.scales.yAxes[i].display;
MYCHART.data.datasets[legendItem.datasetIndex].hidden = !MYCHART.data.datasets[legendItem.datasetIndex].hidden;
MYCHART.update();
}
}
}
},
scales: {
yAxes: [{
id: 'TOGGLE_yaxis1'
},{
id: 'yaxis2'
}]}
},
Source: stackoverflow.com
Related Query
- Completely hide the Y-axis on chartjs when data is hidden
- Chartjs 2.7.3: Set Y data at the correct X position axis
- Chartjs: Is it possible to hide the data labels on the axis but show up on the graph on hover?
- ChartJS - format datetime X axis when displaying data from MySql table
- How to hide Fields and Strike-through Legends when the data is empty or Zero in Pie/Polar/Doughnut Chart?
- Chartjs Bar Chart showing old data when hovering
- Chartjs hide data point labels
- Hide Y-axis labels when data is not displayed in Chart.js
- TypeError: Cannot read property 'defaults' of undefined when using the react wrapper of chartjs
- Hide gridlines in chartjs without the drawTicks
- How to change the cursor to a pointer when I hover over a bar in a ChartJS bar chart?
- Chartjs change the specific label color in x axis in callback function
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Why can I not see a data value when hovering over a point on the radar chart?
- Changing the Y axis unit in Chartjs
- React ChartJS 2 : Get data on clicking the chart
- Strikethough labels when data is hidden
- Maintain Y axis scale in graph with scroll in the X axis when the dataset grows bigger. Aspect-ratio problem
- why is the background black when with Chartjs export to a image
- How to make chartJs stacked bar always rounded when data is 0?
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- ChartJS align axis label to the top
- How can I load multiple Chartjs charts with different data on the same page?
- ChartJS shows date, but not time, when displaying labels in time axis
- How do I hide line outside the min/max (scale area) in chartjs 2.0?
- Chartjs does not show annotations when x axis is of type time
- ChartJS bar chart - trigger hover even when the cursor is outside of the bar
- Chart.JS: How can I only display data labels when the bar width is big enough for the text?
- How can I change the label name when you hover your data in Chart.js?
- How can I show a subset of data on pie pieces in Chart.JS while still displaying the superset when hovering?
More Query from same tag
- Change tooltip positioning in doughnut chart using Chart.js
- Vuejs prop does not get updated
- Chart.js Treemap Adding custom text to each rectangle
- Chart.js: evenly distribute ticks when using maxTicksLimit
- Collect json disordered, order it and show it in chart.js
- How to loop tooptip additional data in chart.js
- Chartjs bar min, max and avarage value
- Chartjs with streaming plugin: update y-range
- Show image instead a point in a ChartJS scatter plot
- Get X, Y onClick chart coordinates in ChartJS
- Chart js nested pie label colors in legend
- how to use chartjs-plugin-crosshair in Angular 6+?
- TypeError: CanvasRenderService is not a constructor
- ChartJS 2.7.3 stacked bar chart with overlap
- Chart.js: How can a line series (out of many) change line color and thickness upon mouse hover?
- chartjs and making an onClick action for a specific element?
- Loading json file to chartjs
- chart.js remove lower grid from mixed chart
- How to add commas when showTooltips is false in ChartJS
- chart looking strange on phone´s browser using chart.js
- Line ChartJs would not display - Date format issue
- How to resize chartjs in bootstrap columns for different browsers
- Chart js :Adding onclick event on slice of doughnut chart is not working in react-chartjs-2
- chart.js how to force min and max y axis values
- In ChartJS how do I change the color of a label in the legend?
- Chart.js updating-animations of radar-charts
- Chart.js (3.7) - Why do the tooltips not appear?
- Switch chart.js data with button click
- Stacked Mixed Horizontal Bar Chart in Charts.Js Axes Positioning
- ChartJS - Show values in the center of each bar