|
4 | 4 |
|
5 | 5 | SeleniumBase Chart Maker allows you to create HTML charts with Python.<br />
|
6 | 6 | The HighCharts library is used for creating charts.
|
7 |
| -(Currently only <b>pie charts</b> are supported.) |
8 | 7 |
|
9 | 8 | **Here's a sample chart:**
|
10 | 9 |
|
11 | 10 | <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>
|
12 | 11 |
|
13 | 12 | ([Click on the image for the actual chart](https://seleniumbase.io/other/chart_presentation.html))
|
14 | 13 |
|
15 |
| -Here's how to run the example (a chart in a presentation): |
16 |
| -``` |
| 14 | +Here's how to run the example (multiple charts in a presentation): |
| 15 | + |
| 16 | +```bash |
17 | 17 | cd examples/chart_maker
|
18 | 18 | pytest my_chart.py
|
19 | 19 | ```
|
20 | 20 |
|
| 21 | +(Press the Right Arrow to advance to the next slide in the chart presentation) |
| 22 | + |
21 | 23 |
|
22 | 24 | ### Creating a new chart:
|
23 | 25 |
|
24 | 26 | ```python
|
25 |
| -self.create_pie_chart(chart_name=None, title="My Chart") |
26 |
| -""" Creates a JavaScript pie chart using "HighCharts". """ |
| 27 | +self.create_pie_chart(chart_name=None, title="My Chart", libs=True) |
| 28 | +""" Creates a JavaScript pie chart using "HighCharts". |
| 29 | + @Params |
| 30 | + chart_name - If creating multiple charts, |
| 31 | + use this to select which one. |
| 32 | + title - The title displayed for the chart. |
| 33 | + libs - The option to include Chart libraries (JS and CSS files). |
| 34 | + Should be set to True (default) for the first time creating |
| 35 | + a chart on a web page. If creating multiple charts on |
| 36 | + a web page, you no longer need to re-import the libraries |
| 37 | + when creating additional charts. |
| 38 | +""" |
| 39 | +``` |
| 40 | + |
| 41 | +```python |
| 42 | +self.create_bar_chart(chart_name=None, title="My Chart", libs=True) |
| 43 | +""" Creates a JavaScript bar chart using "HighCharts". |
| 44 | + @Params |
| 45 | + chart_name - If creating multiple charts, |
| 46 | + use this to select which one. |
| 47 | + title - The title displayed for the chart. |
| 48 | + libs - The option to include Chart libraries (JS and CSS files). |
| 49 | + Should be set to True (default) for the first time creating |
| 50 | + a chart on a web page. If creating multiple charts on |
| 51 | + a web page, you no longer need to re-import the libraries |
| 52 | + when creating additional charts. |
| 53 | +""" |
| 54 | +``` |
| 55 | + |
| 56 | +```python |
| 57 | +self.create_column_chart(chart_name=None, title="My Chart", libs=True) |
| 58 | +""" Creates a JavaScript column chart using "HighCharts". |
| 59 | + @Params |
| 60 | + chart_name - If creating multiple charts, |
| 61 | + use this to select which one. |
| 62 | + title - The title displayed for the chart. |
| 63 | + libs - The option to include Chart libraries (JS and CSS files). |
| 64 | + Should be set to True (default) for the first time creating |
| 65 | + a chart on a web page. If creating multiple charts on |
| 66 | + a web page, you no longer need to re-import the libraries |
| 67 | + when creating additional charts. |
| 68 | +""" |
27 | 69 | ```
|
28 | 70 |
|
29 | 71 | If creating multiple charts at the same time, you can pass the ``chart_name`` parameter to distinguish between different charts.
|
@@ -87,26 +129,38 @@ self.display_chart(chart_name=None, filename=None):
|
87 | 129 | """
|
88 | 130 | ```
|
89 | 131 |
|
90 |
| -All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at once. |
| 132 | +All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at the same time. |
91 | 133 |
|
92 | 134 |
|
93 | 135 | ### Here's an example of using SeleniumBase Chart Maker:
|
94 | 136 |
|
95 | 137 | ```python
|
96 | 138 | from seleniumbase import BaseCase
|
97 | 139 |
|
98 |
| - |
99 | 140 | class MyChartMakerClass(BaseCase):
|
100 | 141 |
|
101 | 142 | def test_chart_maker(self):
|
| 143 | + self.create_presentation() |
| 144 | + |
102 | 145 | self.create_pie_chart(title="Automated Tests")
|
103 | 146 | self.add_data_point("Passed", 7, color="#95d96f")
|
104 | 147 | self.add_data_point("Untested", 2, color="#eaeaea")
|
105 | 148 | self.add_data_point("Failed", 1, color="#f1888f")
|
106 |
| - self.create_presentation() |
107 | 149 | self.add_slide(self.extract_chart())
|
108 |
| - self.begin_presentation() |
109 | 150 |
|
| 151 | + self.create_bar_chart(title="Code", libs=False) |
| 152 | + self.add_data_point("Python", 33, color="Orange") |
| 153 | + self.add_data_point("JavaScript", 27, color="Teal") |
| 154 | + self.add_data_point("HTML + CSS", 21, color="Purple") |
| 155 | + self.add_slide(self.extract_chart()) |
| 156 | + |
| 157 | + self.create_column_chart(title="Colors", libs=False) |
| 158 | + self.add_data_point("Red", 10, color="Red") |
| 159 | + self.add_data_point("Green", 25, color="Green") |
| 160 | + self.add_data_point("Blue", 15, color="Blue") |
| 161 | + self.add_slide(self.extract_chart()) |
| 162 | + |
| 163 | + self.begin_presentation() |
110 | 164 | ```
|
111 | 165 |
|
112 | 166 | #### 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:
|
|
0 commit comments