Home  >  Article  >  Web Front-end  >  Detailed introduction to Echarts usage

Detailed introduction to Echarts usage

巴扎黑
巴扎黑Original
2017-08-12 16:12:323839browse

This article mainly introduces the basic usage of Echarts, and introduces the basic usage and examples of Echarts in detail. If you are interested, you can learn more

echarts is so perfect:

1, open source software, selflessly provides us with a beautiful graphical interface;

2, easy to use, silently encapsulates important js for us , as long as you can quote, you will use echarts;

3, there are many types, echarts provides us with various icons, the most symbolic of which is the map;

4. Good compatibility, excellent animation rendering based on html5.

echarts official website provides source code and documentation. To use echarts, you need to first go to the official website to download the required js source files.

The demo on the official website contains many things that we don’t need. If you want to use the pie chart, you have to remove the unused ones from the demo, leaving only the most original function implementation. . After all, this is more time-consuming, so I will summarize it in the cut code. So the new usage tutorial is as follows:

echarts pie chart implementation steps:

1, introduce js files into simple html


<head> 
  <meta charset="utf-8"> 
  <title>Charts demo</title> 
   <script src="js/esl.js"></script> 
</head> 
<body> 
</body>

2, prepare containers for graphics


<head> 
  <meta charset="utf-8"> 
  <title>Charts demo</title> 
   <script src="js/esl.js"></script> 
</head> 
<body> 
   
  <p id="picturePlace"></p> 
  
</body>

Just add a p with a given id in the html, and the chart will be displayed in p.

3, module import js


<head> 
  <meta charset="utf-8"> 
  <title>Charts demo</title> 
   <script src="js/esl.js"></script> 
</head> 
<body> 
  <p id="picturePlace"></p> 
   <script type="text/javascript"> 
    // 路径配置 
    require.config({ 
      paths:{  
        &#39;echarts&#39; : &#39;js/echarts&#39;, 
        &#39;echarts/chart/pie&#39; : &#39;js/echarts&#39; 
      } 
    }); 
  </script> 
</body>

4, add display data


<head> 
  <meta charset="utf-8"> 
  <title>Charts demo</title> 
   <script src="js/esl.js"></script> 
</head> 
<body> 
  <p id="picturePlace"></p> 
   <script type="text/javascript"> 
    // 路径配置 
    requireconfig({ 
      paths:{  
        &#39;echarts&#39; : &#39;js/echarts&#39;, 
        &#39;echarts/chart/pie&#39; : &#39;js/echarts&#39; 
      } 
    }); 
     
     // 使用 
    require( 
      [ 
        &#39;echarts&#39;, 
        &#39;echarts/chart/pie&#39; // 使用柱状图就加载bar模块,按需加载 
      ], 
      function (ec) { 
        // 基于准备好的dom,初始化echarts图表 
        var myChart = ec.init(document.getElementById(&#39;picturePlace&#39;));  
         
        option = { 
            title : { 
              text: &#39;某站点用户访问来源&#39;, 
              subtext: &#39;纯属虚构&#39;, 
              x:&#39;center&#39; 
            }, 
            tooltip : { 
              trigger: &#39;item&#39;, 
              formatter: "{a} {b} : {c} ({d}%)" 
            }, 
            legend: { 
              orient : &#39;vertical&#39;, 
              x : &#39;left&#39;, 
              data:[&#39;直接访问&#39;,&#39;邮件营销&#39;,&#39;联盟广告&#39;,&#39;视频广告&#39;,&#39;搜索引擎&#39;] 
            }, 
            toolbox: { 
              show : true, 
              feature : { 
                mark : {show: true}, 
                dataView : {show: true, readOnly: false}, 
                restore : {show: true}, 
                saveAsImage : {show: true} 
              } 
            }, 
            calculable : true, 
            series : [ 
              { 
                name:&#39;访问来源&#39;, 
                type:&#39;pie&#39;, 
                radius : &#39;55%&#39;, 
                center: [&#39;50%&#39;, &#39;60%&#39;], 
                data:[ 
                  {value:335, name:&#39;直接访问&#39;}, 
                  {value:310, name:&#39;邮件营销&#39;}, 
                  {value:234, name:&#39;联盟广告&#39;}, 
                  {value:135, name:&#39;视频广告&#39;}, 
                  {value:1548, name:&#39;搜索引擎&#39;} 
                ] 
              } 
            ] 
          }; 
     
        // 为echarts对象加载数据  
        myChart.setOption(option);  
      } 
    ); 
  </script> 
</body>

5, run the program to display the result

The above are the steps to implement the pie chart. The histogram scatter chart is similar to this. When referencing js, the pie chart is pie and the histogram is bar. The corresponding The data in the option is different, but the program frame is the same.

The above is the detailed content of Detailed introduction to Echarts usage. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn