echarts使用结合时间轴timeline动态刷新案例

使用案例

第一步:echarts初始化

第二步:定义option,

第三步:echarts加载option

echarts初始化:

var right_bottom_chart = echarts.init(document.getElementById("right_bottom"));

定义option

var getLBOptionConfig = function(data_res, monthArr , index){
            
            var data_arr = getDataArr(data_res);
                
            
            right_bottom_option = {
                    baseOption:{
                        timeline:{
                            axisType :'category',
                            orient:'vertical',
                            autoPlay :true,
                            playInterval :15000,
                            right: '5',
                            left:'320',
                            top:'0',
                            bottom:'0',
                            label:{
                                interval:0,
                                 formatter: function (item) {
                                        var str = item.split("-")[1];
                                        return parseInt(str)+'月';
                                    }
                            },
                            data:monthArr,
                            currentIndex : index,
                            controlStyle:{
                                showPlayBtn :false
                            }
                        }    
                        
                    },
                         
                    options:[
                          {
                title: {
                    text: '租赁人口',
                    textStyle:{
                        color:'#fff'
                    }
                },
                textStyle:{
                    color:'#B3E4A1'
                },
                grid: {
                },
                angleAxis: {
                    type: 'category',
                    data: cities,
                    axisLabel:{
                        show:true,
                        interval : 0
                    }
                },
                radiusAxis: {
                    
                },
                polar: {
                    
                    
                },
                tooltip: {
                    show: true,
                    formatter: function (params) {
                        var id = params.dataIndex;
                        return cities[id] + '<br>最低:' + data_arr[id][0] + '<br>最高:' + data_arr[id][1] + '<br>平均:' + data_arr[id][2];
                    }
                },
                series: [{
                    type: 'bar',
                    itemStyle: {
                        normal: {
                            color: 'transparent'
                        }
                    },
                    data: data_arr.map(function (d) {
                        return d[0];
                    }),
                    coordinateSystem: 'polar',
                    stack: '最大最小值',
                    silent: true
                }, {
                    type: 'bar',
                    data: data_arr.map(function (d) {
                        return d[1] - d[0];
                    }),
                    coordinateSystem: 'polar',
                    name: '价格范围',
                    stack: '最大最小值'
                }, {
                    type: 'bar',
                    itemStyle: {
                         normal: {
                             color: 'transparent',/*设置bar为隐藏,撑起下面横线*/
                         }
                    },
                   
                    data: data_arr.map(function (d) {
                        return d[2];
                    }),
                    coordinateSystem: 'polar',
                    stack: '均值',
                    silent: true,
                    barGap: '-100%',
                    z: 10
                }, {
                    type: 'bar',
                    itemStyle: {
                         normal: {
                             color: 'green',/*设置bar为隐藏,撑起下面横线*/
                         }
                    },
                    data: data_arr.map(function (d) {
                        return 8;
                    }),
                    coordinateSystem: 'polar',
                    name: '均值',
                    stack: '均值',
                    barGap: '-100%',
                    z: 10
                }]
            }]
            }
            
            right_bottom_option.options=[];
            monthArr.forEach(function(n){
                right_bottom_option.options.push(getTemplate(data_arr));
            });
            
            
        return right_bottom_option;
        };

echarts加载option:

 right_bottom_chart.setOption(LBoption,true);

时间轴代码片:

timeline:{
                            axisType :'category',
                            orient:'vertical',
                            autoPlay :true,
                            playInterval :15000,
                            right: '5',
                            left:'320',
                            top:'0',
                            bottom:'0',
                            label:{
                                interval:0,
                                 formatter: function (item) {
                                        var str = item.split("-")[1];
                                        return parseInt(str)+'月';
                                    }
                            },
                            data:monthArr,
                            currentIndex : index,
                            controlStyle:{
                                showPlayBtn :false
                            }
                        }    

 

时间轴时间监听:

right_bottom_chart.on('timelinechanged', function (timeLineIndex) {
  var month_str = monthArr[timeLineIndex.currentIndex];
  if(month_str){
    loadRightBottomCON(right_bottom_chart, month_str, timeLineIndex.currentIndex);
  }
});

抽取模板

var getTemplate = function(data_arr){
            
            
            return  {
                title: {
                    text: '租赁人口',
                    textStyle:{
                        color:'#fff'
                    }
                },
                textStyle:{
                    color:'#B3E4A1'
                },
                grid: {
                },
                angleAxis: {
                    type: 'category',
                    data: cities,
                    axisLabel:{
                        show:true,
                        interval : 0
                    }
                },
                radiusAxis: {
                    
                },
                polar: {
                    
                    
                },
                tooltip: {
                    show: true,
                    formatter: function (params) {
                        var id = params.dataIndex;
                        return cities[id] + '<br>最低:' + data_arr[id][0] + '<br>最高:' + data_arr[id][1] + '<br>平均:' + data_arr[id][2];
                    }
                },
                series: [{
                    type: 'bar',
                    itemStyle: {
                        normal: {
                            color: 'transparent'
                        }
                    },
                    data: data_arr.map(function (d) {
                        return d[0];
                    }),
                    coordinateSystem: 'polar',
                    stack: '最大最小值',
                    silent: true
                }, {
                    type: 'bar',
                    data: data_arr.map(function (d) {
                        return d[1] - d[0];
                    }),
                    coordinateSystem: 'polar',
                    name: '价格范围',
                    stack: '最大最小值'
                }, {
                    type: 'bar',
                    itemStyle: {
                         normal: {
                             color: 'transparent',/*设置bar为隐藏,撑起下面横线*/
                         }
                    },
                   
                    data: data_arr.map(function (d) {
                        return d[2];
                    }),
                    coordinateSystem: 'polar',
                    stack: '均值',
                    silent: true,
                    barGap: '-100%',
                    z: 10
                }, {
                    type: 'bar',
                    itemStyle: {
                         normal: {
                             color: 'green',/*设置bar为隐藏,撑起下面横线*/
                         }
                    },
                    data: data_arr.map(function (d) {
                        return 8;
                    }),
                    coordinateSystem: 'polar',
                    name: '均值',
                    stack: '均值',
                    barGap: '-100%',
                    z: 10
                }]
            };
        }

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ECharts中的Map和Timeline可以结合使用来展示地理位置随时间变化的情况。具体实现步骤如下: 1. 首先需要准备好地图数据和时间序列数据,可以参考ECharts官网提供的示例或者自己准备数据; 2. 在ECharts使用map组件添加地图,并通过series中的data属性将地图数据传入; 3. 使用timeline组件添加时间轴,并通过options属性设置每个时间点对应的option,其中option中的series中的data属性应该根据当前时间点来动态设置,以展示对应时间点的数据; 4. 在option中设置visualMap组件,用于展示数据的颜色变化,可以根据实际需求自定义颜色范围等属性。 下面是一个简单的示例代码: ```javascript option = { baseOption: { timeline: { data: ['2010', '2011', '2012', '2013', '2014', '2015'], autoPlay: true, playInterval: 1000 }, visualMap: { min: 0, max: 1000, text: ['High', 'Low'], orient: 'horizontal', left: 'center', bottom: 10 }, series: [{ type: 'map', map: 'world', data: [{name: 'China', value: 500}, {name: 'USA', value: 300}, {name: 'Japan', value: 200}] }] }, options: [{ series: [{ data: [{name: 'China', value: 600}, {name: 'USA', value: 200}, {name: 'Japan', value: 100}] }] }, { series: [{ data: [{name: 'China', value: 700}, {name: 'USA', value: 400}, {name: 'Japan', value: 300}] }] }, { series: [{ data: [{name: 'China', value: 800}, {name: 'USA', value: 500}, {name: 'Japan', value: 400}] }] }, { series: [{ data: [{name: 'China', value: 900}, {name: 'USA', value: 600}, {name: 'Japan', value: 500}] }] }, { series: [{ data: [{name: 'China', value: 1000}, {name: 'USA', value: 700}, {name: 'Japan', value: 600}] }] }, { series: [{ data: [{name: 'China', value: 900}, {name: 'USA', value: 600}, {name: 'Japan', value: 500}] }] }] }; ``` 在这个示例中,我们使用了世界地图,并设置了6个时间点的数据,每个时间点的数据都会通过timeline组件来展示。同时,我们还设置了visualMap来展示数据的颜色变化,使得数据更加直观。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值