简体   繁体   English

Google图表:“无法读取未定义的属性'toLowerCase'”

[英]Google Chart: “Cannot read property 'toLowerCase' of undefined”

I try to generate a google chart. 我尝试生成一个Google图表。 It returns " Cannot read property 'toLowerCase' of undefined " in the chart area but no error in the console. 它在图表区域中返回“ 无法读取未定义的'toLowerCase属性',但在控制台中没有错误。

function drawChart(chart_data, chartType, chartOptions){

           console.log(chartOptions);

            var data = new google.visualization.DataTable(chart_data);

            var chart = new google.visualization.ChartWrapper({

                chartType: chartType,
                dataTable: data,
                options: chartOptions,
                containerId: 'chart'

            });

            chart.draw();
        }

The results of the console.log is a string that looks like: console.log的结果是一个类似于以下内容的字符串:

{"title":"test","vAxis":{"minValue":"0"},"hAxis":{"showTextEvery":"1"},"chartArea":{"width":"70%","height":"90%"},"pointSize":"7","height":"500","intervals":{"lineWidth":2,"barWidth":0.5,"color":"#000000"}} 

If I use (copy-paste) the result of the console.log instead of using chartOptions as options , the chart is displayed perfectly. 如果我使用(复制粘贴) console.log的结果而不是使用chartOptions作为options ,则该图表将完美显示。

What am I missing here? 我在这里想念什么?

The only explanation I can think of (given that copy-pasting it works fine), is that in one instance you are sending a string, and when you copy paste it back in, you then have an object. 我能想到的唯一解释(假设复制粘​​贴可以正常工作)是,在一种情况下,您正在发送字符串,复制时将其粘贴回去,然后便有了一个对象。

在此处输入图片说明

So if you look at the console log, it SHOULD look like the first one in the picture above. 因此,如果您查看控制台日志,它应该类似于上图中的第一个日志。 If it looks like the second, you need to do 如果看起来像第二个,则需要

chartOptions = JSON.parse(chartOptions);

var chart = new google.visualization.ChartWrapper({
              chartType: chartType,
              dataTable: data,
              options: chartOptions,
              containerId: 'chart'
            });

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

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