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/11/01 08:41:19 UTC

[GitHub] Scookie commented on issue #7853: 使用dataset和time,在多个维度时异常

Scookie commented on issue #7853: 使用dataset和time,在多个维度时异常
URL: https://github.com/apache/incubator-echarts/issues/7853#issuecomment-434972128
 
 
   you can do it according to the following way.
   你可以试试下面的方法.
   
   ```
   option = {
       legend: {},
       tooltip: {},
       dataset: {
           source: [
               ['time', 'pay', 'income'],
               ['2017/5/3', 43.3, 85.8],
               ['2017/5/4', 83.1, 73.4],
               ['2017/5/5', 86.4, 65.2],
               ['2017/5/6', 72.4, 53.9]
           ]
       },
       xAxis: {type: 'time'},
       yAxis: {},
       series: [
           {
               type: 'line',
               name:"pay",
               encode:{
                   x:"time",
                   y:"pay"
               }
           },
           {
               type: 'line',
               name:"income",
               encode:{
                   x:"time",
                   y:"income"
               }
           }
       ]
   }
   ```
   ![image](https://user-images.githubusercontent.com/9074425/47841229-e5faa400-ddf3-11e8-96f1-260a2747caac.png)
   
   
   Or you can do it like this.
   或者你也可以优化下写成这样
   ```
   let data = [
       ['time', 'pay', 'income'],
       ['2017/5/3', 43.3, 85.8],
       ['2017/5/4', 83.1, 73.4],
       ['2017/5/5', 86.4, 65.2],
       ['2017/5/6', 72.4, 53.9]
   ];
   let dimensions = data[0];
   let timeKey = "time";
   let series = [];
   dimensions.forEach(item => {
       if(item != timeKey){
           series.push({
               type: 'line',
               name:item,
               encode:{
                   x:timeKey,
                   y:item
               }
           });
       }
   })
   option = {
       legend: {},
       tooltip: {},
       dataset: {
           source: data
       },
       xAxis: {type: 'time'},
       yAxis: {},
       series: series
   }
   ```
   ![image](https://user-images.githubusercontent.com/9074425/47841533-dc257080-ddf4-11e8-9092-c228b815ebdf.png)
   

----------------------------------------------------------------
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