Simple use of echarts chart (visualization) (recommended)

1. Create a new echarts.html file and prepare a node (Dom) with size (width and height) for ECharts.

<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
</head>
 
<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="height:400px"></div>
</body>

New <script>label introduces modular single file echarts.js

    <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
    

In the new <script>tab, configure the path of echarts and the required chart for the module loader (the relative path is the link from the current page to echarts.js). For importing chart files, see Importing ECharts2

    <!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <title>ECharts</title>
    </head>
    <body>
        <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
        <div id="main" style="height:400px"></div>
        <!-- ECharts单文件引入 -->
        <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
        <script type="text/javascript">
            // 路径配置
            require.config({
     
     
                paths: {
     
     
                    echarts: 'http://echarts.baidu.com/build/dist'
                }
            });
        </script>
    </body>

<script>Dynamic loading of echarts and required charts in the label, the callback function can initialize the chart and drive the generation of the chart, see API & Doc for options

    <!DOCTYPE html>
    <head>
        <meta charset="utf-8">
        <title>ECharts</title>
    </head>
    <body>
        <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
        <div id="main" style="height:400px"></div>
        <!-- ECharts单文件引入 -->
        <script src="http://echarts.baidu.com/build/dist/echarts.js"></script>
        <script type="text/javascript">
            // 路径配置
            require.config({
     
     
                paths: {
     
     
                    echarts: 'http://echarts.baidu.com/build/dist'
                }
            });
            
            // 使用
            require(
                [
                    'echarts',
                    'echarts/chart/bar' // 使用柱状图就加载bar模块,按需加载
                ],
                function (ec) {
     
     
                    // 基于准备好的dom,初始化echarts图表
                    var myChart = ec.init(document.getElementById('main')); 
                    
                    var option = {
     
     
                        tooltip: {
     
     
                            show: true
                        },
                        legend: {
     
     
                            data:['销量']
                        },
                        xAxis : [
                            {
     
     
                                type : 'category',
                                data : ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
                            }
                        ],
                        yAxis : [
                            {
     
     
                                type : 'value'
                            }
                        ],
                        series : [
                            {
     
     
                                "name":"销量",
                                "type":"bar",
                                "data":[5, 20, 40, 10, 10, 20]
                            }
                        ]
                    };
            
                    // 为echarts对象加载数据 
                    myChart.setOption(option); 
                }
            );
        </script>
    </body>

Run in the browser to see the effect!

Guess you like

Origin blog.csdn.net/weixin_49549509/article/details/108739983