echarts icon indicating copy to clipboard operation
echarts copied to clipboard

关于百度股票K线图的一些疑问

Open LkpCzt opened this issue 9 years ago • 4 comments

我想知道像百度股票这样的图例,自动显示鼠标指向的数据是通过 tooltip实现的吗?如果不是,那怎么实现比较好,以及y轴指示线怎么自动依附到value上的?

ce5b1156-620d-4b88-aea9-99b450d02b92

Version & Environment [版本及环境]

  • ECharts version 3.8.4:
  • Browser version chrome:
  • OS Version macOS:

LkpCzt avatar Nov 15 '17 03:11 LkpCzt

确实是通过tooltip来设置的,可以利用它来进行自定义样式, y轴的自动依附还没找到方法,如果找到了可以分享一下。(我也在学习中。。。逃)

git-stf-01 avatar Nov 15 '17 09:11 git-stf-01

@git-stf-01 我查看了百度的代码,上边我划线的部分他们是直接用canvas绘制出来的,下面的那个弹框倒是可以用 echarts 的tooltip来实现,百度的股票图没有使用这个框架,直接使用js绘制出来的,分享下百度的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)
},

LkpCzt avatar Nov 16 '17 03:11 LkpCzt

嗯,确实是这样的,百度没用Echart画股票图。

如果用echart,鼠标触发的tooltip的样式可以利用tooltip的formatter属性的formatter函数来进行自定义。包括一些数据,该函数的参数也会提供。 不过目前还没解决的问题就是: 平行于x轴的那条指示线了,tooltip的axispointer属性设置为cross后,指示线只能根据鼠标走,不能依附数据。。。

git-stf-01 avatar Nov 16 '17 03:11 git-stf-01

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 02 '20 11:04 stale[bot]