我的应用程序正在从作业列表网站抓取软件开发人员列表,并将数据打印为json。我已经将chart.js实现到我的仪表板页面。我问的是如何在图表顶部修复细线并将小数字更改为图表上的整数? (我不是以十进制形式发送数据)
Json文件:
{"25-03-2018": 224,"28-03-2018": 227,"29-03-2018": 227}
Javascript代码:
fetch();
function fetch(){
var lang = "C#";
var langData = {};
var days = [];
var jsonUrl = 'https://example.com/'+lang+'.json?nocache=' + moment().format('HHmmss');
$.getJSON(jsonUrl, function(data) {
//passing json datas to array
$.each(data, function(index, value) {
if ( (index !== null || index !== '') && (value !== null || value !== '')){
langData[index] = parseInt(value);
}
});
//Convert time from DD MM YYYY(coming from json) to YYYY MM DD
// Format with moment.js after that
for(var i = 0 ; i<Object.keys(langData).length;i++) {
var dayPart = Object.keys(langData)[i].split('-');
days.push(moment(dayPart[2]+"-"+(dayPart[1])+"-"+dayPart[0]).format("DD MMMM YYYY"));
}
chart.data.labels = days;
chart.data.datasets[0].data = Object.values(langData);
chart.update();
});
};
var chart = new Chart(document.getElementById("canvas"), {
type: 'line',
data: {
datasets: [
{
label: "Jobs",
borderColor: '#fe8b36',
backgroundColor: '#fe8b36',
lineTension: 0.3,
fill: false
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
}
});
这是我的问题: