我正在使用Chart.js的2.0(Alpha)版本,以及......
条形图的工具提示显示字符串“rgb(0,0,0)”而不是上面代码的标签值。您可以看到this.data.labels包含数字字符串。如果我将它们改为常规的整数,它们会在一个奇怪的效果之后显示正常,你会看到很多小数变化如此之快......
var ScoresFrequencyChartDrawer = function () {
this.data = {
labels: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
datasets: [{
backgroundColor: "rgba(150, 150, 150, 0.9)",
data: [1, 1, 2, 3, 7, 12, 15, 17, 23, 15, 10]
}]
};
this.options = {
events: ["mousemove"],
scales: {
xAxes: [{
display: true,
gridLines: {
drawOnChartArea: false
},
labels: {
fontSize: 15,
fontStyle: "bolder"
}
}],
yAxes: [{
display: false,
gridLines: {
drawOnChartArea: false
}
}]
}
};
this.chart = {};
}
ScoresFrequencyChartDrawer.prototype.draw = function() {
var canvas = document.getElementById("scores-frequency-chart");
var ctx = canvas.getContext("2d");
this.chart = new Chart(ctx, {
type: 'bar',
data: this.data,
options: this.options
});
}
github上的问题 - > https://github.com/nnnick/Chart.js/issues/1261
答案 0 :(得分:0)
我已经用上面的代码修复了它......
// Adding this to the this.data.labels initialization
labels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(eachToString),
// The eachToString function
function eachToString(el) {
return el.toString()+"%";
}
但是,就像它的错误一样,Github上的问题仍然存在。