|
2 | 2 |
|
3 | 3 | # 📊 Chart Maker 📊
|
4 | 4 |
|
5 |
| -SeleniumBase Chart Maker allows you to create HTML charts with Python.<br /> |
6 |
| -The HighCharts library is used for creating charts. |
| 5 | +SeleniumBase Chart Maker allows you to create HTML charts with Python. (The HighCharts library is used for creating charts.) |
7 | 6 |
|
8 |
| -**Here's a sample chart:** |
| 7 | +**Here's a sample pie chart:** |
9 | 8 |
|
10 | 9 | <a href="https://seleniumbase.io/other/chart_presentation.html"><img width="500" src="https://seleniumbase.io/other/sample_pie_chart.png" title="Screenshot"></a><br>
|
11 | 10 |
|
12 |
| -([Click on the image for an actual chart demo](https://seleniumbase.io/other/chart_presentation.html)) |
| 11 | +([Click to see a presentation with multiple charts](https://seleniumbase.io/other/chart_presentation.html)) |
13 | 12 |
|
14 |
| -Here's how to run the example: |
| 13 | +Here's how to run an example presentation with a pie chart: |
15 | 14 |
|
16 | 15 | ```bash
|
17 | 16 | cd examples/chart_maker
|
18 | 17 | pytest my_chart.py
|
19 | 18 | ```
|
20 | 19 |
|
| 20 | +Here's the code for that pie chart presentation: |
21 | 21 |
|
22 |
| -### Creating a new chart: |
| 22 | +```python |
| 23 | +from seleniumbase import BaseCase |
| 24 | + |
| 25 | +class MyChartMakerClass(BaseCase): |
| 26 | + def test_chart_maker(self): |
| 27 | + self.create_presentation() |
| 28 | + self.create_pie_chart(title="Automated Tests") |
| 29 | + self.add_data_point("Passed", 7, color="#95d96f") |
| 30 | + self.add_data_point("Untested", 2, color="#eaeaea") |
| 31 | + self.add_data_point("Failed", 1, color="#f1888f") |
| 32 | + self.add_slide("<p>Pie Chart</p>" + self.extract_chart()) |
| 33 | + self.begin_presentation(filename="my_chart.html") |
| 34 | +``` |
| 35 | + |
| 36 | +Here's how to run an example presentation with multiple charts: (Press the right arrow to advance to the next slide) |
| 37 | + |
| 38 | +```bash |
| 39 | +cd examples/chart_maker |
| 40 | +pytest chart_presentation.py |
| 41 | +``` |
| 42 | + |
| 43 | +Here are screenshots from the examples: |
| 44 | + |
| 45 | +<a href="https://seleniumbase.io/other/sample_column_chart.png"><img width="500" src="https://seleniumbase.io/other/sample_column_chart.png" title="Screenshot"></a><br> |
| 46 | + |
| 47 | +<a href="https://seleniumbase.io/other/sample_bar_chart.png"><img width="500" src="https://seleniumbase.io/other/sample_bar_chart.png" title="Screenshot"></a><br> |
| 48 | + |
| 49 | +<a href="https://seleniumbase.io/other/sample_line_chart.png"><img width="500" src="https://seleniumbase.io/other/sample_line_chart.png" title="Screenshot"></a><br> |
| 50 | + |
| 51 | +<a href="https://seleniumbase.io/other/sample_area_chart.png"><img width="500" src="https://seleniumbase.io/other/sample_area_chart.png" title="Screenshot"></a><br> |
| 52 | + |
| 53 | +<a href="https://seleniumbase.io/other/multi_series_chart.png"><img width="500" src="https://seleniumbase.io/other/multi_series_chart.png" title="Screenshot"></a><br> |
| 54 | + |
| 55 | + |
| 56 | +### Creating new charts: |
23 | 57 |
|
24 | 58 | ```python
|
25 | 59 | self.create_pie_chart(
|
@@ -85,7 +119,28 @@ self.create_column_chart(
|
85 | 119 | self.create_line_chart(
|
86 | 120 | chart_name=None, title=None, subtitle=None,
|
87 | 121 | data_name=None, unit=None, zero=False, libs=True):
|
88 |
| -""" Creates a JavaScript column chart using "HighCharts". |
| 122 | +""" Creates a JavaScript line chart using "HighCharts". |
| 123 | + @Params |
| 124 | + chart_name - If creating multiple charts, |
| 125 | + use this to select which one. |
| 126 | + title - The title displayed for the chart. |
| 127 | + subtitle - The subtitle displayed for the chart. |
| 128 | + data_name - Set the series name. Useful for multi-series charts. |
| 129 | + unit - The description label given to the chart's y-axis values. |
| 130 | + zero - If True, the y-axis always starts at 0. (Default: False). |
| 131 | + libs - The option to include Chart libraries (JS and CSS files). |
| 132 | + Should be set to True (default) for the first time creating |
| 133 | + a chart on a web page. If creating multiple charts on |
| 134 | + a web page, you no longer need to re-import the libraries |
| 135 | + when creating additional charts. |
| 136 | +""" |
| 137 | +``` |
| 138 | + |
| 139 | +```python |
| 140 | +self.create_area_chart( |
| 141 | + chart_name=None, title=None, subtitle=None, |
| 142 | + data_name=None, unit=None, zero=False, libs=True): |
| 143 | +""" Creates a JavaScript area chart using "HighCharts". |
89 | 144 | @Params
|
90 | 145 | chart_name - If creating multiple charts,
|
91 | 146 | use this to select which one.
|
@@ -187,23 +242,29 @@ All methods have the optional ``chart_name`` argument, which is only needed if y
|
187 | 242 | from seleniumbase import BaseCase
|
188 | 243 |
|
189 | 244 | class MyChartMakerClass(BaseCase):
|
190 |
| - |
191 | 245 | def test_chart_maker(self):
|
192 | 246 | self.create_presentation()
|
193 |
| - self.create_pie_chart(title="Automated Tests") |
194 |
| - self.add_data_point("Passed", 7, color="#95d96f") |
195 |
| - self.add_data_point("Untested", 2, color="#eaeaea") |
196 |
| - self.add_data_point("Failed", 1, color="#f1888f") |
197 |
| - self.add_slide("<p>Pie Chart</p>" + self.extract_chart()) |
198 |
| - self.begin_presentation(filename="my_chart.html") |
| 247 | + self.create_line_chart( |
| 248 | + title="Time Outside", subtitle="Last Week", unit="Minutes") |
| 249 | + self.add_data_point("Sun", 5) |
| 250 | + self.add_data_point("Mon", 10) |
| 251 | + self.add_data_point("Tue", 20) |
| 252 | + self.add_data_point("Wed", 40) |
| 253 | + self.add_data_point("Thu", 80) |
| 254 | + self.add_data_point("Fri", 65) |
| 255 | + self.add_data_point("Sat", 50) |
| 256 | + self.add_slide("<p>Line Chart</p>" + self.extract_chart()) |
| 257 | + self.begin_presentation(filename="line_chart.html", interval=8) |
199 | 258 | ```
|
200 | 259 |
|
201 |
| -#### This example is from [my_chart.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/chart_maker/my_chart.py), which you can run from the ``examples/chart_maker`` folder with the following command: |
| 260 | +#### This example is from [test_line_chart.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/chart_maker/test_line_chart.py), which you can run from the ``examples/chart_maker`` folder with the following command: |
202 | 261 |
|
203 | 262 | ```bash
|
204 |
| -pytest my_chart.py |
| 263 | +pytest test_line_chart.py |
205 | 264 | ```
|
206 | 265 |
|
| 266 | +Because that presentation above has an ``interval`` set to ``8``, it will automatically advance to the next slide after 8 seconds. (Or exit if there are no more slides.) |
| 267 | + |
207 | 268 | ### For a more advanced example (multiple charts in a presentation):
|
208 | 269 |
|
209 | 270 | ```python
|
|
0 commit comments