@@ -961,6 +961,44 @@ def bar_custom_bar_color() -> Bar:
961
961
```
962
962
![ ] ( https://user-images.githubusercontent.com/19553554/63005440-1dcc6700-beaf-11e9-9281-8b20a047c113.png )
963
963
964
+ > Bar-堆叠显示百分比
965
+
966
+ ``` python
967
+ def stack_bar_percent () -> Bar:
968
+ list2 = [
969
+ {" value" : 12 , " percent" : 12 / (12 + 3 )},
970
+ {" value" : 23 , " percent" : 23 / (23 + 21 )},
971
+ {" value" : 33 , " percent" : 33 / (33 + 5 )},
972
+ {" value" : 3 , " percent" : 3 / (3 + 52 )},
973
+ {" value" : 33 , " percent" : 33 / (33 + 43 )},
974
+ ]
975
+
976
+ list3 = [
977
+ {" value" : 3 , " percent" : 3 / (12 + 3 )},
978
+ {" value" : 21 , " percent" : 21 / (23 + 21 )},
979
+ {" value" : 5 , " percent" : 5 / (33 + 5 )},
980
+ {" value" : 52 , " percent" : 52 / (3 + 52 )},
981
+ {" value" : 43 , " percent" : 43 / (33 + 43 )},
982
+ ]
983
+
984
+ c = (
985
+ Bar(init_opts = opts.InitOpts(theme = ThemeType.LIGHT ))
986
+ .add_xaxis([1 , 2 , 3 , 4 , 5 ])
987
+ .add_yaxis(" product1" , list2, stack = " stack1" , category_gap = " 50%" )
988
+ .add_yaxis(" product2" , list3, stack = " stack1" , category_gap = " 50%" )
989
+ .set_series_opts(
990
+ label_opts = opts.LabelOpts(
991
+ position = " right" ,
992
+ formatter = JsCode(
993
+ " function(x){return Number(x.data.percent * 100).toFixed() + '%';}"
994
+ ),
995
+ )
996
+ )
997
+ )
998
+ return c
999
+ ```
1000
+ ![ ] ( https://user-images.githubusercontent.com/17564655/68597426-e5e9b580-04d7-11ea-882f-d5cce5ccd484.png )
1001
+
964
1002
965
1003
## Boxplot:箱形图
966
1004
@@ -1832,6 +1870,84 @@ def line_itemstyle() -> Line:
1832
1870
```
1833
1871
![ ] ( https://user-images.githubusercontent.com/19553554/56972743-1b632d00-6b9e-11e9-8110-c52070cc2783.png )
1834
1872
1873
+ > Line图-高级自定义
1874
+
1875
+ ``` python
1876
+ def line_color_with_js_func () -> Line:
1877
+ x_data = [" 14" , " 15" , " 16" , " 17" , " 18" , " 19" , " 20" , " 21" , " 22" , " 23" ]
1878
+ y_data = [393 , 438 , 485 , 631 , 689 , 824 , 987 , 1000 , 1100 , 1200 ]
1879
+
1880
+ background_color_js = (
1881
+ " new echarts.graphic.LinearGradient(0, 0, 0, 1, "
1882
+ " [{offset: 0, color: '#c86589'}, {offset: 1, color: '#06a7ff'}], false)"
1883
+ )
1884
+ area_color_js = (
1885
+ " new echarts.graphic.LinearGradient(0, 0, 0, 1, "
1886
+ " [{offset: 0, color: '#eb64fb'}, {offset: 1, color: '#3fbbff0d'}], false)"
1887
+ )
1888
+
1889
+ c = (
1890
+ Line(init_opts = opts.InitOpts(bg_color = JsCode(background_color_js)))
1891
+ .add_xaxis(xaxis_data = x_data)
1892
+ .add_yaxis(
1893
+ series_name = " 注册总量" ,
1894
+ y_axis = y_data,
1895
+ is_smooth = True ,
1896
+ is_symbol_show = True ,
1897
+ symbol = " circle" ,
1898
+ symbol_size = 6 ,
1899
+ linestyle_opts = opts.LineStyleOpts(color = " #fff" ),
1900
+ label_opts = opts.LabelOpts(is_show = True , position = " top" , color = " white" ),
1901
+ itemstyle_opts = opts.ItemStyleOpts(
1902
+ color = " red" , border_color = " #fff" , border_width = 3
1903
+ ),
1904
+ tooltip_opts = opts.TooltipOpts(is_show = False ),
1905
+ areastyle_opts = opts.AreaStyleOpts(color = JsCode(area_color_js), opacity = 1 ),
1906
+ )
1907
+ .set_global_opts(
1908
+ title_opts = opts.TitleOpts(
1909
+ title = " OCTOBER 2015" ,
1910
+ pos_bottom = " 5%" ,
1911
+ pos_left = " center" ,
1912
+ title_textstyle_opts = opts.TextStyleOpts(color = " #fff" , font_size = 16 ),
1913
+ ),
1914
+ xaxis_opts = opts.AxisOpts(
1915
+ type_ = " category" ,
1916
+ boundary_gap = False ,
1917
+ axislabel_opts = opts.LabelOpts(margin = 30 , color = " #ffffff63" ),
1918
+ axisline_opts = opts.AxisLineOpts(is_show = False ),
1919
+ axistick_opts = opts.AxisTickOpts(
1920
+ is_show = True ,
1921
+ length = 25 ,
1922
+ linestyle_opts = opts.LineStyleOpts(color = " #ffffff1f" ),
1923
+ ),
1924
+ splitline_opts = opts.SplitLineOpts(
1925
+ is_show = True , linestyle_opts = opts.LineStyleOpts(color = " #ffffff1f" )
1926
+ ),
1927
+ ),
1928
+ yaxis_opts = opts.AxisOpts(
1929
+ type_ = " value" ,
1930
+ position = " right" ,
1931
+ axislabel_opts = opts.LabelOpts(margin = 20 , color = " #ffffff63" ),
1932
+ axisline_opts = opts.AxisLineOpts(
1933
+ linestyle_opts = opts.LineStyleOpts(width = 2 , color = " #fff" )
1934
+ ),
1935
+ axistick_opts = opts.AxisTickOpts(
1936
+ is_show = True ,
1937
+ length = 15 ,
1938
+ linestyle_opts = opts.LineStyleOpts(color = " #ffffff1f" ),
1939
+ ),
1940
+ splitline_opts = opts.SplitLineOpts(
1941
+ is_show = True , linestyle_opts = opts.LineStyleOpts(color = " #ffffff1f" )
1942
+ ),
1943
+ ),
1944
+ legend_opts = opts.LegendOpts(is_show = False ),
1945
+ )
1946
+ )
1947
+ return c
1948
+ ```
1949
+ ![ ] ( https://user-images.githubusercontent.com/17564655/68598066-09f9c680-04d9-11ea-9390-9d161c9228e8.png )
1950
+
1835
1951
1836
1952
## PictorialBar:象形柱状图
1837
1953
0 commit comments