You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@echarts.apache.org by GitBox <gi...@apache.org> on 2018/07/30 07:56:23 UTC

[GitHub] menkeydyvh opened a new issue #8778: 添加自定义矩形会对改变原有的k线图大小

menkeydyvh opened a new issue #8778: 添加自定义矩形会对改变原有的k线图大小
URL: https://github.com/apache/incubator-echarts/issues/8778
 
 
   <!--
   为了方便我们能够复现和修复 bug,请遵从下面的规范描述您的问题。
   -->
   
   
   ### One-line summary [问题简述]
   可以通过黏贴下面javascripts看到  custom内容的引入导致图形变化  变形严重
   
   
   
   ### Version & Environment [版本及环境]
   + ECharts version [ECharts 版本]:  "echarts": "^4.1.0",
   
   
   
   ### Expected behaviour [期望结果]
   
   
   
   ### ECharts option [ECharts配置项]
   <!-- Copy and paste your 'echarts option' here. -->
   <!-- [下方贴你的option,注意不要删掉下方 ```javascript 和 尾部的 ``` 字样。最好是我们能够直接运行的 option。如何得到能运行的 option 参见上方的 guidelines for contributing] -->
   ```javascript
   
   var dataAry = [
       [75.449996948242,75.900001525879,75.449996948242,76.349998474121],
       [75.699996948242,76.099998474121,75.599998474121,76.199996948242],
       [76.699996948242,77.099998474121,76.699996948242,77.300003051758],
       [77.900001525879,77.550003051758,77.300003051758,77.900001525879],
       [78.050003051758,78.400001525879,78,78.599998474121],
       [78.550003051758,77.949996948242,77.699996948242,78.550003051758],
       [77.949996948242,78.050003051758,77.75,78.199996948242],
       [77.400001525879,77,76.800003051758,77.550003051758],
       [77,77.25,76.699996948242,77.400001525879],
       [77.5,77.8,77.5,77.9],[78.25,77.5,77.5,78.25],
       [77.5,77.55,76.95,77.7],[76.9,77.05,76.8,77.25],
       [77,76.85,76.7,77.1],[76.6,75.9,75.9,76.75]
       ];
   
   function renderItem(params, api) {
   
       const startBarIndex = api.value(0); 
       const endBarIndex = api.value(1);
       const rectAreaColor = api.value(2); 
   
       let minPriceInRange = dataAry[startBarIndex][2];
       let maxPriceInRange = dataAry[startBarIndex][3];
       for (let j = startBarIndex; j <= endBarIndex; j++) {
         if (dataAry[j][2] < minPriceInRange) {
           minPriceInRange = dataAry[j][2]
         }
         if (dataAry[j][3] > maxPriceInRange) {
           maxPriceInRange = dataAry[j][3]
         }
       }
       minPriceInRange = minPriceInRange * 0.98;
       maxPriceInRange = maxPriceInRange * 1.02;
       const leftTopCornerPoint = api.coord([startBarIndex, maxPriceInRange]);
       const rightBottomCornerPoint = api.coord([endBarIndex, minPriceInRange]);
       const oneBarWidth = api.size([1, 1])[0];
       const rectWidth = Math.abs(rightBottomCornerPoint[0] - leftTopCornerPoint[0]);
       const rectHeight = Math.abs(rightBottomCornerPoint[1] - leftTopCornerPoint[1]);
   
       return {
         type: 'rect',
         shape: {
           x: leftTopCornerPoint[0] - oneBarWidth / 2,
           y: leftTopCornerPoint[1],
           width: rectWidth + oneBarWidth,
           height: rectHeight
         },
         style: {
           fill: rectAreaColor,
           opacity: 0.4,
           stroke: 'rgba(255,255,255,0.8)',
           lineWidth: 1
         },
       }
   }
   
   
   option = {
       tooltip: {
           formatter: function (params) {
               return params.marker + params.name + ': ' + params.value[3] + ' ms';
           }
       },
       title: {
           text: 'Profile',
           left: 'center'
       },
       grid: {
           height:300
       },
       xAxis: {
           scale: true,
           data: [
             1435766400000,
             1435852800000,
             1436112000000,
             1436198400000,
             1436284800000,
             1436371200000,
             1436457600000,
             1436716800000,
             1436803200000,
             1436889600000,
             1436976000000,
             1437062400000,
             1437321600000,
             1437408000000,
             1437494400000
           ]
       },
       yAxis: {
          scale: true,
       },
       series: [
            {
               name: 'k線圖',
               type: 'candlestick',
               data:   dataAry,
               itemStyle: {
                 normal: {
                   color: '#ee4e45',
                   color0: '#32C896',
                   borderColor: '#ee4e45',
                   borderColor0: '#32C896'
                 }
               }
             },
   //可以注释下面这段代码看到原图效果   图形改版太多无法展示
             {
                 type: 'custom',
                 name: 'rect-box',
                 z: 100,
                 data: [[1, 2, '#f00']],
                 renderItem: renderItem
             }
           
       ]
   }
   
   ```
   
   
   
   
   ### Other comments [其他信息]
   <!-- For example: Screenshot or Online demo -->
   <!-- [例如,截图或线上实例 (JSFiddle/JSBin/Codepen)] -->
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: dev-unsubscribe@echarts.apache.org
For additional commands, e-mail: dev-help@echarts.apache.org