柱状图

柱状图

$def with(sales_data,source_data,source_title,source_stat_data)
// domechartsvar chart_1 = echarts.init(document.getElementById("sales_wrap"));
var sales_data  = $:sales_data;
var option_1 = {
    title:{
        text:"XX",
        subtext:""
    },
    xAxis:{
        type:"category",
        data:sales_data['category']
    },
    yAxis:{},
    series:[
        {
            "name":"",
            type:"bar",
            data:sales_data['data'],
             markPoint:{
            data:[
                {type:"max",name:""},
                {type:"min",name:""}
            ]
        },
        markLine:{
            data:[
               {type:"average",name:""}
            ]
        }
        }
    ],
    tooltip:{
        trigger:"axis"
    },
    toolbox:{
       show:true,
       feature:{
            dataView:{},
            restore:{},
            saveAsImage:{},
            magicType:{type:['line','bar']},
            dataZoom:{}
       }
    }
};
  chart_1.setOption(option_1);

var chart_2 = echarts.init(document.getElementById("source_wrap"))
var source_data = $:source_data;
var source_title = $:source_title;
var source_stat_data = $:source_stat_data;
var option_2 = {
    tooltip:{
        trigger:'item',
        formatter:'{a}<br/>{b}:{c}({d}%)'
    },#PPTlegend:{
        orient:'vertical',//left:10,//10
        data:source_title
    },//series:[
        {
        name:"",
        type:"pie",
        radius:[ '40%','55%'],//data:source_data
        },
        {
            name:"",
            type:"pie",
            radius:[0,'30%'],
            data:source_stat_data,
            label:{
                position:'inner'
            },//selectedMode:'single'//}
    ]
};
chart_2.setOption(option_2);


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕美 2022-04-27 09:40:04

同学,你好!运行同学的代码是可以显示柱状图的,同学运行是报错吗?可以具体描述下问题,并将报错信息提供下

https://img1.sycdn.imooc.com//climg/62689ef109c5c72813620365.jpg

祝学习愉快!

  • 提问者 weixin_慕仙9081395 #1

    饼图失败

    $def with(sales_data,source_data,source_title,source_stat_data)
    // domechartsvar chart_1 = echarts.init(document.getElementById("sales_wrap"));
    var sales_data  = $:sales_data;
    var option_1 = {
        title:{
            text:"XX",
            subtext:""
        },
        xAxis:{
            type:"category",
            data:sales_data['category']
        },
        yAxis:{},
        series:[
            {
                "name":"",
                type:"bar",
                data:sales_data['data'],
                 markPoint:{
                data:[
                    {type:"max",name:""},
                    {type:"min",name:""}
                ]
            },
            markLine:{
                data:[
                   {type:"average",name:""}
                ]
            }
            }
        ],
        tooltip:{
            trigger:"axis"
        },
        toolbox:{
           show:true,
           feature:{
                dataView:{},
                restore:{},
                saveAsImage:{},
                magicType:{type:['line','bar']},
                dataZoom:{}
           }
        }
    };
      chart_1.setOption(option_1);
    
    var chart_2 = echarts.init(document.getElementById("source_wrap"))
    var source_data = $:source_data;
    var source_title = $:source_title;
    var source_stat_data = $:source_stat_data;
    var option_2 = {
        tooltip:{
            trigger:'item',
            formatter:'{a} <br/>{b}: {c} ({d}%)'
        },#PPTlegend:{
            orient:'vertical',//left:10,//10
            data:source_title
        },//series:[
            {
            name:"",
            type:"pie",
            radius:[ '40%','55%'],//data:source_data
            },
            {
                name:"",
                type:"pie",
                radius:[0,'30%'],
                data:source_stat_data,
                label:{
                    formatter:'{a|{a}}\n{hr|}\n {b|{b}: }{c} {per{d}%}' ,
                    borderColor:'#aaa',
                    borderWidth:1,
                    borderRadius:4,
                    backgroundColor:'#eee',
                    #……
                    rich:{
                        a:{
                            color:'#999',
                            lineHeight:22,
                            align:'center'
                        },#{a|  }ahr:{
                          borderColor:'#aaa',
                          width:'100%',
                          borderWidth:0.5height:0
                        },#hrb:{
                            fontSize:16,
                            lineHeight:33
                        },#hrper:{
                            color:'#eee',
                            background:'#334455',
                            padding:[2,4],#borderRadius:3#}
                    }
                },
                label:{
                    position:'inner'
                },//selectedMode:'single'//}
        ]
    };
    chart_2.setOption(option_2);
    2022-04-27 10:22:30
  • 同学,你好!

    1、设置label样式相关的代码应放在第一个字典中

    https://img1.sycdn.imooc.com//climg/6268ac98095b377610520717.jpg

    2、同学代码中有很多不需要的字母符号,可以删除掉或注释掉

    https://img1.sycdn.imooc.com//climg/6268acad093add2605990219.jpg

    https://img1.sycdn.imooc.com//climg/6268acbc09bffa2204120366.jpg

    https://img1.sycdn.imooc.com//climg/6268acd4092ab7d904080505.jpg

    正确代码如下:

    var chart_2 = echarts.init(document.getElementById("source_wrap"))
    var source_data = $:source_data;
    var source_title = $:source_title;
    var source_stat_data = $:source_stat_data;
    var option_2 = {
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b}: {c} ({d}%)'
            },
            // #PPT
            legend: {
                orient: 'vertical',//
                left: 10,//10
                data: source_title
            },//
            series: [
                {
                    name: "",
                    type: "pie",
                    radius: ['40%', '55%'],//
                    data: source_data,
                    label: {
                        formatter: '{a|{a}}\n{hr|}\n {b|{b}: }{c} {per{d}%}',
                        borderColor: '#aaa',
                        borderWidth: 1,
                        borderRadius: 4,
                        backgroundColor: '#eee',
                        // #……
                        rich: {
                            a: {
                                color: '#999',
                                lineHeight: 22,
                                align: 'center'
                            },
                            // ,#{a|}a
                            hr: {
                                borderColor: '#aaa',
                                width: '100%',
                                borderWidth: 0.5,
                                height: 0
                            },
                            // #hr
                            b: {
                                fontSize: 16,
                                lineHeight: 33
                            },
                            // #hr
                            per: {
                                color: '#eee',
                                background: '#334455',
                                padding: [2, 4],
                                // #
                                borderRadius: 3
                                // #
                            }
                        }
                    },
                },
                {
                    name: "",
                    type: "pie",
                    radius: [0, '30%'],
                    data: source_stat_data,
                    label: {
                        position: 'inner'
                    },//
                    selectedMode:'single'//
                }
            ]
        };
    chart_2.setOption(option_2);

    祝学习愉快!

    2022-04-27 10:40:23
  • 还是不行?

    $def with(sales_data,source_data,source_title,source_stat_data)
    // domechartsvar chart_1 = echarts.init(document.getElementById("sales_wrap"));
    var sales_data  = $:sales_data;
    var option_1 = {
        title:{
            text:"XX",
            subtext:""
        },
        xAxis:{
            type:"category",
            data:sales_data['category']
        },
        yAxis:{},
        series:[
            {
                "name":"",
                type:"bar",
                data:sales_data['data'],
                 markPoint:{
                data:[
                    {type:"max",name:""},
                    {type:"min",name:""}
                ]
            },
            markLine:{
                data:[
                   {type:"average",name:""}
                ]
            }
            }
        ],
        tooltip:{
            trigger:"axis"
        },
        toolbox:{
           show:true,
           feature:{
                dataView:{},
                restore:{},
                saveAsImage:{},
                magicType:{type:['line','bar']},
                dataZoom:{}
           }
        }
    };
      chart_1.setOption(option_1);
    
    var chart_2 = echarts.init(document.getElementById("source_wrap"))
    var source_data = $:source_data;
    var source_title = $:source_title;
    var source_stat_data = $:source_stat_data;
    var option_2 = {
        tooltip:{
            trigger:'item',
            formatter:'{a} <br/>{b}: {c} ({d}%)'
        },//PPTlegend:{
            orient:'vertical',//left:10,//10
            data:source_title
        },//series:[
            {
            name:"",
            type:"pie",
            radius:[ '40%','55%'],//data:source_data,
             label:{
                    formatter:'{a|{a}}\n{hr|}\n {b|{b}: }{c} {per{d}%}' ,
                    borderColor:'#aaa',
                    borderWidth:1,
                    borderRadius:4,
                    backgroundColor:'#eee',
                    //……
                    rich:{
                        a:{
                            color:'#999',
                            lineHeight:22,
                            align:'center'
                        },//{a|  }ahr:{
                          borderColor:'#aaa',
                          width:'100%',
                          borderWidth:0.5height:0
                        },//hrb:{
                            fontSize:16,
                            lineHeight:33
                        },//hrper:{
                            color:'#eee',
                            background:'#334455',
                            padding:[2,4],//borderRadius:3 //}
                    }
              
    
            },
            {
                name:"",
                type:"pie",
                radius:[0,'30%'],
                data:source_stat_data,
    
                label:{
                    position:'inner'
                },//selectedMode:'single'//}
        ]
    };
    chart_2.setOption(option_2);


    2022-04-27 21:17:06
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师