search
HomeWeb Front-endJS TutorialExtJs integration Echarts method sharing

ExtJs integration Echarts method sharing

Mar 01, 2018 am 09:02 AM
echartsextjsjavascript

This article mainly introduces you to the example code of ExtJs integrating Echarts. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

Since Echarts does not provide table functions, if you want to implement the above picture and the following table, you need to add a table tag yourself.

ExtJs integrates Echarts

Download the js file from the Echarts official website and create a new page through the import reference, typesetting through two vertically placed p, the top is reserved for Echarts, The bottom is reserved for table tags


initPanel : function() {
 if (this.panel) {
  return
 }
 
 var panel = new Ext.Panel({
  id : 'echart',
  html :   &#39;<p id="mainEchart" style="height:50%;border:1px solid #ccc;padding:10px;"></p>&#39;
        + &#39;<p id="mainTable" style="position:relative;text-align:center;padding:10px;">&#39;
        +&#39;<label for="mainTable"><h1 id="档案调用次数表">档案调用次数表</h1></label>&#39;
        +&#39;<table id="content-table" border="1" style="width:100%;text-align:center;">&#39;
        + &#39;<tr><th>月份</th><th>调用次数</th></tr>&#39;,
  buttonAlign : &#39;center&#39;,
  autoScroll : true,//允许滚动
  bodyStyle : &#39;overflow-x:hidden; overflow-y:scroll&#39;
  //开启竖直滚动条,关闭水平滚动条
 });
 
 this.panel = panel;
 return this.panel; 
}

Echarts initialization and data loading

Official statement that only one echarts can be generated at a time, definition Relevant styles, and query data from the background to provide echarts


initData : function(id, personName, year) {
 this.id = id;
 var p = document.getElementById("mainEchart");
 var myChart = echarts.init(p);
 // myChart.showLoading({
 // text: "图表数据正在努力加载..."
 // });
 this.myChart = myChart;
 // 初始化数据
 var data = [];
 var yearStr = "";
 var flag = false;
 var monthData = [];
 
 var res = QueryData();//调用数据查询,涉及项目名,略
 
 for (var i = 0; i < res.json.body.length; i++) {
  var map = res.json.body[i];
  monthData.push(map.MM);//月份
  data.push(map.DYCS);//调用次数
 }
 var options = {
  arg : {
   id : this.id
  },
  noDataLoadingOption : {
   text : &#39;暂无数据&#39;,
   effect : &#39;bubble&#39;,
   effectOption : {
    effect : {
     n : 0
    }
   }
  },
  title : {
   text : personName + "的档案调用情况",
   x : &#39;west&#39;
  },
  tooltip : {
   trigger : &#39;axis&#39;
  },
  legend : {
   data : [&#39;调用次数&#39;]
  },
  toolbox : {
   show : true,
   feature : {
    mark : {
     show : true
    },
    dataView : {
    //重写dataView
    //在切换视图的时候能够以<table>的形式显示
     show : true,
     readOnly : true,
     optionToContent : function(opt) {
      var axisData = opt.xAxis[0].data;
      var series = opt.series;
      var table = &#39;<table style="width:100%;text-align:center" border="1"><tbody><tr>&#39;
        + &#39;<td>时间</td>&#39;
        + &#39;<td>&#39;
        + series[0].name + &#39;</td>&#39;
        // + &#39;<td>&#39;
        // + series[1].name
        // + &#39;</td>&#39;
        + &#39;</tr>&#39;;
      for (var i = 0, l = axisData.length; i < l; i++) {
       table += &#39;<tr>&#39; + &#39;<td>&#39; + axisData[i]
         + &#39;</td>&#39; + &#39;<td>&#39;
         + series[0].data[i] + &#39;</td>&#39;
         // + &#39;<td>&#39; + series[1].data[i]
         // + &#39;</td>&#39;
         + &#39;</tr>&#39;;
      }
      table += &#39;</tbody></table>&#39;;
      return table;
     }
    },
    magicType : {
     show : true,
     type : [&#39;line&#39;, &#39;bar&#39;]
    },
    restore : {
     show : true
    },
    saveAsImage : {
     show : true
    }
   }
  },
  calculable : true,
  xAxis : [{
     type : &#39;category&#39;,
     data : monthData
    }],
  yAxis : [{
     type : &#39;value&#39;,
     splitArea : {
      show : true
     }
    }],
  series : [{
   name : &#39;调用次数&#39;,
   type : &#39;bar&#39;,
   barWidth : 35,
   data : data,
   itemStyle : {//修改柱状图的颜色并在顶部显示数值
    normal : {
     color : &#39;#3575a8&#39;, 
     label : {
      show : true,
      position : &#39;top&#39;,
      formatter : &#39;{c}&#39;//&#39;{b}\n{c}&#39;
     }
    }
   }
  }]
 };
 myChart.setOption(options, true);
 myChart.on(&#39;click&#39;, function eConsole(param) {
   });
 this.tableData(personName, monthData, data)
 //表格的加载
}

Assignment of table data

The table part is simple html Assignment, there is not much to talk about, just pay attention to refresh the html after splicing. The code is as follows:


tableData : function(personName, monthData, data) {
 // 表格部分
 var html = &#39;<p id="mainTable" style="position:relative;text-align:center;padding:10px;">&#39;
   +&#39;<label for="mainTable"><h1>&#39;
   + personName
   + &#39;档案调用情况表</h1></label>&#39;
   +&#39;<table id="content-table" border="1" style="width: 100%;text-align: center;">&#39;
   + &#39;<tr style="height: 30px;text-align:center;"><th>月份</th><th>调用次数</th></tr>&#39;;
 // if(monthData.length != data.length)
 // throw new Error("数据条数不对,请检查!");
 for (var i = 0; i < data.length; i++) {
  html += &#39;<tr style="height: 30px;text-align: center;">&#39;
     +&#39;<td id="data-month-&#39;+i+&#39;">&#39;
     + monthData[i]
     + &#39;</td><td id="data-value-&#39;+i+&#39;">&#39;
     + data[i]
     + &#39;</td></tr>&#39;
 }
 html += &#39;</table></p>&#39;;
 document.getElementById(&#39;mainTable&#39;).innerHTML = html;
}

Related recommendations:

How to use H5’s WebGL to make json and echarts charts in the same interface

Detailed explanation of how to use the jQuery plug-in echarts to remove vertical grid lines

Detailed explanation of using Echarts to generate data statistical reports in PHP

The above is the detailed content of ExtJs integration Echarts method sharing. 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
Javascript Data Types : Is there any difference between Browser and NodeJs?Javascript Data Types : Is there any difference between Browser and NodeJs?May 14, 2025 am 12:15 AM

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScript Comments: A Guide to Using // and /* */JavaScript Comments: A Guide to Using // and /* */May 13, 2025 pm 03:49 PM

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use