Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 解析聚合物中的岩心响应值_Javascript_D3.js_Polymer_C3.js - Fatal编程技术网

Javascript 解析聚合物中的岩心响应值

Javascript 解析聚合物中的岩心响应值,javascript,d3.js,polymer,c3.js,Javascript,D3.js,Polymer,C3.js,我正在使用Polymer从flax/python后端请求x和y值,我可以在控制台中读取XMLHttpResquest响应的值,但现在我需要将输出转换为一组离散的x和y值(因此可以由C3.js读取,C3.js是一个位于D3顶部用于绘图的框架) 下面是我用来获取XMLHttpResquest响应的代码: <paper-button affirmative hover on-tap="{{addNewGraph}}">Submit</paper-button> Polymer

我正在使用Polymer从flax/python后端请求x和y值,我可以在控制台中读取XMLHttpResquest响应的值,但现在我需要将输出转换为一组离散的x和y值(因此可以由C3.js读取,C3.js是一个位于D3顶部用于绘图的框架)

下面是我用来获取XMLHttpResquest响应的代码:

<paper-button affirmative hover on-tap="{{addNewGraph}}">Submit</paper-button>

Polymer("add-graphItem",{

        addNewGraph: function () {

            var HeaderName = this.$.graphOptionsLoad.$.headerValue.selectedItem.label;
            var FunctionName = this.$.graphFunctionsLoad.$.functionValue.selectedItem.label;
            console.log("The options are " +HeaderName +" and " +FunctionName);

            var params = {};
            if (this.$.graphOptionsLoad.$.headerValue.selectedItem) {
                params['DataHeader'] = this.$.graphOptionsLoad.$.headerValue.selectedItem.label;
            }
            if (this.$.graphFunctionsLoad.$.functionValue.selectedItem) {
                params['FunctionName'] = this.$.graphFunctionsLoad.$.functionValue.selectedItem.label;
            }
            this.$.sendOptions.params = JSON.stringify(params);
            var x = this.$.sendOptions.go();
            // this.$.sendOptions.go();
            console.log(x)

            // var ajax = document.querySelector("sendOptions");

            var results = [];
            this.addEventListener("core-response", 
                function(e) {
                    console.log(x.response);
                }
            );
        }
});
最终,我需要输出如下所示:

['x', 0.0, 131.35, 26971.3, 27044.75, 27351.4, 27404.483333333334...],
['y', 1, 2, 3, 4, 5, 6]

这里有一种快速而肮脏的方法,不建议大规模使用,或者如果您不完全信任响应值。同样,很明显,但是如果他们的api/数据结构发生了变化,那么你就是SOL

xArr = JSON.parse(x.response).graph[1].x
xArr.unshift('x')

yArr = JSON.parse(y.response).graph[2].y
yArr.unshift('y')
您将获得所需的两个阵列,您可以根据需要进行组合

xArr = JSON.parse(x.response).graph[1].x
xArr.unshift('x')

yArr = JSON.parse(y.response).graph[2].y
yArr.unshift('y')