当前位置 博文首页 > u012442504的专栏:ECharts+get.done来绘制图表,亲测有效,网上

    u012442504的专栏:ECharts+get.done来绘制图表,亲测有效,网上

    作者:[db:作者] 时间:2021-09-23 10:41

    一、按照官网的引入相关js

    官网教程引入

    二、给个容器

    <!-- 为 ECharts 准备一个具备大小(宽高)的 DOM -->
        <div id="main" style="width: 600px;height:400px;"></div>

    三、绘制空图表(很重要,否则报错)

    option = {
        color: ['#3398DB'],
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                data : ['今天', '昨天', '本周', '上周', '本月', '上月', '今年','去年'],
                axisTick: {
                    alignWithLabel: true
                }
            }
        ],
        yAxis : [
            {
                type : 'value'
            }
        ],
        series : [
            {
                name:'接单数量',
                type:'bar',
                barWidth: '60%',
                color: ['#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C','#ff9f7f', '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'],
                data:[]
            }
        ]
    };

    四、请求数据

     $.get('http://自己的请求地址').done(function (data) {
                    // console.log(data);
                    var arr = data.num.split(","); 
                        myChart.hideLoading();
                        myChart.setOption({
                            
        series : [
            {            
                data:arr
            }
        ]
    });
                });

    五、请求数据展示

    //使用thinkphp返回的json数据,直接渲染,简单实用
    {"num":"0,7,7,0,7,0,7,0"}
    //重要的是按照符号进行分割数据就可以了,很简单

    六、完成

    cs