mirror of
https://github.com/pyecharts/pyecharts.git
synced 2026-01-25 17:06:27 +00:00
* Format: code * Remove: #coding=utf-8 * Add: 新增示例以及数据 json 文件 * Update: 移除 List 使用 Sequence 代替,移除 instance 判断 * Update: 修复 Geo Lines 线条丢失的问题 * Remove: 移除 Mark* data 类型判断 * Update: js_functions/bmap_js_funtions 分开处理 * Update: 解决 Grid 图 title 不为 List 的问题 * Update: self.color 对外暴露 * Test: 完善测试 * Update: 更新测试和示例 * Fix: test * Fix: 修复 Grid 不能正常渲染主题以及标题的问题 * Add: Bar 图新增 gap 参数 * Add: example * Update: 百度地图 ak 保存至环境变量中
110 lines
3.1 KiB
Python
110 lines
3.1 KiB
Python
import os
|
|
import random
|
|
|
|
from pyecharts.render import make_snapshot
|
|
|
|
|
|
def render_chart_images(charts: list):
|
|
for fn, name in charts:
|
|
make_snapshot(fn().render(), Faker.img_path(name + ".png"))
|
|
|
|
|
|
class _Faker:
|
|
clothes = ["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"]
|
|
drinks = ["可乐", "雪碧", "橙汁", "绿茶", "奶茶", "百威", "青岛"]
|
|
phones = ["小米", "三星", "华为", "苹果", "魅族", "VIVO", "OPPO"]
|
|
fruits = ["草莓", "芒果", "葡萄", "雪梨", "西瓜", "柠檬", "车厘子"]
|
|
animal = ["河马", "蟒蛇", "老虎", "大象", "兔子", "熊猫", "狮子"]
|
|
cars = ["宝马", "法拉利", "奔驰", "奥迪", "大众", "丰田", "特斯拉"]
|
|
dogs = ["哈士奇", "萨摩耶", "泰迪", "金毛", "牧羊犬", "吉娃娃", "柯基"]
|
|
week = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
|
|
week_en = "Saturday Friday Thursday Wednesday Tuesday Monday Sunday".split()
|
|
clock = (
|
|
"12a 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12p "
|
|
"1p 2p 3p 4p 5p 6p 7p 8p 9p 10p 11p".split()
|
|
)
|
|
visual_color = [
|
|
"#313695",
|
|
"#4575b4",
|
|
"#74add1",
|
|
"#abd9e9",
|
|
"#e0f3f8",
|
|
"#ffffbf",
|
|
"#fee090",
|
|
"#fdae61",
|
|
"#f46d43",
|
|
"#d73027",
|
|
"#a50026",
|
|
]
|
|
months = ["{}月".format(i) for i in range(1, 13)]
|
|
provinces = ["广东", "北京", "上海", "江西", "湖南", "浙江", "江苏"]
|
|
guangdong_city = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市", "广州市", "惠州市"]
|
|
country = [
|
|
"China",
|
|
"Canada",
|
|
"Brazil",
|
|
"Russia",
|
|
"United States",
|
|
"Africa",
|
|
"Germany",
|
|
]
|
|
days_attrs = ["{}天".format(i) for i in range(30)]
|
|
days_values = [random.randint(1, 30) for _ in range(30)]
|
|
|
|
def choose(self) -> list:
|
|
return random.choice(
|
|
[
|
|
self.clothes,
|
|
self.drinks,
|
|
self.phones,
|
|
self.fruits,
|
|
self.animal,
|
|
self.dogs,
|
|
self.week,
|
|
]
|
|
)
|
|
|
|
@staticmethod
|
|
def values(start: int = 20, end: int = 150) -> list:
|
|
return [random.randint(start, end) for _ in range(7)]
|
|
|
|
@staticmethod
|
|
def rand_color():
|
|
return random.choice(
|
|
[
|
|
"#c23531",
|
|
"#2f4554",
|
|
"#61a0a8",
|
|
"#d48265",
|
|
"#749f83",
|
|
"#ca8622",
|
|
"#bda29a",
|
|
"#6e7074",
|
|
"#546570",
|
|
"#c4ccd3",
|
|
"#f05b72",
|
|
"#444693",
|
|
"#726930",
|
|
"#b2d235",
|
|
"#6d8346",
|
|
"#ac6767",
|
|
"#1d953f",
|
|
"#6950a1",
|
|
]
|
|
)
|
|
|
|
@staticmethod
|
|
def img_path(path: str, prefix: str = "images") -> str:
|
|
return os.path.join(prefix, path)
|
|
|
|
|
|
Faker = _Faker()
|
|
|
|
|
|
class Collector:
|
|
charts = []
|
|
|
|
@staticmethod
|
|
def funcs(fn):
|
|
Collector.charts.append((fn, fn.__name__))
|