【发布时间】:2019-05-06 06:24:27
【问题描述】:
我正在尝试从数据库中获取数据并将其动态显示到 highchart 系列数据中。为此,我使用以下代码:
$(function () {
$.ajax({
url: "/WebApi/MIPResource_DistrictWise",
cache: false,
success: function (data) {
var categories ;
var i;
for (i = 0; i < data.length; i++) {
categories += data[i].DISTRICT_NAME;
}
alert(categories);
// var xx = [][][];
// var data = "";
// var i;
// for (i = 0; i < xx.length; i++) {
// data += xx[i];
// }
Highcharts.chart('MIPDistrictWise', {
chart: {
type: 'bar'
},
title: {
text: 'MIP Resource Requirement <br> (District Wise)'
},
xAxis: {
categories: categories
},
yAxis: {
min: 0,
title: {
text: 'Total Resources Required'
}
},
legend: {
reversed: true
},
plotOptions: {
series: {
stacking: 'percent',
borderWidth: 1,
groupPadding: 0,//add here
pointPadding: 0//add here
},
bar: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b><br>{point.percentage:.1f} %',
color: 'white'
}
}
},
series: [{
name: 'TVET',
data: [5, 3, 4, 7, 2, 4, 7, 2]
}, {
name: 'IGGs',
data: [2, 2, 3, 2, 1, 4, 7, 2]
}, {
name: 'CIF',
data: [3, 4, 4, 2, 5, 4, 7, 2]
}]
});
}
});
});
在“警报”中,它正确显示了地区的名称,但在它们的开头有一个额外的关键字“未定义”,在控制台面板中也显示以下错误:未捕获的类型错误:无法读取属性“部分/全局” .js' of undefined.我想从数据库中动态显示类别的名称。
【问题讨论】:
标签: javascript c# jquery