简体   繁体   English

我想在每个按钮单击事件上加载多个图表。

[英]I want to load multiple charts on every button click event.I have used below google code

In my project I have 3 buttons and on each button click event I am calling different google chart function ...... 在我的项目中,我有3个按钮,并且在每个按钮单击事件上,我都调用不同的Google图表函数......

My question is when I click on one button the chart is load but when I click second or any button the chart is not update I am passing data from json 我的问题是当我单击一个按钮时图表已加载,但是当我单击第二个按钮或任何按钮时图表未更新时,我正在从json传递数据

 function daily() { google.charts.load('current', { packages: ['corechart', 'line'] }); google.charts.setOnLoadCallback(drawBasic); function drawBasic() { var data = new google.visualization.DataTable(); data.addColumn('date', 'X'); data.addColumn('number', 'Score'); for (var i = 0; i < dscr.length; i++) { //alert(dscr.length); //alert(dscr[i].Success); //alert(dscr[i].Date); var dt = mscr[i].Date; //var dt = dscr[i].Date; //var d = new Date(dt); //var n = d.getDate(); //alert(n); data.addRow([new Date(dscr[i].Date), dscr[i].Success]); } var options = { hAxis: { title: 'Day' }, vAxis: { title: 'Score' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } } function weekly() { google.charts.load('current', { packages: ['corechart', 'line'] }); google.charts.setOnLoadCallback(drawBasic); function drawBasic() { var data = new google.visualization.DataTable(); data.addColumn('date', 'X'); data.addColumn('number', 'Score'); for (var i = 0; i < wscr.length; i++) { data.addRow([new Date(wscr[i].Date), wscr[i].Success]); } var options = { hAxis: { title: 'Day' }, vAxis: { title: 'Score' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } } function monthly() { google.charts.load('current', { packages: ['corechart', 'line'] }); google.charts.setOnLoadCallback(drawBasic); function drawBasic() { var data = new google.visualization.DataTable(); data.addColumn('date', 'X'); data.addColumn('number', 'Score'); for (var i = 0; i < mscr.length; i++) { scr[i].Date), mscr[i].Success]); } var options = { hAxis: { title: 'Day', }, vAxis: { title: 'Score' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } } 
  <li role="presentation" class="active"> <a href="#Daily" aria-controls="home" class="btn btn-md WinnerButton" role="tab" onclick="daily()" data-toggle="tab" data-bind=" click: StatisticalDaily"> DAILY </a> </li> <li role="presentation"> <a href="#Weekly" aria-controls="profile" class="btn btn-md WinnerButton" role="tab" onclick="weekly()" data-toggle="tab" data-bind=" click: StatisticalWeekly"> WEEKLY </a> </li> <li role="presentation"> <a href="#Monthly" aria-controls="messages" class="btn btn-md WinnerButton" role="tab" data-toggle="tab" onclick="monthly()" data-bind="click: StatisticalMonthly"> MONTHLY </a> </li> <div id="chart_div"></div> 

Your issue is you are trying yo call google.charts.load() more than once which is not allowed. 您的问题是您尝试不止一次致电google.charts.load() In addition, you should not define drawBasic() three times in daily() , weekly() , and monthly() . 此外,您不应在daily()weekly()drawBasic()定义3次drawBasic() monthly()

Here is a working jsfiddle . 这是一个工作的jsfiddle It may be a good start to achieve what you need. 这可能是实现您所需的一个良好的开始。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想在提示中按下 Esc 按钮时提醒一个值,但我不知道...(下面的代码) - I want to alert a value when I press the Esc button in prompt, but I have no idea... (code below) 为什么当我按下按钮时,我的 output 会乘以? 我希望它每次点击都有一个 output - Why are my output multiplies when I press the button? I want it to have single output every click Google图表-我希望该坐标轴不显示每个项目 - Google Charts - I want the axis to not show every item 我在下面有此代码,我希望控制台显示文本 - I have this code below and I want the console to display the text 每次单击按钮,我都想在两个功能之间切换 - On every button click, I want to switch between two functions Google图表上的Click事件 - Click event on google charts 我必须使用coffeescript将为图表编写的每一行代码转换为一个类(面向对象) - I have to Transform every line of code that I have written for charts into a class (object oriented) using coffeescript 在网页上有不可见的表单,并希望通过DojoToolkit在单击按钮时使它们可见,不知道我的代码有什么问题 - Have invisible forms on a webpage and want to make them visible on button click with DojoToolkit, not sure what's wrong with the code I have 我想在tinyMCE图像工具中捕获“确定”按钮的单击事件 - I want to catch click event of Ok button in tinyMCE image tools 该按钮没有单击我已经使用了javascript和Actions语法 - The button does not click I have used javascript and and the Actions syntax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM