def bar_base() -> Bar: c = ( Bar() .add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]) .add_yaxis("商家A", [randrange(0, 100) for _ in range(6)]) .add_yaxis("商家B", [randrange(0, 100) for _ in range(6)]) .set_global_opts(title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题")) .dump_options_with_quotes() ) return c
def test(request): return render(request, 'test.html', {'data': json.dumps(json.loads(bar_base()))})
· 注意要{{data|safe}}格式过滤器
<div id="abc" class="chart-container" style="width:1400px; height:600px;"></div> <script> var chart_abc = echarts.init(document.getElementById('abc'), 'essos', {renderer: 'canvas'}); chart_abc.setOption({{data|safe}}); </script>
https://www.cnblogs.com/tangji/p/14764040.html
https://www.cnblogs.com/iamjqy/p/7988806.html