首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >字符串化JSON的高级图表选项

字符串化JSON的高级图表选项
EN

Stack Overflow用户
提问于 2014-09-03 16:30:03
回答 1查看 1.2K关注 0票数 1

我需要将高级图表选项转换为JSON字符串。我真的很纠结于此。

因为它有立方体结构。

示例:http://jsfiddle.net/8TEKD/

我还试着用douglascrockford cycle.js:https://github.com/douglascrockford/JSON-js来拆解它

如果我试着去循环它,我就会得到这个堆迹

代码语言:javascript
复制
'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 ,然后用该配置加载它。

有办法这样做吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-03 23:50:07

问题是,$('#container').highcharts(options);向对象(即DOM元素)添加了一个renderTo元素。在添加之前,您没有循环结构。而且,如果您真的想保存配置选项以便再次使用,那么保存它们呈现到的DOM元素对您没有用处。

我建议在创建图表之前保存json:

代码语言:javascript
复制
$(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.stringifyreplacer选项来排除您不想要的options对象的部分。parameter

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25649369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档