vchart 坐标轴标题_如何设置ChartJS y轴标题

I am using Chartjs for showing diagrams and I need to set title of y axis, but there are no information about it in documentation.

I need y axis to be set like on picture, or on top of y axis so someone could now what is that parameter

I have looked on official website but there was no information about it

解决方案

You can tweak the options and extend the chart type to do this, like so

Chart.types.Line.extend({

name: "LineAlt",

draw: function () {

Chart.types.Line.prototype.draw.apply(this, arguments);

var ctx = this.chart.ctx;

ctx.save();

// text alignment and color

ctx.textAlign = "center";

ctx.textBaseline = "bottom";

ctx.fillStyle = this.options.scaleFontColor;

// position

var x = this.scale.xScalePaddingLeft * 0.4;

var y = this.chart.height / 2;

// change origin

ctx.translate(x, y)

// rotate text

ctx.rotate(-90 * Math.PI / 180);

ctx.fillText(this.datasets[0].label, 0, 0);

ctx.restore();

}

});

calling it like this

var ctx = document.getElementById("myChart").getContext("2d");

var myLineChart = new Chart(ctx).LineAlt(data, {

// make enough space on the right side of the graph

scaleLabel: " "

});

Notice the space preceding the label value, this gives us space to write the y axis label without messing around with too much of Chart.js internals

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值