【发布时间】:2017-09-04 07:04:25
【问题描述】:
我正在使用数据加载器生成图表。我的 JSON 数据与此类似。
{
"Month": 1,
"District1": 2.6,
"District2": 5.7,
"District3": 6.2,
"District4": 7.3,
}, {
"Month": 2,
"District1": 4.6,
"District2": 5.7,
"District3": 2.2,
"District4": 6.3,
"District5": 4.3,
"District7": 1.3,
}
在我的 JavaScrit 中,我使用此代码从 PHP 文件生成图形。
for ( var key in chart.dataProvider[ 0 ] ) {
if ( chart.dataProvider[ 0 ].hasOwnProperty( key ) && key != chart.categoryField ) {
var graph = new AmCharts.AmGraph();
graph.valueField = key;
graph.type = "column";
graph.title = key;
graph.lineThickness = 0;
graph.urlField =?????????????????????
graph.urlTarget ="_blank";
graph.labelColor = "#cccccc";
graph.connect = false;
graph.fillAlphas = 0.8;
graph.balloonFunction = adjustBalloonText;
graph.labelText = key;
chart.addGraph( graph );
}
}
数据是动态的,有些飞蛾有 15 个对象,有些只有 12 个。
我想为每个地区或 ID 添加一个链接,以便生成新图表。 我如何将它添加到 JSON 字符串中。我试图用对象做到这一点 像这样。
{
"Month":1
"District1": {"value":1, "url":"url.php?id=1", "id":1}
"District2": {"value":2, "url":"url.php?id=2", "id":2}
}
我无法将对象分配给 graph.valueField = key;
这可以解决吗?点击事件只返回月份索引而不是关于图形“ID”的信息。
希望有人能帮我解决这个问题。我已经尝试了几个小时没有任何运气。
最好的问候
马丁
【问题讨论】: