gpt4 book ai didi

javascript - 如何在堆栈中添加值

转载 作者:行者123 更新时间:2023-11-27 23:34:55 25 4
gpt4 key购买 nike

我有一堆数字,用于在图表中显示...我想添加这些数字并在标签中显示数字......我该怎么做?

 $(function ZoneClick() {
$("[id*=rbtnZone]").click(function() {
var row = $(this).closest('tr');
var branchId = $(row).find('[id*=hfBranchId]').val();
var rbtlSales = $("#<%= rbtlSales.ClientID%>");
var selectedValue = rbtlSales.find("input:checked").val();

$.ajax({
url: '<%=ResolveUrl("~/Corporate/Sales.aspx/GetZoneData") %>',
data: "{'rbtlSales':'" + selectedValue + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(data) {
var labels = [];
var datas = [];
$.each(data.d, function(i, item) {
var l = item.split('-')[0];
var d = item.split('-')[1];
var dd = d | 0;
labels.push(l);
datas.push(dd);
});

var barChartLocData =
{
labels: labels,
datasets:
[
{
fillColor: "indianred",
highlightFill: "red",
data: datas
}
]
};
var ctx = document.getElementById("canvas").getContext("2d");
new Chart(ctx).HorizontalBar(barChartLocData, {
responsive: true,
scaleFontColor: "#000",
showTooltips: false,
onAnimationComplete: function() {
var ctx = this.chart.ctx;
ctx.font = this.scale.font;
ctx.fillStyle = this.scale.textColor
ctx.textAlign = "right";
ctx.textBaseline = "center";
this.datasets.forEach(function(dataset) {
dataset.bars.forEach(function(bar) {
ctx.fillText(bar.value, bar.x + 15, bar.y);
});
});
}
});
},
error: function(response) {
},
failure: function(response) {
}
});
});
});

最后一行 dd 包含值...我想添加它们并将其显示在标签中...

问候,萨金A

最佳答案

使用 array.push()array.pop()array 用作 stack

http://www.w3schools.com/jsref/jsref_push.asp

http://www.w3schools.com/jsref/jsref_pop.asp

一些例子:

var initial_arr = [ 1, 4 ];
console.log( initial_arr ); // output : [ 1, 4 ]

initial_arr.push(6);
console.log( initial_arr ); // output : [ 1, 4 , 6]

initial_arr.push(9);
initial_arr.push(7);
console.log( initial_arr ); // output : [ 1, 4 , 6, 9, 7]

var popedValue = initial_arr.pop();
console.log( popedValue ); // output : 7
console.log( initial_arr ); // output : [ 1, 4 , 6, 9]

关于javascript - 如何在堆栈中添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34332422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com