我想要在随机数为1的时候设置一条线的样式,在0的时候设置另一条线的样式,但最总效果不是这样,代码如下,请大神帮忙看看<template>
<div class="about">
<div id="tree" style="height:100vh"></div>
</div>
</template><script>
import echarts from 'echarts'
export default {
name: 'about',
mounted() {
let tree = echarts.init(document.getElementById('tree'));
let option = this.getOption(); setInterval(function() {
let aa = Math.floor(Math.random() * 2) console.log(aa); if (aa == 0) {
option.series[0].data[0].children[0].lineStyle = {
color: '#ff0000'
}
} else {
option.series[0].data[0].children[0].children[0].lineStyle = {
color: '#0000ff'
}
} tree.setOption(option)
}, 3000)
},
methods: {
getOption() {
let option = {
series: [{
type: 'tree',
left: '2%',
right: '2%',
top: '10%',
bottom: '10%',
animationDurationUpdate: 750,
orient: 'vertical', data: [{
name: '测试',
children: [{
name: '子',
children: [{
name: '测试最底层'
}, {
name: '子2', } ]
}]
}]
}]
} return option;
}
}, }
</script>
<div class="about">
<div id="tree" style="height:100vh"></div>
</div>
</template><script>
import echarts from 'echarts'
export default {
name: 'about',
mounted() {
let tree = echarts.init(document.getElementById('tree'));
let option = this.getOption(); setInterval(function() {
let aa = Math.floor(Math.random() * 2) console.log(aa); if (aa == 0) {
option.series[0].data[0].children[0].lineStyle = {
color: '#ff0000'
}
} else {
option.series[0].data[0].children[0].children[0].lineStyle = {
color: '#0000ff'
}
} tree.setOption(option)
}, 3000)
},
methods: {
getOption() {
let option = {
series: [{
type: 'tree',
left: '2%',
right: '2%',
top: '10%',
bottom: '10%',
animationDurationUpdate: 750,
orient: 'vertical', data: [{
name: '测试',
children: [{
name: '子',
children: [{
name: '测试最底层'
}, {
name: '子2', } ]
}]
}]
}]
} return option;
}
}, }
</script>
各版本对应的lineStyle属性是有差异的
V2 V4 color属性 是在series lineStyle下
V3 color属性 是在series lineSyle normal下
多谢你的答复,我的版本v4,是这样的,只要不是在定时器里,都会生效,但我的需求是想随机生成加颜色的线条
控制台有没报错提示信息什么的 会不会是定时器里面的option的问题
myChart.setOption(option,true,false);
option.series[0].data[0].children[0].name=option.series[0].data[0].children[0].name.substring(0,option.series[0].data[0].children[0].name.length-1);
myChart.setOption(option,true,false);
多谢你的答复,我的版本v4,是这样的,只要不是在定时器里,都会生效,但我的需求是想随机生成加颜色的线条
控制台有没报错提示信息什么的 会不会是定时器里面的option的问题没有报错,可能就是echarts不支持