我有一堆数字,用于在图表中显示... 我想添加这些数字并在标签中显示数字...... 我怎么能这样做?
$(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) {
}
});
});
});
&#13;
最后一行dd包含值...我想添加它们并将其显示在标签中......
此致 Sajin A
答案 0 :(得分:2)
使用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]
答案 1 :(得分:0)