我尝试在这里使用chart.js,但是当我输入json数据时,它没有显示出来,我尝试在数据之间添加空间,但仍然无法正常工作,我使用php制作了json数据
我已经尝试使用ch31 = ch3.join(', ');
来腾出空间,但仍然无法正常工作
var ch31;
$(document).ready(function () {
$.ajax({
url:"php/chart3.php",
method:"POST",
dataType:"json",
success:function(data){ //---
var ch3 = [];
for(var i in data) {
ch3.push(data[i]);
}
ch31 = ch3.join(', ');
console.log(ch31);
}
});
});
$(function() {
var ctx, data, myBarChart, option_bars;
Chart.defaults.global.responsive = true;
ctx = $('#radar-chart').get(0).getContext('2d');
option_bars = {
scaleBeginAtZero: true,
scaleShowGridLines: true,
scaleGridLineColor: "rgba(0,0,0,.05)",
scaleGridLineWidth: 1,
scaleShowHorizontalLines: true,
scaleShowVerticalLines: false,
barShowStroke: false,
barStrokeWidth: 0,
barValueSpacing: 5,
barDatasetSpacing: 1
};
data = {
labels: ['Troubleshooting', 'Installation', 'Maintenance', 'Site Visit', 'Survey', 'Comissioning', 'Auditing' , 'Facility'],
datasets: [
{
label: "Kategori Pekerjaan",
fillColor: "rgba(26, 188, 156,0.2)",
strokeColor: "#1ABC9C",
pointColor: "#1ABC9C",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
data: [ch31],
},
]
};
myBarChart = new Chart(ctx).Radar(data, option_bars);
});
除了显示图表外,但仍然无法正常工作