用于在superset==0.35.*
中使用echarts
- 将
superset-chart-echarts
文件夹复制到../assets/src/visualizations
。 - 在
../assets/src/visualizations/presets/MainPreset.js
中注册插件:import EchartsChartPlugin from '../superset-chart-echarts/EchartsChartPlugin'; ... plugins: [ ... new EchartsChartPlugin().configure({ key: 'echarts' }) ],
- 在
../assets/src/explore/controls.jsx
中定义control
:code: { type: 'TextAreaControl', label: t('Code'), default: 'def get_opts(df):\n return df.T.to_dict()', }
- 安装依赖
npm install -d npm install echarts-for-react@3.0.1 npm install echarts@5.1.2 npm install echarts-gl@2.0.7
- 重新生成前端文件
npm run build
from importlib.util import spec_from_loader, module_from_spec
# from superset.viz import viz_types, TableViz
class EchartsViz(TableViz):
"""Echarts"""
viz_type = "echarts"
verbose_name = "Echarts"
is_timeseries = True
def get_data(self, df):
if df.empty:
return None
get_opts = self.get_opts_func()
return get_opts(df)
def get_opts_func(self):
fd = self.form_data
code = fd.get('code')
tmp_name = 'tmp_module'
tmp_spec = spec_from_loader(tmp_name, loader=None)
tmp_module = module_from_spec(tmp_spec)
exec(code, tmp_module.__dict__)
return tmp_module.get_opts
viz_types['echarts'] = EchartsViz