入门案例
需求: 使用Superset展示不同性别的用户人数
- 效果图
- 准备环境
yum install python-devel -y
yum install mysql-devel -y
yum install gcc -y
pip install mysqlclient
- 实现步骤:
- 1、导入MySQL数据源
- 导入superset_demo.sql
- 2、添加新的数据库
- mysql的url地址
mysql://root:123456@node1/superset_demo?charset=utf8
- 3、点击 SQLLab > SQL Editor编写以下SQL语句
- 选择 数据库
- 选择表,查看表的列
- 参考SQL语句:
select
case when gender = 0 then '男'
when gender = 1 then '女'
else '保密'
end as gender,
count(id) as total_cnt
from
t_user
group by gender
- 4、保存查询
- 5、点击 saved queries
运行查询,点击 Explore 浏览数据
- 6、配置图表类型为 Bar Chart 条形图
- 7、指定统计指标 sum(total_cnt)
- 8、指定序列为 gender(性别)