Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
38112 Lượt xem

I am using  Chart JS in my custom module. And I am using one canvas to display Multiple Charts. But when I move the mouse through the division and canvas it hover itself without clicking or selecting any button. I need to chage it when i select an drop down option. But its doesnt change.

I used empty() and remove() functions but its not worked well.

Can Anyone help me to resolve this issue?

My JS code is given below


var ctx = document.getElementById("canvas").getContext('2d');
var labels = [MONDAY,TUESDAY,WEDNESDAY]; 

var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [
{
label: 'Attendance', // Name the series
data: [25, 28, 24], // Specify the data values array
backgroundColor: '#66aecf',
borderColor: '#66aecf',

borderWidth: 1, // Specify bar border width
type: 'bar', // Set this data to a line chart
fill: false
}
}]
},
options: {
responsive: true,
maintainAspectRatio: false, });
 })
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Please re-write var myChart = new Chart(ctx, {  into the following code 

if(window.myCharts != undefined)
window.myCharts.destroy();
window.myCharts = new Chart(ctx, {

In current code the hover will not work because in your code multiple charts work on the same canvas, so the destroy() will remove your previous chart and add current chart on your action(may be a button click).

Hope it helps

Ảnh đại diện
Huỷ bỏ
Tác giả

Good , it works well....

Thank you Cybrosys Techno Solutions

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 21
2738
1
thg 7 24
1091
1
thg 6 23
1571
2
thg 5 23
2561
1
thg 5 23
1497