Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改变visualMap颜色不起作用 #8854

Closed
miniboxhaha opened this issue Aug 10, 2018 · 1 comment
Closed

改变visualMap颜色不起作用 #8854

miniboxhaha opened this issue Aug 10, 2018 · 1 comment

Comments

@miniboxhaha
Copy link

One-line summary [问题简述]

使用myChart.setOption(options, {notMerge:true})
改变visualMap->inRange->color时不起作用

Version & Environment [版本及环境]

  • ECharts version [ECharts 版本]:4.0.2
  • Browser version [浏览器类型和版本]:Chrome 67.0.3396.62
  • OS Version [操作系统类型和版本]:WIN7

Expected behaviour [期望结果]

ECharts option [ECharts配置项]

let options = this.myChart.getOption()
let keyName = 'keyName'
/////////////////////////可以正常更改Y轴颜色、标签
let newYAxis = options.yAxis.map((item, index) =>{
	if(item.name === keyName){
		return item
	}else{
		if(index > posInArr){
			item.nameTextStyle.color = [options.color[index - 1]]
			item.axisLabel.color = [options.color[index - 1]]
			item.axisLine.lineStyle.color = [options.color[index - 1]]
			item.offset = (index - 1)*(-15)
			item.position = (index -1) % 2 > 0 ? 'right' : 'left'
		}
		return item
	}
})

newYAxis.forEach((item, index) =>{
	if(item.name === keyName){
		newYAxis.splice(index,1)
	}
})

/////////////////////////不能正常更改线条及visualMap颜色
let newVisualMap = options.visualMap.map((item, index) =>{
	if(item.name === keyName){
		return item
	}else{
		if(index > posInArr){
			item.seriesIndex = item.seriesIndex -1
			item.inRange.color = [options.color[index - 1]]
		}
		return item
	}
})

newVisualMap.forEach((item, index) =>{
	if(item.id === keyName){
		newVisualMap.splice(index,1)
	}
})


options.visualMap = newVisualMap
myChart.setOption(options, {notMerge:true})

Other comments [其他信息]

截图

https://img-blog.csdn.net/20180810174024843?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2pveW1vZA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70

@miniboxhaha
Copy link
Author

解决了,方法是单独定义controller和target的inRange中color属性。

修改时也是同时修改controller和target的inRange中color属性。

//之前的定义
visualMap.push({
	id: keyName,
	show: false,
	realtime:false,
    seriesIndex:this.number,
    min: parseFloat(min),
    max: parseFloat(max),
    left: 'right',
    bottom: '45%',
    calculable: true,
    precision:1,
    inRange: {
         color: [options.color[this.number]]
    },
})

//修改后定义
visualMap.push({
    id: keyName,
    show: false,
    realtime:false,
    seriesIndex:this.number,
    min: parseFloat(min),
    max: parseFloat(max),
    left: 'right',
    bottom: '45%',
    calculable: true,
    precision:1,
    controller:{
    	inRange: {
            color: [options.color[this.number]]
        }
    },
    target:{
    	inRange: {
            color: [options.color[this.number]]
        }
    },
})

//修改时
let newVisualMap = options.visualMap.map((item, index) =>{
	if(item.name === keyName){
		return item
	}else{
		if(index > posInArr){
			item.seriesIndex = item.seriesIndex -1
			item.controller.inRange.color = [options.color[index - 1]]
			item.target.inRange.color = [options.color[index - 1]]
		}
		return item
	}
})

@Ovilia Ovilia closed this as completed Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants