|
15 | 15 | from selenium.webdriver.chrome.options import Options |
16 | 16 |
|
17 | 17 |
|
18 | | -# Data - Monthly sales data |
19 | | -sales = [100, 150, 130, 180, 200, 220, 195, 240, 260, 245, 280, 310] |
| 18 | +# Data |
| 19 | +months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] |
| 20 | +sales = [100, 150, 130, 180, 200, 220, 195, 240, 260, 230, 270, 310] |
20 | 21 |
|
21 | 22 | # Create chart |
22 | 23 | chart = Chart(container="container") |
|
26 | 27 | chart.options.chart = {"type": "area", "width": 4800, "height": 2700, "backgroundColor": "#ffffff"} |
27 | 28 |
|
28 | 29 | # Title |
29 | | -chart.options.title = {"text": "Basic Area Chart", "style": {"fontSize": "48px"}} |
| 30 | +chart.options.title = {"text": "Monthly Sales Overview", "style": {"fontSize": "48px"}} |
30 | 31 |
|
31 | 32 | # Axes |
32 | 33 | chart.options.x_axis = { |
33 | | - "title": {"text": "Month", "style": {"fontSize": "40px"}}, |
34 | | - "categories": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], |
35 | | - "labels": {"style": {"fontSize": "32px"}}, |
36 | | - "gridLineWidth": 1, |
37 | | - "gridLineColor": "rgba(0, 0, 0, 0.1)", |
| 34 | + "categories": months, |
| 35 | + "title": {"text": "Month", "style": {"fontSize": "36px"}}, |
| 36 | + "labels": {"style": {"fontSize": "28px"}}, |
38 | 37 | } |
39 | 38 |
|
40 | 39 | chart.options.y_axis = { |
41 | | - "title": {"text": "Sales", "style": {"fontSize": "40px"}}, |
42 | | - "labels": {"style": {"fontSize": "32px"}}, |
| 40 | + "title": {"text": "Sales ($)", "style": {"fontSize": "36px"}}, |
| 41 | + "labels": {"style": {"fontSize": "28px"}}, |
| 42 | + "gridLineColor": "#e0e0e0", |
43 | 43 | "gridLineWidth": 1, |
44 | | - "gridLineColor": "rgba(0, 0, 0, 0.1)", |
45 | 44 | } |
46 | 45 |
|
47 | | -# Legend styling |
48 | | -chart.options.legend = {"itemStyle": {"fontSize": "32px"}} |
49 | | - |
50 | | -# Area series |
| 46 | +# Add series |
51 | 47 | series = AreaSeries() |
52 | 48 | series.data = sales |
53 | | -series.name = "Monthly Sales" |
54 | | -series.color = "#306998" # Python Blue |
| 49 | +series.name = "Sales" |
| 50 | +series.color = "#306998" |
55 | 51 | series.fill_opacity = 0.5 |
56 | 52 | series.line_width = 4 |
57 | 53 |
|
58 | 54 | chart.add_series(series) |
59 | 55 |
|
60 | | -# Download Highcharts JS for inline embedding |
| 56 | +# Legend |
| 57 | +chart.options.legend = {"enabled": False} |
| 58 | + |
| 59 | +# Credits |
| 60 | +chart.options.credits = {"enabled": False} |
| 61 | + |
| 62 | +# Download Highcharts JS |
61 | 63 | highcharts_url = "https://code.highcharts.com/highcharts.js" |
62 | 64 | with urllib.request.urlopen(highcharts_url, timeout=30) as response: |
63 | 65 | highcharts_js = response.read().decode("utf-8") |
|
90 | 92 |
|
91 | 93 | driver = webdriver.Chrome(options=chrome_options) |
92 | 94 | driver.get(f"file://{temp_path}") |
93 | | -time.sleep(5) # Wait for chart to render |
| 95 | +time.sleep(5) |
94 | 96 | driver.save_screenshot("plot.png") |
95 | 97 | driver.quit() |
96 | 98 |
|
97 | | -Path(temp_path).unlink() # Clean up temp file |
| 99 | +Path(temp_path).unlink() |
0 commit comments