简体   繁体   English

并非所有事件都在单击按钮时触发

[英]Not all events firing on button clicks

EDIT: I have fixed the code so that the callback calls drawChart outside of the function, and it does in fact work on a button click. 编辑:我已经修复了代码,以便回调drawChart外部调用drawChart ,它实际上在单击按钮时起作用。 But, I have two things happening that need to happen on one button click. 但是,一键式单击就需要发生两件事。

I am using $.get to grab data that I have loaded into an array server-side (nodejs) and then send the response of this data to the pie chart. 我正在使用$.get来获取已加载到服务器端阵列(nodejs)中的数据,然后将此数据的响应发送到饼图。 I am not getting any errors inside my command prompt or on the console inside the browser, so I am at a loss as to why both .click actions are not firing. 我没有在命令提示符下或浏览器内的控制台上收到任何错误,所以我对为什么两个.click操作均未触发感到.click

At first, the pie chart was not working, but then I adjusted it to have the chart draw at the correct time on the button click and now the chart works, but not the other action. 最初,饼图无法正常工作,但是随后我对其进行了调整,以使其在正确的时间单击按钮即可绘制图表,现在该图表可以工作了,但其他操作却没有。

Also, is it not possible to have more than one $.get request on a button click? 此外,单击按钮是否不可能有多个$.get请求? I do not have it fully implemented in below code, but I am ultimately trying to do that. 我没有在下面的代码中完全实现它,但是我最终试图做到这一点。 (on first request, I send an array of tweets to the clientside javascript to parse, on second request I send an array of other analyzation data to the clientside javascript to put into the piechart visualization) (在第一个请求上,我向客户端javascript发送了一组tweet进行解析,在第二个请求上,我向客户端javascript发送了一系列其他分析数据,以放入饼图可视化中)

Here is some code: 这是一些代码:

$("#startButton").click(function() {
    $.get( "/startButton", success);
    function success(data){ ... code inside creates html for 2 divs..., has been working }
});

function drawChart() {
    var data = google.visualization.arrayToDataTable(
    //chartData);
    [
    ['Task', 'Hours per Day'],
    ['Work',     11],
    ['Eat',      2],
    ['Commute',  2],
    ['Watch TV', 2],
    ['Sleep',    7]
    ]);
    var options = {
        title: 'Retweets versus Original Tweets'
    };
    var chart = new google.visualization.PieChart(document.getElementById('piechart'));
    chart.draw(data, options);
}
function initialize() {
    $('#startButton').click(function() {
        drawChart();
    });
}
google.setOnLoadCallback(initialize);
google.load("visualization", "1", {packages:["corechart"]});

Function drawChart() is not called at all. 完全不调用drawChart()函数。 This should work: 这应该工作:

//    $(document).ready(function() {

google.load("visualization", "1", {packages:["corechart"]});

function drawChart() {
    var data = google.visualization.arrayToDataTable(
    //chartData);
    [
    ['Task', 'Hours per Day'],
    ['Work',     11],
    ['Eat',      2],
    ['Commute',  2],
    ['Watch TV', 2],
    ['Sleep',    7]
    ]);
    var options = {
      title: 'Retweets versus Original Tweets'
    };

    var chart = new google.visualization.PieChart(document.getElementById('piechart'));
    chart.draw(data, options);

    //google.setOnLoadCallback(drawChart);
}
google.setOnLoadCallback(drawChart);

//});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM