1 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊
自問自答一波,查看了echarts 官方文檔,legend不能做到實(shí)時(shí)更新數(shù)據(jù)的功能,參看了百度股票的源代碼,他們直接實(shí)用的 canvas 來進(jìn)行繪制的,以下為百度 MA5 那一行的繪制代碼
drawCurMa: function(t, i, e) {
t = "MA5 " + (t ? t.toFixed(2) : "--"),
i = "MA10 " + (i ? i.toFixed(2) : "--"),
e = "MA20 " + (e ? e.toFixed(2) : "--");
var s = this.ctx.measureText(t).width,
h = this.ctx.measureText(i).width,
n = this.ctx.measureText(e).width,
a = this.axes[0][0] + 1,
o = this.axes[1][0] + 1,
l = 10,
c = s + 3 * l + 45 + h + n;
this.ctx.fillStyle = "rgba(255, 255, 255, 0.5)",
this.ctx.fillRect(a, o, c, 1.5 * this.conf.fontSize),
o += .75 * this.conf.fontSize,
this.ctx.textAlign = "left",
this.ctx.textBaseline = "middle",
a += l,
this.ctx.fillStyle = this.conf.ma5LineColor,
this.ctx.beginPath(),
this.ctx.arc(a + 5, o, 5, 0, 2 * Math.PI),
this.ctx.fill(),
a += 15,
this.ctx.fillText(t, a, o),
a += s + l,
this.ctx.beginPath(),
this.ctx.fillStyle = this.conf.ma10LineColor,
this.ctx.arc(a + 5, o, 5, 0, 2 * Math.PI),
a += 15, this.ctx.fill(),
this.ctx.fillText(i, a, o),
a += h + l,
this.ctx.beginPath(),
this.ctx.fillStyle = this.conf.ma20LineColor,
this.ctx.arc(a + 5, o, 5, 0, 2 * Math.PI),
a += 15,
this.ctx.fill(),
this.ctx.fillText(e, a, o)
},
添加回答
舉報(bào)