You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/06/29 13:13:41 UTC

[GitHub] [incubator-superset] shrinivaskulkarni removed a comment on issue #7710: Treemap visualization with multi group by filed raises KeyError

shrinivaskulkarni removed a comment on issue #7710:
URL: https://github.com/apache/incubator-superset/issues/7710#issuecomment-651111130


   I solved the above issue by changes in viz.py.
   `class TreemapViz(BaseViz):
   
       """Tree map visualisation for hierarchical data."""
   
       viz_type = 'treemap'
       verbose_name = _('Treemap')
       credits = '<a href="https://d3js.org">d3.js</a>'
       is_timeseries = False
   
       def _nest(self, metric, df):
           nlevels = df.index.nlevels
           if nlevels == 1:
               result = [{'name': n, 'value': v}
                         for n, v in zip(df.index, df[metric])]
           else:
               result = [{'name': l, 'children': self._nest(metric, df.loc[l])}
                         for l in df.index.unique(0)]
           return result
   
       def get_data(self, df):
           df = df.set_index(self.form_data.get('groupby'))
           chart_data = [{'name': metric, 'children': self._nest(metric, df)}
                         for metric in df.columns]
           return chart_data`


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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org