我使用的是Chart.js甜甜圈图。图表看上去很好。然而,它缺少工具提示(就像我使用Chart.js制作的所有其他图表一样)。为什么要这样,我怎么才能让他们兴奋呢?在线文档声称我可以在Chart.defaults.global上访问全局默认设置(其中工具提示可以被设置为on/off,尽管该站点声称它们默认为on),因为Chart.defaults甚至不存在,所以对我不起作用。我试图访问这些默认设置,以便打开工具提示。谢谢你能提供的任何帮助。
var context = document.getElementById("scoreChart").getContext("2d");
var chartData = [
{
label: "Number correct",
value: $scope.numRight,
color: "rgb(134, 202,54)",
highlight: "rgb(100,100,100)"
//not sure what highlight does
},
{
label: "Number wrong",
value: $scope.myTest.testQuestions.length - $scope.numRight,
color: '#7c0b10',
highlight: 'rgb(10,10,10)'
}
];
var theChart = new Chart(context);
var theDough = theChart.Doughnut(chartData/*, chartOptions*/);
console.log("Here is the chart object:");
console.log(theChart);
console.log("Chart.Doughnut object:");
console.log(theChart.Doughnut);
console.log("Chart.Doughnut.defaults:");
console.log(theChart.Doughnut.defaults); // <-- This works
console.log("theChart.defaults:");
console.log(theChart.defaults); // <--This is undefined
console.log("Chart.defaults.global:");
console.log(Chart.defaults.global); // throws an error
// because Chart.defaults is undefined更新:修好了。Chart.js的第一个版本是非常古老的。见下面的答案。
发布于 2014-12-13 05:08:48
我使用Bower下载了Chart.js。在Bower上列出的Chart.js版本是旧的。这就是为什么文件是错误的。我不得不剪切和粘贴最新的Chart.js从吉特布到我的项目。瞧,工具提示和对象的行为就像文档所说的那样。或者,正如JAAulde所指出的那样,也更简单,您可以将您的第一个依赖项设置为指向:
"chartjs": "master"这应该会自动拉出正确的副本。
发布于 2014-12-13 04:50:28
theChart和theDough应该一次性设置,而不是作为单独的对象设置。例如:
var theChart = new Chart(ctx).Doughnut(data);
如果仍然无法获得工具提示,请传入并修改以下选项:
var theChart = new Chart(ctx).Doughnut(data, {
// Boolean - Determines whether to draw tooltips on the canvas or not
showTooltips: true,
});有关工具提示样式的进一步变化,请参阅本页中的全局图表选项文档:http://www.chartjs.org/docs/#getting-started-global-chart-configuration。
https://stackoverflow.com/questions/27455604
复制相似问题