数据可视化工具哪家强 - superset 开源图表工具

superset 官网简介链接

为何选择 Superset?

Superset 是一个现代的数据探索和数据可视化平台。Superset 可以为许多团队取代或增强专有的商业智能工具。Superset 可以很好地与各种数据源集成。

Superset 提供

  • 一个无代码界面,用于快速构建图表
  • 一个功能强大的基于 Web 的SQL 编辑器,用于高级查询
  • 一个轻量级语义层,用于快速定义自定义维度和指标
  • 开箱即用,支持几乎任何 SQL数据库或数据引擎
  • 各种美观的可视化效果,展示您的数据,从简单的条形图到地理空间可视化效果
  • 轻量级、可配置的缓存层,帮助减轻数据库负载
  • 高度可扩展的安全角色和身份验证选项
  • 用于编程自定义的API
  • 云原生架构,从头开始设计,以实现扩展
  • 最重要的是开源免费够用

安装

bash 复制代码
sudo apt-get install build-essential libssl-dev libffi-dev python-dev python-pip libsasl2-dev libldap2-dev default-libmysqlclient-dev


python3 -m venv superset_venv
source superset_venv/bin/activate

pip install apache-superset

superset db upgrade # 执行此命令后,会生成superset.db。位置:~/.superset/superset.db

mkdir superset_app
cd superset_app
vim superset_config.py  # 可参考:https://github.com/apache/superset/blob/master/superset/config.py 

---------------------- superset_config.py ---------------------------
ROW_LIMIT = 5000
SECRET_KEY = 'YOUR_OWN_RANDOM_GENERATED_SECRET_KEY'
SQLALCHEMY_DATABASE_URI = 'sqlite:root/.superset/superset.db?check_same_thread=false'
WTF_CSRF_ENABLED = True
WTF_CSRF_EXEMPT_LIST = []
WTF_CSRF_TIME_LIMIT = 60 * 60 * 24 * 365
MAPBOX_API_KEY = ''

FILTER_STATE_CACHE_CONFIG = {
    'CACHE_TYPE': 'RedisCache',
    'CACHE_DEFAULT_TIMEOUT': 86400,
    'CACHE_KEY_PREFIX': 'superset_filter_cache',
    'CACHE_REDIS_URL': 'redis://localhost:6379/0'
}

---------------------- end --------------------------------------------

# Create an admin user in your metadata database (use `admin` as username to be able to load the examples)

vim ~/.bashrc
添加:export FLASK_APP=superset
source ~/.bashrc


superset fab create-admin

# Load some data to play with
superset load_examples

# Create default roles and permissions
superset init

# To start a development web server on port 8088, use -p to bind to another port
superset run -host 0.0.0.0 -p 8088 --with-threads --reload --debugger

gunicorn -w 4 --timeout 120 --bind 0.0.0.0:8088 "superset.app:create_app()"

使用supervisor管理进程

bash 复制代码
cd /etc/supervisor/conf.d
vim superset.conf

-------------------- start ----------------
[program:superset]
directory=/root/superset_app
command=/root/superset_venv/bin/gunicorn -w 4 --timeout 120 --bind 0.0.0.0:8088 "superset.app:create_app()"
user=root
autostart=true
autorestart=true
startsecs=5
redirect_stderr=true
stdout_logfile_maxbytes=50MB
stdout_logfile=/root/superset_app/superset.log
loglevel=info
[supervisord]
[supervisorctl]
-------------------- end ------------------

supervisorctl reread # 加载配置,不启动进程
supervisorctl update # 更新配置,启动新进程

访问 : http://10.10.25.113:8088 

安装数据库连接依赖

bash 复制代码
pip install psycopg2 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install clickhouse-connect  -i https://pypi.tuna.tsinghua.edu.cn/simple

API使用

bash 复制代码
https://superset.apache.org/docs/api/

http://10.10.25.113:8088/api/v1/chart  # 返回所有图表信息

rows = data.get('result', [])
for row in rows:
	slice_name = row.get('slice_name') # "slice_name": "各个省份锥形图"
	id = row.get('id') # "id": 2,
	viz_type = row.get('viz_type') # 图表类型 "viz_type": "pie"


将图表数据通过API,将数据返回给前段

如何获取csrf_token 
http://10.10.25.113:8088/api/v1/security/csrf_token/

{
    "result": "IjJiNjI0ODZkYmI3NTYxY2Q4MDdmMTg2NDkxODI0NTQ4OGJiOTBiNDki.ZrHMjw.FMTc8dovtd9qPOleDo9AKFNf6qA"
}

图标ID=1
http://10.10.25.113:8088/api/v1/chart/{图表ID}/data

{
  "result": [
    {
      "cache_key": "81846ce79d7a5c4c9cb532f776cab21b",
      "cached_dttm": null,
      "cache_timeout": 86400,
      "applied_template_filters": [],
      "annotation_data": {},
      "error": null,
      "is_cached": null,
      "query": "SELECT sheng AS sheng,\n       source AS source,\n                 count(id) AS \"COUNT(id)\"\nFROM public.bicompanyinfo\nWHERE ((DATE(created_time) = '2024-08-04'))\nGROUP BY sheng,\n         source\nORDER BY \"COUNT(id)\" DESC\nLIMIT 100;\n\n",
      "status": "success",
      "stacktrace": null,
      "rowcount": 19,
      "sql_rowcount": 19,
      "from_dttm": null,
      "to_dttm": null,
      "label_map": {
        "sheng": [
          "sheng"
        ],
        "source": [
          "source"
        ],
        "COUNT(id)": [
          "COUNT(id)"
        ]
      },
      "colnames": [
        "sheng",
        "source",
        "COUNT(id)"
      ],
      "indexnames": [
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        11,
        12,
        13,
        14,
        15,
        16,
        17,
        18
      ],
      "coltypes": [
        1,
        1,
        0
      ],
      "data": [
        {
          "sheng": "江苏",
          "source": "处置信息",
          "COUNT(id)": 7
        },
        {
          "sheng": "山东",
          "source": "处置信息",
          "COUNT(id)": 7
        },
        {
          "sheng": "河北",
          "source": "处置信息",
          "COUNT(id)": 5
        },
        {
          "sheng": "黑龙江",
          "source": "处置信息",
          "COUNT(id)": 4
        },
        {
          "sheng": "陕西",
          "source": "处置信息",
          "COUNT(id)": 3
        },
        {
          "sheng": "广西",
          "source": "处置信息",
          "COUNT(id)": 3
        },
        {
          "sheng": "广东",
          "source": "处置信息",
          "COUNT(id)": 2
        },
        {
          "sheng": "湖北",
          "source": "处置信息",
          "COUNT(id)": 2
        },
        {
          "sheng": "辽宁",
          "source": "处置信息",
          "COUNT(id)": 2
        },
        {
          "sheng": "安徽",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "直辖市",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "甘肃",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "海南",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "河南",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "江西",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "山西",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "四川",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "云南",
          "source": "处置信息",
          "COUNT(id)": 1
        },
        {
          "sheng": "浙江",
          "source": "处置信息",
          "COUNT(id)": 1
        }
      ],
      "result_format": "json",
      "applied_filters": [],
      "rejected_filters": []
    }
  ]
}
相关推荐
小鹿( ﹡ˆoˆ﹡ )9 分钟前
深入探索 Seaborn:高级绘图的艺术与实践
python·信息可视化
工业3D_大熊24 分钟前
【虚拟仿真】CEETRON SDK在船舶流体与结构仿真中的应用解读
java·python·科技·信息可视化·c#·制造·虚拟现实
IT铺子28 分钟前
Excel和微软小冰的结合应用
信息可视化
申耀的科技观察3 小时前
【观察】华为持续投入开源开放“结硕果”,openEuler走出操作系统“创新路”...
华为·开源
IT规划师10 小时前
开源 - Ideal库 - 常用时间转换扩展方法(二)
开源·.net core·时间转换·ideal库
_tison12 小时前
夜天之书 #103 开源嘉年华纪实
开源
customer0812 小时前
【开源免费】基于SpringBoot+Vue.JS周边产品销售网站(JAVA毕业设计)
java·vue.js·spring boot·后端·spring cloud·java-ee·开源
非著名程序员18 小时前
腾讯为什么支持开源?
开源
CSDN云计算18 小时前
如何以开源加速AI企业落地,红帽带来新解法
人工智能·开源·openshift·红帽·instructlab
customer0819 小时前
【开源免费】基于SpringBoot+Vue.JS医院管理系统(JAVA毕业设计)
java·vue.js·spring boot·后端·spring cloud·开源·intellij-idea