无法从 Google 动态图表中获取 getState()
Unable to getState() from a Google motion chart
我正在尝试获取 Google 动态图表的状态,以便我可以在图表选项中修改初始状态。该文档建议创建一个按钮,该按钮将在图表上调用 getState() 以检索包含您想要的参数的字符串。
但是,当我尝试 console.log() 从 drawChart 函数内部获取值时,在图表 returns "null" 上调用 getState() 并且在我尝试时根本不起作用使用闭包从按钮调用它。这是我的代码:
<script>
function drawChart() {
var data = new google.visualization.DataTable();
//there is data here
data.addRows(datajson);
var options = {};
//there are options here
var chart = new google.visualization.MotionChart(document.getElementById('chart_div'));
chart.draw(data, options);
var getChartState = function() {
var chartState = chart.getState();
console.log(chartState);
};
return getChartState;
};
</script>
<div onclick="getChartState()">Get Chart State</div>
<div id="chart_div"> </div>
Motion Chart 是一个基于 Flash 的组件,您可能从 getState
函数中得到 null,因为图表无法正确呈现,这反过来可能与以下原因有关:
确保您的计算机上安装了 Flash Player,请按照 此
link判断Flash Player是否安装在你的
系统
由于 Flash 安全设置,Motion Chart(以及所有基于 Flash 的
可视化)从文件访问时可能无法正常工作
浏览器中的位置(例如,file:///c:/webhost/myhost/myviz.html
)
而不是来自 Web 服务器 URL
工作示例 演示如何绘制 Motion Chart 并获取其状态。
我正在尝试获取 Google 动态图表的状态,以便我可以在图表选项中修改初始状态。该文档建议创建一个按钮,该按钮将在图表上调用 getState() 以检索包含您想要的参数的字符串。
但是,当我尝试 console.log() 从 drawChart 函数内部获取值时,在图表 returns "null" 上调用 getState() 并且在我尝试时根本不起作用使用闭包从按钮调用它。这是我的代码:
<script>
function drawChart() {
var data = new google.visualization.DataTable();
//there is data here
data.addRows(datajson);
var options = {};
//there are options here
var chart = new google.visualization.MotionChart(document.getElementById('chart_div'));
chart.draw(data, options);
var getChartState = function() {
var chartState = chart.getState();
console.log(chartState);
};
return getChartState;
};
</script>
<div onclick="getChartState()">Get Chart State</div>
<div id="chart_div"> </div>
Motion Chart 是一个基于 Flash 的组件,您可能从 getState
函数中得到 null,因为图表无法正确呈现,这反过来可能与以下原因有关:
确保您的计算机上安装了 Flash Player,请按照 此 link判断Flash Player是否安装在你的 系统
由于 Flash 安全设置,Motion Chart(以及所有基于 Flash 的 可视化)从文件访问时可能无法正常工作 浏览器中的位置(例如,
file:///c:/webhost/myhost/myviz.html
) 而不是来自 Web 服务器 URL
工作示例 演示如何绘制 Motion Chart 并获取其状态。