You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by GitBox <gi...@apache.org> on 2019/10/21 03:26:50 UTC

[GitHub] [incubator-echarts] zhiweinibajian opened a new issue #11441: 关于echarts2.0后雷达图单轴显示解决方案

zhiweinibajian opened a new issue #11441: 关于echarts2.0后雷达图单轴显示解决方案
URL: https://github.com/apache/incubator-echarts/issues/11441
 
 
   **要想解决此问题,必须拿到x坐标和y坐标,然后计算得到对应的index
   x坐标和y坐标可以通过源码中的_showTooltipContent方法进行返回;
   或者通过echart.on('mousemove',function(params){})可以得到,
   拿到x坐标和y坐标后调用下面方法就可以得到你想要的index了
   **
   
   
   `//zr:echarts实例;x:鼠标x坐标;y:鼠标y坐标;_index:seriesIndex
   function getRadarIndex(zr, x, y, _index) { 
               var polar = zr.getOption().radar;
   
               var func = {
                   getNearestIndex: function (e) {
                       for (var t, n, i, a, o, r, s, l, h, V = 0; V < polar.length; V++) {
                           if (t = polar[V], n = this.getCenter(V), e[0] == n[0] && e[1] == n[1]) return 0;
                           if (i = this._getRadius(), o = t.startAngle, r = t.indicator, s = r.length, l = 2 * Math.PI / s, a = this.cartesian2polar(e[0] - n[0], n[1] - e[1]), e[0] - n[0] < 0 && (a[1] += Math.PI), a[1] < 0 && (a[1] += 2 * Math.PI), h = a[1] - o / 180 * Math.PI + 2 * Math.PI, Math.abs(Math.cos(h % (l / 2))) * i > a[0]) return Math.floor((h + l / 2) / l) % s;
                       }
                       return Math.floor((h + l / 2) / l) % s;
                   },
                   getCenter: function (e) {
                       var e = e || 0;
                       return this.parseCenter(zr, polar[e].center);
                   },
                   _getRadius: function () {
                       var e = polar[_index];
                       return this.parsePercent(e.radius, Math.min(zr.getWidth(), zr.getHeight()) / 2);
                   },
                   cartesian2polar: function (e, t) {
                       return [Math.sqrt(e * e + t * t), Math.atan(t / e)];
                   },
                   parseCenter: function (e, n) {
                       return [this.parsePercent(n[0], e.getWidth()), this.parsePercent(n[1], e.getHeight())];
                   },
   
                   parsePercent: function (t, n) {
                       return "string" == typeof t ? this.trimSpace(t).match(/%$/) ? parseFloat(t) / 100 * n : parseFloat(t) : t;
                   },
                   trimSpace: function (e) {
                       return e.replace(/^\s+/, "").replace(/\s+$/, "");
                   }
               }
   
               return func.getNearestIndex([x, y]);
           }`
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org