cd venv/lib/python2.7/site-packages/superset
vi viz.py
class EchartsFunnelViz(BaseViz):
""" Funnel Chart"""
viz_type = 'echarts_funnel'
is_timeseries = False
def get_data(self, df):
df = df.pivot_table(
index=self.groupby)
df = df.reset_index()
df.columns = ['name', 'value']
return df.to_dict(orient='records')
cd venv/lib/python2.7/site-packages/superset/static/assets/src/visualizations
touch echarts_funnel.js
import echarts from 'echarts';
function echartsFunnelVis(slice, payload) {
const div = d3.select(slice.selector);
const slice_id = "echarts_slice_"+slice.formData.slice_id;
var html = '';
div.html(html);
const fd = slice.formData;
const json = payload.data;
var data_name = [];
const data = json;
data.forEach(function (item, index, array) {
data_name.push(item['name']);
});
var myChart =echarts.init(document.getElementById(slice_id));
var option = {
tooltip: {
trigger: 'item',
formatter: "{a}
{b} : {c}"
},
legend: {data: data_name},
calculable: true,
series: [
{
name:'漏斗图',
type:'funnel',
left: '10%',
top: 60,
//x2: 80,
bottom: 60,
width: '80%',
// height: {totalHeight} - y - y2,
min: 0,
max: 100,
minSize: '0%',
maxSize: '100%',
sort: 'descending',
gap: 2,
label: {
normal: {
show: true,
position: 'inside'
},
emphasis: {
textStyle: {
fontSize: 20
}
}
},
labelLine: {
normal: {
length: 10,
lineStyle: {
width: 1,
type: 'solid'
}
}
},
itemStyle: {
normal: {
borderColor: '#fff',
borderWidth: 1
}
},
data: data
}
]
};
myChart.setOption(option);
}
module.exports = echartsFunnelVis;
cd venv/lib/python2.7/site-packages/superset/static/assets/src/visualizations
vi index.js
在export const VIZ_TYPES 代码块的最后面加入echarts_funnel: ‘echarts_funnel’,
加入后如下图所示:
在const vizMap 代码块的最后面加入[VIZ_TYPES.echarts_funnel]: require(‘./echarts_funnel.js’),
cd venv/lib/python2.7/site-packages/superset/static/assets/src/explore
vi visTypes.js
echarts_funnel: {
label: t('Funnel View'),
showOnExplore: true,
controlPanelSections: [
{
label: t('Query'),
expanded: true,
controlSetRows: [
['metrics'],
['adhoc_filters'],
['groupby'],
['limit'],
],
},
{
label: t('Chart Options'),
controlSetRows: [
['color_scheme'],
],
},
],
},
cd venv/lib/python2.7/site-packages/superset/static/assets/images/viz_thumbnails
cd venv/lib/python2.7/site-packages/superset/static/assets
npm install --save [email protected](版本尽量要保持一致)
cd venv/lib/python2.7/site-packages/superset/static/assets
npm run dev