drumslave-git commented on issue #8151: dataset 可以为每个数据指定样式
URL: 
https://github.com/apache/incubator-echarts/issues/8151#issuecomment-530690619
 
 
   Hi.
   If anyone needs it, I found a workaround.
   
   My dataset looks like this:
   
   ```
   {source: [
     {value: 15, name: 'test', color: '#FF00FF'},
     ...
   ]}
   ```
   
   Before chart init you need to add such code
   
   ```
   import echarts from 'echarts';
   
   const VISUAL_PRIORITY = echarts.PRIORITY.VISUAL.COMPONENT;
   
   echarts.registerVisual(VISUAL_PRIORITY, {
       createOnAllSeries: true,
       reset: function (seriesModel) {
           const data = seriesModel.getData();
   
           data.each(function (idx) {
               const itemModel = data.getItemModel(idx);
               let color = itemModel.get('itemStyle.color');
               if(!color){ // if there is no color set in normal way
                   color = itemModel.get('color');
   
                   if(color && typeof color === 'string'){ // if there is no 
such field in dataset, it can return array (default color palette)
                       data.setItemVisual(idx, 'color', color);
                   }
               }
           });
       }
   });
   ```
   
   After this you can init charts as always. Using such approach you can do any 
calculations based on your dataset item data to determine color.
   
   Don't know if it is good, but works for me and I got no other choice. 
   
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to