Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 24 additions & 29 deletions plots/highcharts/line/line-basic/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Library: highcharts
"""

import json
import tempfile
import time
import urllib.request
Expand All @@ -17,10 +16,10 @@


# Data
time_values = ["1", "2", "3", "4", "5", "6", "7"]
values = [10, 15, 13, 18, 22, 19, 25]
time_values = [1, 2, 3, 4, 5, 6, 7]
value_data = [10, 15, 13, 18, 22, 19, 25]

# Create chart with container
# Create chart with container specified
chart = Chart(container="container")
chart.options = HighchartsOptions()

Expand All @@ -30,42 +29,40 @@
"width": 4800,
"height": 2700,
"backgroundColor": "#ffffff",
"style": {"fontFamily": "Arial, sans-serif"},
"spacing": [20, 40, 80, 40],
}

# Title
chart.options.title = {"text": "Basic Line Plot", "style": {"fontSize": "48px"}}

# Axes
chart.options.x_axis = {
"title": {"text": "Time", "style": {"fontSize": "40px"}},
"labels": {"style": {"fontSize": "32px"}, "enabled": True},
"categories": time_values,
"gridLineWidth": 1,
"gridLineColor": "#e0e0e0",
"lineWidth": 2,
"tickWidth": 2,
"title": {"text": "Time", "style": {"fontSize": "36px"}},
"categories": [str(t) for t in time_values],
"labels": {"style": {"fontSize": "28px"}},
}
chart.options.y_axis = {
"title": {"text": "Value", "style": {"fontSize": "40px"}},
"labels": {"style": {"fontSize": "32px"}},
"title": {"text": "Value", "style": {"fontSize": "36px"}},
"labels": {"style": {"fontSize": "28px"}},
"gridLineColor": "#e0e0e0",
"lineWidth": 2,
}

# Legend (not needed for single series)
# Legend
chart.options.legend = {"enabled": False}

# Disable credits
chart.options.credits = {"enabled": False}
# Plot options
chart.options.plot_options = {
"line": {
"lineWidth": 4,
"marker": {"enabled": True, "radius": 8, "fillColor": "#306998", "lineWidth": 2, "lineColor": "#ffffff"},
}
}

# Create and add series
# Create series
series = LineSeries()
series.data = values
series.data = value_data
series.name = "Value"
series.color = "#306998"
series.marker = {"enabled": True, "radius": 8, "fillColor": "#306998"}
series.line_width = 4

chart.add_series(series)

Expand All @@ -74,8 +71,8 @@
with urllib.request.urlopen(highcharts_url, timeout=30) as response:
highcharts_js = response.read().decode("utf-8")

# Generate HTML with inline scripts using JSON approach for reliability
opts_json = json.dumps(chart.options.to_dict())
# Generate HTML with inline scripts
html_str = chart.to_js_literal()
html_content = f"""<!DOCTYPE html>
<html>
<head>
Expand All @@ -84,9 +81,7 @@
</head>
<body style="margin:0;">
<div id="container" style="width: 4800px; height: 2700px;"></div>
<script>
Highcharts.chart('container', {opts_json});
</script>
<script>{html_str}</script>
</body>
</html>"""

Expand All @@ -100,13 +95,13 @@
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=4800,2800")
chrome_options.add_argument("--window-size=4900,2800")

driver = webdriver.Chrome(options=chrome_options)
driver.get(f"file://{temp_path}")
time.sleep(5)

# Take screenshot of just the chart container element
# Get the chart container element and take screenshot of it
container = driver.find_element("id", "container")
container.screenshot("plot.png")
driver.quit()
Expand Down
Loading