json代码如下
命名为city.json

{
    "list":[
        {
            "department":"杭州",
            "num":480
        },
        {
            "department":"上海",
            "num":380
        },
        {
            "department":"北京",
            "num":366
        },
{
            "department":"河南",
            "num":320
        },
{
            "department":"厦门",
            "num":300
        }

    ]
}

js代码

function tai(){
    var myChart = echarts.init(document.getElementById('chart'));    
    option = {
        title: {
            text: 'xxxx',
            x: '40', 
            textStyle:{
                color:'#4ba493',
                fontSize: 18,
                fontWeight: 'bold',
                align: 'center',            
            }
        },
        tooltip : {
            trigger: 'axis',
            axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
            }
        },//鼠标悬浮的效果
        grid:{
            top:40,
            x:50,
            y:45,
            bottom:40,
            borderWidth:4
              },//容器的距离
        xAxis: {
            type : 'value',
            position: 'top',
            show: false, 
        },
        yAxis: {
            type : 'category',
             axisLabel: {
                show: true,
                textStyle: {
                    color: '#fff'
                }
            },
//          axisLabel : { 
//                  formatter : '{b}%' 
//              }, 
//            
//          data : [ '杭州', '北京', '上海', '厦门', '成都']
            data : []
        },
        series: [
            {
                name: '实时在线台数',
                type: 'bar',
                itemStyle: {
                     emphasis: {
                        barBorderRadius: 5
                   },//设置圆角
            normal: {
//                  color: function(params) {
//                      // build a color map as your need.
//                      var colorList = ['#C1232B','#B5C334','#FCCE10','#E87C25','#27727B'];
//                              return colorList[params.dataIndex]
//                  },//设置柱状图的颜色

                   barBorderRadius: 5,//圆角
                   color: new echarts.graphic.LinearGradient(
                            0, 0, 1, 0,
                            [
                                {offset: 0, color: '#65d0de'},
                                {offset: 1, color: '#abd5da'}

                            ]
                        ),//设置柱状图渐变
                    label: {
                        show: true,
                        position: 'right',
                        formatter: '{c}',    //这是关键,在需要的地方加上就行了  
                        color: '#fff',  
                        }
                     }
                },
//              data: [120,210,100,40,120],
                data: [],
            }]
        };
            myChart.showLoading();    //数据加载完之前先显示一段简单的loading动画
            var namey = [];    //类别数组(实际用来盛放X轴坐标值)
            var numo = [];    //销量数组(实际用来盛放Y坐标值)
            console.log(namey)
            console.log(numo)
            $.ajax({
                type: 'get',
                url: 'json/city.json',//请求数据的地址
                dataType: "json",        //返回数据形式为json
                success: function (result) {
                    //请求成功时执行该函数内容,result即为服务器返回的json对象
                    $.each(result.list, function (index, item) {
                        namey.push(item.department);    //挨个取出类别并填入类别数组                    
                        numo.push(item.num);    //挨个取出销量并填入销量数组
                    });


                    myChart.hideLoading();    //隐藏加载动画
                    myChart.setOption({        //加载数据图表
                        yAxis: {
                            data: namey
                        },
                        series: [{
                            // 根据名字对应到相应的系列
                            data: numo
                        }]
                    });
                },
                error: function (errorMsg) {
                    //请求失败时执行该函数
                    alert("图表请求数据失败!");
                    myChart.hideLoading();
                }
            });

效果图如下
这里写图片描述

GitHub 加速计划 / js / json
53
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:17 天前 )
230bfd15 Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.6.0 to 4.7.0. - [Release notes](https://github.com/actions/dependency-review-action/releases) - [Commits](https://github.com/actions/dependency-review-action/compare/ce3cf9537a52e8119d91fd484ab5b8a807627bf8...38ecb5b593bf0eb19e335c03f97670f792489a8b) --- updated-dependencies: - dependency-name: actions/dependency-review-action dependency-version: 4.7.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 5 天前
e9391dc5 Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.0.1 to 4.02. - [Release notes](https://github.com/lukka/get-cmake/releases) - [Commits](https://github.com/lukka/get-cmake/compare/57c20a23a6cac5b90f31864439996e5b206df9dc...ea004816823209b8d1211e47b216185caee12cc5) --- updated-dependencies: - dependency-name: lukka/get-cmake dependency-version: '4.02' dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 7 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐