0

如果我们有这样的代码

 yAxis : {
            title : {
                text : 'Exchange rate'
            },
            plotLines : [{
                value : 0.6738,
                color : 'green',
                dashStyle : 'shortdash',
                width : 2,
                label : {
                    text : 'Last quarter minimum'
                }
            }, {
                value : 0.7419,
                color : 'red',
                dashStyle : 'shortdash',
                width : 2,
                label : {
                    text : 'Last quarter maximum'
                }
            }]
        },

我如何获取 plotlines json 字符串并将其分配给一个变量并将此变量传递给 plotline 对象?我试过这样的东西

 var jsonObj = [];
 jsonObj.push({ "value": 1256211571000, "color": '#D2691E', "width": 1, "label": {   "text": 'rinse'} });
        var myLines = JSON.stringify(jsonObj);

然后将 mylines 传递给 plotlines 但它并没有真正起作用

4

2 回答 2

1

假设此对象位于名为 的变量中data,只需执行以下操作:

data.yAxis.plotLines.push({
    "value": 1256211571000,
    "color": '#D2691E',
    "width": 1,
    "label": {
        "text": 'rinse'
    }
});

这只是一个 JavaScript 对象,而不是 JSON。JSON 是对象(或数组)的字符串表示形式。

于 2012-05-01T21:05:20.363 回答
0

这是一个例子,如果它适合你'

$(文档).ready(函数() {

        $.getJSON('yourpage.php?getdata=y&compid=<?php echo $comp_details[0]['id']; ?>', function(data) {

            // split the data set into ohlc and volume
            var ohlc = [],
            volume = [],
            dataLength = data.length;

            for (i = 0; i < dataLength; i++) {
                //console.log(data[i][2]);
                ohlc.push([
                    data[i][0], // the date
                    data[i][1], // open
                    data[i][2], // high
                    data[i][3], // low
                    data[i][4] // close
                ]);

                volume.push([
                    data[i][0], // the date
                    data[i][5] // the volume
                ])
            }

            // set the allowed units for data grouping
            var groupingUnits = [[
                    'week',                         // unit name
                    [1]                             // allowed multiples
                ], [
                    'month',
                    [1, 2, 3, 4, 6]
                ]];

            // create the chart
              chart = new Highcharts.StockChart({
                chart: {
                    renderTo: 'container',
                    alignTicks: false,
                    zoomType: 'x'
                },

                rangeSelector: {
                    selected: 0
                },

                title: {
                    text:  '<?php echo strtoupper($_GET['CompanySymbol']); ?>'+' Historical'
                },

                yAxis: [{
                        title: {
                            text: 'OHLC'
                        },
                        height: 200,
                        lineWidth: 2,
                        min:0
                    }, {
                        title: {
                            text: 'Volume'
                        },
                        top: 300,
                        height: 100,
                        offset: 0,
                        lineWidth: 2

                    },
                    {

                        height: 200,
                        min: 0,
                        lineWidth: 2,
                        opposite: true

                    }],
                tooltip: {
                    crosshairs: [true,true],
                    shared: true
                },  

                series: [{
                        type: 'ohlc',
                        name: '<?php echo strtoupper($_GET['CompanySymbol']); ?>',
                        data: ohlc,
                        dataGrouping: {
                            units: groupingUnits
                        }
                    },
                    {
                        type: 'line',
                        name:'Fuerte',
                        yAxis: 2,
                        data:[<?php echo $newdata; ?>]
                    },
                    {
                        type: 'line',
                        name:'Debil',
                        yAxis: 2,
                        data:[<?php echo $newdata1; ?>]
                    },
                    {
                        type: 'column',
                        name: 'Volume',
                        data: volume,
                        yAxis: 1,
                        dataGrouping: {
                            units: groupingUnits
                        }
                    }]
            });
                chart.yAxis[2].setExtremes(10,90);
        });
    });'
于 2012-05-11T09:48:34.217 回答