使用Chart.js 2.0.我正在寻找一种在图表底部添加页脚(文本行)以显示数据源的方法.@H_404_2@
我尝试通过选项对象解决它,与包含和修改标题和图例的方式相同.像这样:@H_404_2@
@H_404_2@
`options: { ...
footer: {
display: true,text: 'data from xy'
}
}`
我在文档中提到了几次“页脚”以及在“工具提示”的上下文中使用它的方式或者使用它,但是没有看到任何具体如何添加它的内容.@H_404_2@
编辑/ UPDATE:
我找到了两个解决方法(但没有完美的解决方案)在尝试解决此问题时向图表添加页脚.如果有人像我一样遇到同样的问题,这里有一些建议如何解决这个问题.@H_404_2@
NR. 1:添加HTML元素.此解决方法的缺点是,如果用户将图表下载为.png,则不会显示添加的HTML元素.也许这是最好的解决方案,则不必显示该元素.@H_404_2@
@H_404_2@
`var myChart = new Chart(ctx,{
type: 'line',data: { ... },options: {
legend: { ... },...
legendCallback: function(){
return '
在画布上添加一个div来附加新的HTML元素
< div id = legendID>< / div>@H_404_2@
NR. 2:添加另一个空的数据集,但是包含应该显示的信息的标签. borderColor和backgroundColor设置为透明.添加一些空标签(“”)会在标签和添加的页脚之间留出一些距离.这种解决方法的缺点是造型的可能性有限.@H_404_2@
@H_404_2@
Labeling Axes@H_404_2@
When creating a chart,you want to tell the viewer what data they are viewing. To do this,you need to label the axis.@H_404_2@
The scale label configuration is nested under the scale configuration in the scaleLabel key. It defines options for the scale title. Note that this only applies to cartesian axes.@H_404_2@
您可以为两个轴添加标签,但在您的情况下,因为您只需要在x轴上,所以您的图表选项应该与此类似.@H_404_2@
@H_404_2@
var options = {
scales: {
xAxes: [
{
scaleLabel: {
display: true,labelString: 'Party size',fontColor: '#C7C7CC',fontSize: 11
}
}
]
}
};