流星上的Google图表有时有效,有时不起作用

时间:2016-01-08 12:48:35

标签: javascript meteor google-chartwrapper

我有2个图表,一个是饼图和其他条形图,饼图在所有条件下工作,而条形图不工作一些,我有列表框值,所选列表框值在会话变量中捕获。基于在列表框值的类型上应显示图表。更改列表框值,饼图工作但条形图显示空白的铬,而在Firefox上它显示错误*没有错误的详细信息。对这种行为有任何想法。以下是饼图和条形图的代码。

Template.DashboardIncomeExpBalancePeriod.onRendered(function() {
    //console.log("iam from dashboard period");
    var currentuserid=Meteor.userId();
        if(currentuserid){
            barChart();
        }
});

function barChart(){
    var currentuserid=Meteor.userId();
    if(currentuserid){
        google.load('visualization', '1.1', {
            'packages': ["bar"],
            callback: drawChart
        });
    }    
    function drawChart() {
    Tracker.autorun(function () {
        console.log("the current accountin draw chart: "+Session.get("SelCurrentAccount"))
        var data = google.visualization.arrayToDataTable(getData());
        var myDiv=document.getElementById('IncomeExpBalancePeriodBarChart')
        var selectedAccount=Session.get("SelCurrentAccount");
        //console.log("in tracker drawchart" + myDiv);
        if( selectedAccount && myDiv && data){
            console.log("the current accountin draw chart: inside if")

            var thismonth=moment.monthsShort(moment().month());
            var lastmonth=moment.monthsShort(moment(new Date()).subtract(1,'month').month());
            var varselectedaccount=$('[name=selectAccount]').find("option:selected").text()
            var options = {
              chart: {
                title: 'Your "' + varselectedaccount +  '" Account Performance',
                subtitle: 'Income, and Expenses: ' +  lastmonth  + ' & ' + thismonth ,
              }
            };

            var chart = new google.charts.Bar(document.getElementById('IncomeExpBalancePeriodBarChart'));
            console.log("data values" + data);
            chart.draw(data, options);
            //this is for responsive graphs
            function resizeHandler () {
                console.log("resizeHandler");
                chart.draw(data, options);
            }
            if (window.addEventListener) {
                //console.log("addEventListener");
                window.addEventListener('resize', resizeHandler, false);
            }
            else if (window.attachEvent) {
                //console.log("attachEvent");
                window.attachEvent('onresize', resizeHandler);
            }
        }
    })
    }

}

0 个答案:

没有答案