English 中文(简体)
• 如何在javascript中积极增加阵列中的物品
原标题:how to add items to an array dynamically in javascript

首先,我是一整条新版,请与我一起。 我有以下文字,利用高智能框架绘制图表。

$(function() {
    var options = {
        colors: ["#66CC00", "#FF0000", "#FF6600"],
        chart: {
            renderTo:  container ,
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: true
        },
        title: {
            text:  Host Status 
        },
        tooltip: {
            formatter: function() {
                return  <b>  + this.point.name +  </b>:   + this.total;
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor:  pointer ,
                dataLabels: {
                    enabled: true,
                    color:  #000000 ,
                    connectorColor:  #000000 ,
                    formatter: function() {
                        return  <b>  + this.point.name +  </b> ;
                    }
                }
            }
        },
        series: [{
            type:  pie ,
            name:  service status ,
            data: []
        }]
    }

    var chart;
    options.series.data.push( [ 
    Service Ok  ,   45.0] )
    $(document).ready(function() {
        chart = new Highcharts.Chart(options)
    });

});​

试图做的是,将价值动态地装入<代码>系列中。 在这里,什么是错的,将数据输入数据阵列是否有更好的办法?

最佳回答

<>系列>:财产是一个阵容,因此,你需要照此写(在系列中增加一个数据点):

options.series[0].data.push( ["Service Ok", 45.0 ]);

我正在查看

问题回答

You have an error on your code:
You said you want to dynamically load the values, rigth ?
But you code just sets the initial serie data and then render it.
So in your case if you want to dinamically change your serie data you have to destroy the current chart, update it s data and then render it again. Propably you loss performance.

The correct way to do it is using highstock api and don t update it manually. If you do it probably you ll get some errors when you use chart zoom, because to update the chart points this api have to calculate the points again, and it s made when you use the functions above.
As you can see on the
serie reference to update your chart data you have to use the following functions:
Set new data: chart.series[0].setData(newData, redraw); example
Add a new point: chart.series[0].addPoint(arrayOfPoints, redraw); example

www.un.org/spanish/ecosoc http://jsfiddle.net/MNb7c/1/"rel=“nofollow”>fiddle。 我人工更新图表,不使用复印机,情况如何? 页: 1

如欲达到最佳业绩,可使用以下代码:

    function createChart() {
        chart = new Highcharts.Chart(options);
    }

    // when you want to update it s data
    $(element).yourEvent(function() {
        var newData = [ Service Ok , 50.0];
        if(chart.hasRendered) {
            chart.series[0].setData(newData, true);
        } else {
            // only use it if your chart isn t rendered
            options.series[0].data.push(newData);
            createChart();
        }
    });

$(function() {
    var options = {
        colors: ["#66CC00", "#FF0000", "#FF6600"],
        chart: {
            renderTo:  container ,
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: true
        },
        title: {
            text:  Host Status 
        },
        tooltip: {
            formatter: function() {
                return  <b>  + this.point.name +  </b>:   + this.total;
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor:  pointer ,
                dataLabels: {
                    enabled: true,
                    color:  #000000 ,
                    connectorColor:  #000000 ,
                    formatter: function() {
                        return  <b>  + this.point.name +  </b> ;
                    }
                }
            }
        },
        series: [{
            type:  pie ,
            name:  service status ,
            data: [ Service Ok  ,   45.0]
        }]
    }

    var chart;
    $(document).ready(function() {
        createChart();
    });
});​

I think it might helps you JavaScript push() Method specification

and Highcharts control specification

<>Series<>>>>>>是一系列物体,因此,您应照此办理:

options.series[0].data.push(["Service Ok", 45.0 ])

在此情况下,你将获得治疗。

series: [{

    type:  pie ,

    name:  service status ,

    data: [
             ["Service Ok", 45.0 ]
          ]

    }]

DEMO with piemap>>

引言

$(function() {
var options = {   
    series: [{
        type:  pie ,
        name:  service status ,
        data: []
        }]
};    
    var objData={ "type": bar , name : second , data :[]};
    options.series.push(objData);
});​

审判

options.series[0]data[0]=  Service Ok ;
options.series[0]data[1]= 45.0;




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签