"elements":[
{
"type": "bar_stack",
"on-click": "barClicked",
"on-click-text": "#key# = #val#",
"values" : [
[2.5,{"val":5, "text":"test key"}],
[{"val":3},{"val":4},{"val":5}],
null,
[{"val":5},{"val":5},{"val":2},{"val":2},
{"val":2, "colour":"#ff00ff",
"text":"special", // Note that this is the #key# value
"on-click-text":"{\"key\":\"#key#\", \"value\":#val#, \"stackTotal\":#total#}",=======重点是这行
"on-click":"specialClicked" },=======重点是这行
{"val":2},{"val":2}]
]
"keys": [
{"colour":"#FF0000", "text": "Key 1", "font-size": 10},
{"colour":"#00FF00", "text": "Key 2", "font-size": 16},
],
"tip":"#key#<br>#val#",
}
],
><script type="text/javascript">
function barClicked(index, onClickText)
{
alert(onClickText);
}
function specialClicked(index, onClickText)
{
alert("before parsing JSON: " + onClickText);
var obj = JSON.parse(onClickText);
alert("after parsing JSON: \n" +
"obj.key = " + obj.key + "\n" +
"obj.value = " + obj.value + "\n" +
"obj.stackTotal = " + obj.stackTotal);
}
</script>
更多信息请查看IT技术专栏