zoukankan      html  css  js  c++  java
  • 百度echarts折线图使用示例

    引入echarts.js
    <script src="${js}/echarts.min.js"></script>
     
    定义一个容器存放echarts图表
    <div id="charts" style="100%;"></div>
    
     var myChart=echarts.init(document.getElementById("charts"));
        option = {
            title: {
                text: ''
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data:['今日','昨日','前日']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                //x轴间隔3个单位显示
                axisLabel :{
                    interval: 3
                },
                data: []
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name:'今日',
                    type:'line',
                    data:[]
                },
                {
                    name:'昨日',
                    type:'line',
                    data:[]
                },
                {
                    name:'前日',
                    type:'line',
                    data:[]
                }
            ]
        };
        myChart.setOption(option);
    
        function getCharts(type,tag_id) {
            var hoursList=[];
            var todays=[];
            var yesterdays=[];
            var beforeYesterdays=[];
            $.ajax({
                url:"/track/stat/ajax/getcharts",
                data:{"tag_id":tag_id,"type":type},
                success:function(data){
                    $.each(data.hoursList,function(n,value){
                        hoursList.push(value);
                    });
    
                    $.each(data.todays,function(n,value){
                        todays.push(value);
                    });
    
                    $.each(data.yesterdays,function(n,value){
                        yesterdays.push(value);
                    });
    
                    $.each(data.beforeYesterdays,function(n,value){
                        beforeYesterdays.push(value);
                    });
    
                    myChart.setOption({
                        title: {
                            text: ''
                        },
                        xAxis: {
                            data: hoursList
                        },
                        series: [
                            {
                                // 根据名字对应到相应的系列
                                name: '今日',
                                data: todays
                            },
                            {
                                name: '昨日',
                                data: yesterdays
                            },
                            {
                                name: '前日',
                                data: beforeYesterdays
                            }
                        ]
                    });
                }
            });
        };
    

      

    文末小福利免费视频资源网站www.sousuohou.com
  • 相关阅读:
    ruby计算平方和开方
    Silverlight中DataGrid翻页或者滚动时CheckBox/RadioButton显示的问题
    bat文件设置ip地址
    gcc编译多线程
    TCP Nagle算法
    fork父子进程 信号处理
    Unix守护进程的创建示例
    inline内联函数
    volatile类型
    ioctl获取接口名称、IP地址、MAC地址、广播地址等
  • 原文地址:https://www.cnblogs.com/vicF/p/8037940.html
Copyright © 2011-2022 走看看