求教一个echarts 仪表盘的问题

聆听灬莫问 2015-08-18 07:54:15
我想给仪表盘max属性赋一个动态的值,以下是我代码,我首先初始化了一个仪表盘,然后给max一个默认值
  option = {
tooltip: {
formatter: "{a}:{c}"
},
toolbox: {
show: false
},

pointer: {
length: '10%',
width: 4,
color: 'auto'
},
series: [
{
name: '当前线程数',
type: 'gauge',
startAngle: 180,
endAngle: 0,
splitNumber: 5,
max:100,
detail: {
formatter: '{value}',
offsetCenter: [0, '10%'],
textStyle: {
color: 'auto',
fontSize: 20
}
},
data: [{ value: 0 }]
}
]
};
当我不给max 赋值的时候仪表盘是正常工作的,当我给max附一个值的时候,仪表盘的指针就会指向max值,这个错误是怎么回事啊?
     option.series[0].max = data.maxThread;
option.series[0].data[0].value = data.count;
...全文
1199 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
编程微刊 2018-10-12
  • 打赏
  • 举报
回复
https://www.jianshu.com/p/457423365dd3
聆听灬莫问 2015-08-19
  • 打赏
  • 举报
回复
引用 1 楼 cheery_an 的回复:
没有问题啊

option = {
        tooltip: {
            formatter: "{a}:{c}"
        },
        toolbox: {
            show: false
        },


 
        pointer: {
            length: '10%',
            width: 4,
            color: 'auto'
        },
        series: [
            {
                name: '当前线程数',
                type: 'gauge',
                startAngle: 180,
                endAngle: 0,
                splitNumber: 5,
                max:100,
                detail: {
                    formatter: '{value}',
                    offsetCenter: [0, '10%'],
                    textStyle: {
                        color: 'auto',
                        fontSize: 20
                    }
                },
                data: [{ value: 0 }]
            }
        ]
    };

clearInterval(timeTicket);
timeTicket = setInterval(function (){
    var vmax = (Math.random()*100).toFixed(2) - 0;
    var curv = vmax - 10 >0?vmax-10:0;
 	option.series[0].max =  vmax;
    option.series[0].data[0].value =curv;
    myChart.setOption(option,true);
},2000)
                    
拷贝到http://echarts.baidu.com/doc/example/gauge2.html 里面运行
我找到原因了,是因为赋值的类型是个string的,把它改为int 类型的就好了
cheery_an 2015-08-19
  • 打赏
  • 举报
回复
没有问题啊

option = {
        tooltip: {
            formatter: "{a}:{c}"
        },
        toolbox: {
            show: false
        },
 
        pointer: {
            length: '10%',
            width: 4,
            color: 'auto'
        },
        series: [
            {
                name: '当前线程数',
                type: 'gauge',
                startAngle: 180,
                endAngle: 0,
                splitNumber: 5,
                max:100,
                detail: {
                    formatter: '{value}',
                    offsetCenter: [0, '10%'],
                    textStyle: {
                        color: 'auto',
                        fontSize: 20
                    }
                },
                data: [{ value: 0 }]
            }
        ]
    };

clearInterval(timeTicket);
timeTicket = setInterval(function (){
    var vmax = (Math.random()*100).toFixed(2) - 0;
    var curv = vmax - 10 >0?vmax-10:0;
 	option.series[0].max =  vmax;
    option.series[0].data[0].value =curv;
    myChart.setOption(option,true);
},2000)
                    
拷贝到http://echarts.baidu.com/doc/example/gauge2.html 里面运行

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧