Skip to content

Commit ed89247

Browse files
committed
✨ add kline chart
1 parent 12bf804 commit ed89247

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

docs/source/charts.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ Here is the source code using pyexcel
1717
title=title, width=800, height=600, embed=True, legend_top='bottom')
1818

1919

20+
Kline chart
21+
********************************************************************************
22+
23+
.. pyexcel-table:: data/kline.csv
24+
:width: 400
25+
:height: 350
26+
27+
Here is the source code using pyexcel
28+
29+
.. pyexcel-code::
30+
31+
title = 'Daily K Line'
32+
sheet = pyexcel.get_sheet(file_name='data/kline.csv')
33+
chart = sheet.plot(chart_type='kline', file_type='echarts.html',
34+
title=title, legend='daily k',
35+
width=800, height=400, embed=True, legend_top='bottom')
36+
37+
2038
Radar chart
2139
********************************************************************************
2240

docs/source/data/kline.csv

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
,open,close,highest,lowest
2+
2017/7/1,2320.26,2320.26,2287.3,2362.94
3+
2017/7/2,2300,2291.3,2288.26,2308.38
4+
2017/7/3,2295.35,2346.5,2295.35,2345.92
5+
2017/7/4,2347.22,2358.98,2337.35,2363.8
6+
2017/7/5,2360.75,2382.48,2347.89,2383.76
7+
2017/7/6,2383.43,2385.42,2371.23,2391.82
8+
2017/7/7,2377.41,2419.02,2369.57,2421.15
9+
2017/7/8,2425.92,2428.15,2417.58,2440.38
10+
2017/7/9,2411,2433.13,2403.3,2437.42
11+
2017/7/10,2432.68,2334.48,2427.7,2441.73
12+
2017/7/11,2430.69,2418.53,2394.22,2433.89
13+
2017/7/12,2416.62,2432.4,2414.4,2443.03
14+
2017/7/13,2441.91,2421.56,2418.43,2444.8
15+
2017/7/14,2420.26,2382.91,2373.53,2427.07
16+
2017/7/15,2383.49,2397.18,2370.61,2397.94
17+
2017/7/16,2378.82,2325.95,2309.17,2378.82
18+
2017/7/17,2322.94,2314.16,2308.76,2330.88
19+
2017/7/18,2320.62,2325.82,2315.01,2338.78
20+
2017/7/19,2313.74,2293.34,2289.89,2340.71
21+
2017/7/20,2297.77,2313.22,2292.03,2324.63
22+
2017/7/21,2322.32,2365.59,2308.92,2366.16
23+
2017/7/22,2364.54,2359.51,2330.86,2369.65
24+
2017/7/23,2332.08,2273.4,2259.25,2333.54
25+
2017/7/24,2274.81,2326.31,2270.1,2328.14
26+
2017/7/25,2333.61,2347.18,2321.6,2351.44
27+
2017/7/26,2340.44,2324.29,2304.27,2352.02
28+
2017/7/27,2326.42,2318.61,2314.59,2333.67
29+
2017/7/28,2314.68,2310.59,2296.58,2320.96
30+
2017/7/29,2309.16,2286.6,2264.83,2333.29
31+
2017/7/30,2282.17,2263.97,2253.25,2286.33
32+
2017/7/31,2255.77,2270.28,2253.31,2276.22

pyexcel_echarts/options.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
xy='XY',
2222
histogram='Histogram',
2323
scatter3d='Scatter3D',
24-
bar3d='Bar3D'
24+
bar3d='Bar3D',
25+
kline='Kline'
2526
)
2627

2728

@@ -69,7 +70,22 @@ def render_sheet(self, sheet,
6970
label_y_in_row=0,
7071
value_x_in_row=1,
7172
**keywords):
72-
self.instance.add("", sheet.row[0], sheet.row[1], **keywords)
73+
self.instance.add("", sheet.row[label_y_in_row],
74+
sheet.row[value_x_in_row], **keywords)
75+
76+
77+
@PluginInfo('chart', tags=['kline'])
78+
class KlineLayout(Chart):
79+
80+
def render_sheet(self, sheet,
81+
label_x_in_column=0, label_y_in_row=0, legend="",
82+
**keywords):
83+
if len(sheet.colnames) == 0:
84+
sheet.name_columns_by_row(label_y_in_row)
85+
if len(sheet.rownames) == 0:
86+
sheet.name_rows_by_column(label_x_in_column)
87+
self.instance.add(legend, sheet.rownames,
88+
list(sheet.rows()), **keywords)
7389

7490

7591
@PluginInfo('chart', tags=['scatter3d'])

tests/test_echarts.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def test_pie_chart():
1111
s.save_as('pie.echarts.html', chart_type='pie')
1212

1313

14+
def test_kline_chart():
15+
s = p.get_sheet(file_name=get_fixtures('kline.csv'))
16+
s.save_as('kline.echarts.html', chart_type='kline', legend='daily k')
17+
18+
1419
def test_radar_chart():
1520
s = p.get_sheet(file_name=get_fixtures('radar.csv'))
1621
s.save_as('radar.echarts.html', chart_type='radar')

0 commit comments

Comments
 (0)