有没有方法可以在没有eval的情况下输入Highchart系列数据? [英] Is there a way to enter Highchart series data without eval?

查看:126
本文介绍了有没有方法可以在没有eval的情况下输入Highchart系列数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



最后,我不得不使用eval(data)。



有没有更好的方法来做到这一点?



JSFiddle示例

  $(function(){
var test =[[Date.UTC(2013,4,08),45.95],[Date.UTC(2013,5,28),19.95]];
$('#container')。highcharts({
图:{
},
xAxis:{
类型:'datetime'
},

系列:[{
数据:eval(测试)
}]
});
});



更新1



我的实际目标是将一个JSON对象传递给一个函数(如下所示),然后获取所需的字符串并将它们传递给序列输入。

以下内容仍然不起作用。

p>

  function showPriceChart(priceData){

var json = jQuery.parseJSON(priceData);
var pricePrices = [json.pricePrices];

//如果我在
下面使用eval,这个方法可以工作// var pricePrices ='['+ json.pricePrices +']';


///其他图表配置在这里

系列:[{
名称:'零售商价格',
数据:pricePrices
},{
名称:'RRP',
data:rrpPrices
}]
});



$ b

这里是使用print_r()的php中的JSON对象:

$ DateTime.UTC(2013,4,8),67],[Date.UTC(2013,4,8),67],

  {pricePrices Date.UTC(2013,4,8),],[Date.UTC(2013,5,28)],rrpPrices:[Date.UTC (2013,4,8),67],[Date.UTC(2013,5,28),67]} 


解决方案

问题是您正在使用 Date.UTC()函数,因此您需要使用eval。如何传递数字(毫秒时间戳)而不是该函数?所以,你的JSON应该是这样的:

  {
pricePrices:[1367971200000,67],[1372377600000 ,29],
salePrices:[1367971200000,],[1372377600000,],//其中是值?!
rrpPrices:[1367971200000,67],[1372377600000,67] //无额外'''!!
}

另外,第二个系列有一些缺失值,它们在哪里?


I have been working on getting data into a highchart graph with much difficulty.

Eventually I had to go with using eval(data).

Is there a better way to do this?

JSFiddle Example

$(function () {
    var test = "[[Date.UTC(2013, 4, 08), 45.95],[Date.UTC(2013, 5, 28), 19.95]]"; 
    $('#container').highcharts({
        chart: {
        },
        xAxis: {
            type: 'datetime'
        },

        series: [{
            data: eval(test)
        }]
    });
});

UPDATE 1

My actual objective is to pass a JSON object into a function (as shown below) then get the required strings and pass them to the series input.

The following is still not working.

function showPriceChart(priceData) {

    var json = jQuery.parseJSON(priceData);
    var pricePrices = [ json.pricePrices ];

            // This works if I use eval below
            // var pricePrices = '['+json.pricePrices+']';


    /// Other chart config goes here

    series: [{
            name: 'Retailer Price',
            data: pricePrices
        }, {
            name: 'RRP',
            data: rrpPrices
        }]
    });
    }

Here is the JSON object from php using print_r():

{"pricePrices":"[Date.UTC(2013, 4, 8), 67],[Date.UTC(2013, 5, 28), 29]","salePrices":"[Date.UTC(2013, 4, 8), ],[Date.UTC(2013, 5, 28), ]","rrpPrices":"[Date.UTC(2013, 4, 8), 67],[Date.UTC(2013, 5, 28), 67]"}

解决方案

The problem is that you are using Date.UTC() function, so you need to use eval. How about passing numbers(timestamps in milliseconds) instead of that functions? So, your JSON should look this way:

{
 "pricePrices":[1367971200000, 67],[1372377600000, 29],
 "salePrices":[1367971200000, ],[1372377600000, ], //where are values ?!
 "rrpPrices":[1367971200000, 67],[1372377600000, 67] //without extra '"'!! 
}

Also, there is some missing values for second series, where are they?

这篇关于有没有方法可以在没有eval的情况下输入Highchart系列数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆