Javascript 向Chart.js折线图添加标题
我试图在渲染后使用fillText在chart.js画布上绘制,但它无法工作。我所能做的就是改变图表的字体。这是我的密码Javascript 向Chart.js折线图添加标题,javascript,jquery,html,canvas,chart.js,Javascript,Jquery,Html,Canvas,Chart.js,我试图在渲染后使用fillText在chart.js画布上绘制,但它无法工作。我所能做的就是改变图表的字体。这是我的密码 var options = { //Boolean - If we show the scale above the chart data scaleOverlay: false, //Boolean - If we want to override with a hard coded scale scaleOverr
var options = {
//Boolean - If we show the scale above the chart data
scaleOverlay: false,
//Boolean - If we want to override with a hard coded scale
scaleOverride: false,
//** Required if scaleOverride is true **
//Number - The number of steps in a hard coded scale
scaleSteps: null,
//Number - The value jump in the hard coded scale
scaleStepWidth: null,
//Number - The scale starting value
scaleStartValue: null,
//String - Colour of the scale line
scaleLineColor: "rgba(0,0,0,.1)",
//Number - Pixel width of the scale line
scaleLineWidth: 1,
//Boolean - Whether to show labels on the scale
scaleShowLabels: true,
//Interpolated JS string - can access value
scaleLabel: "<%=value%>",
//String - Scale label font declaration for the scale label
scaleFontFamily: "'Arial'",
//Number - Scale label font size in pixels
scaleFontSize: 12,
//String - Scale label font weight style
scaleFontStyle: "normal",
//String - Scale label font colour
scaleFontColor: "#666",
///Boolean - Whether grid lines are shown across the chart
scaleShowGridLines: true,
//String - Colour of the grid lines
scaleGridLineColor: "rgba(0,0,0,.05)",
//Number - Width of the grid lines
scaleGridLineWidth: 1,
//Boolean - Whether the line is curved between points
bezierCurve: true,
//Boolean - Whether to show a dot for each point
pointDot: true,
//Number - Radius of each point dot in pixels
pointDotRadius: 3,
//Number - Pixel width of point dot stroke
pointDotStrokeWidth: 1,
//Boolean - Whether to show a stroke for datasets
datasetStroke: true,
//Number - Pixel width of dataset stroke
datasetStrokeWidth: 2,
//Boolean - Whether to fill the dataset with a colour
datasetFill: true,
//Boolean - Whether to animate the chart
animation: false,
//Number - Number of animation steps
animationSteps: 60,
//String - Animation easing effect
animationEasing: "easeOutQuart",
//Function - Fires when the animation is complete
onAnimationComplete: null
}
这是通过JSON数据完成的,在调用之后,我有:
$("canvas").each(function (i, item) {
var context = $(this).get(0).getContext("2d");
context.textBaseline = 'top';
context.fillText('Test', 0, 0);
});
图形只是正常加载,没有任何文本。如果使用context.font,则每个画布上的所有标签都会更改。我已关闭加载动画。有什么想法吗?我只是在元素周围添加了一个标签,而不是在画布上绘制
<label for = "idOfCanvas">
Your Label<br />
<canvas></canvas>
</label>
您的标签
在选项中添加此参数
multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>"
MultiToolTemplate:“-”
是的,我就是这么做的。我真的很喜欢能够将图表转换成图像并保存它们。唯一的问题是当我这样做时没有标签,除非我在画布上绘制。@ToddSkelton我不认为不可能修改代码,让框架自动绘制标签。
multiTooltipTemplate: "<%= datasetLabel %> - <%= value %>"