我需要将高级图表选项转换为JSON字符串。我真的很纠结于此。
因为它有立方体结构。
示例:http://jsfiddle.net/8TEKD/
我还试着用douglascrockford cycle.js:https://github.com/douglascrockford/JSON-js来拆解它
如果我试着去循环它,我就会得到这个堆迹
'Attr.ownerElement' is deprecated and has been removed from DOM4 (http://w3.org/tr/dom). cycle.js:92
'Attr.textContent' is deprecated. Please use 'value' instead. cycle.js:92
'Attr.nodeValue' is deprecated. Please use 'value' instead. cycle.js:92
'HTMLHtmlElement.manifest' is deprecated. The manifest attribute only has an effect during the early stages of document load. cycle.js:92
InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('checkbox') does not support selection.我需要这样做,因为我想要保存图表的configuration ,然后用该配置加载它。
有办法这样做吗?
谢谢
发布于 2014-09-03 23:50:07
问题是,$('#container').highcharts(options);向对象(即DOM元素)添加了一个renderTo元素。在添加之前,您没有循环结构。而且,如果您真的想保存配置选项以便再次使用,那么保存它们呈现到的DOM元素对您没有用处。
我建议在创建图表之前保存json:
$(function () {
var options = {
chart: {
marginRight: 120
},
legend: {
align: 'right',
verticalAlign: 'top',
x: 0,
y: 100
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
};
jsonstring = JSON.stringify(options);
$('#container').highcharts(JSON.parse(jsonstring)); // just to prove it works, obviously you would use the options variable here
});http://jsfiddle.net/6y2gg6oy/
但是,如果这不是一个选项,您可以使用JSON.stringify的replacer选项来排除您不想要的options对象的部分。parameter
https://stackoverflow.com/questions/25649369
复制相似问题