
Do not write any import statements.
Import statements will be ignored.
These libraries are already available:
pandas as pd
numpy as np
json
pyecharts
This code runs in a backend Python environment and must only produce ECharts JSON options (not render charts).
The final output must be saved in a variable named result.
The final output must be generated using:
result = <chart>.dump_options()
Example: result = bar.dump_options()
Do not write files. Do not print. Do not return anything else.
The pandas dataframe is always named df.
Always work on a copy:
df1 = df.copy()
Link events to chart elements by embedding an event_list inside each data item in the series values:
A) Required structure (when available)
When event_uuid exists, each plotted element must be represented as a dict like:
{"value": <number>, "event_list": [<uuid_str>, ...]}
B) Segment-level behavior
For grouped/stacked/multi-series charts, each segment must carry only the events belonging to that exact segment.
C) Ordering + uniqueness
Preserve original df order when collecting UUIDs.
Do not include duplicates in event_list.
D) Fail-safe requirement
If event_uuid does not exist, the code must still run and produce valid ECharts options JSON.
In that case, set "event_list": [] for each data item (preferred) or omit event_list, but do not throw errors.
Use this as the baseline pattern. Users may change chart type/grouping/styling later, but must preserve output rules and event-linking structure.
# Step 1: Work on a copy
df1 = df.copy()
# Step 2: Count occurrences for each category
category_counts = df1["Primary category"].value_counts().sort_values(ascending=False)
categories = list(category_counts.index)
values = []
event_lists = [] # optional helper list; keep if useful
# Step 3: Collect event UUIDs and counts (fail-safe if event_uuid is missing)
for category in categories:
category_rows = df1[df1["Primary category"] == category]
event_uuids = []
if "event_uuid" in df1.columns:
for uuid in category_rows["event_uuid"].tolist():
s = str(uuid)
if s not in event_uuids:
event_uuids.append(s)
values.append({
"value": int(category_counts[category]),
"event_list": event_uuids
})
event_lists.append(event_uuids)
# Step 4: Create the bar chart
bar = (
pyecharts.charts.Bar(
init_opts=pyecharts.options.InitOpts(
width="800px",
height="600px",
bg_color="black"
)
)
.add_xaxis(categories)
.add_yaxis(
"Counts",
values,
itemstyle_opts=pyecharts.options.ItemStyleOpts(
border_radius=[10, 10, 0, 0],
),
)
.set_global_opts(
title_opts=pyecharts.options.TitleOpts(
title="Overall player involvement in game",
title_textstyle_opts=pyecharts.options.TextStyleOpts(color="white"),
),
xaxis_opts=pyecharts.options.AxisOpts(
name="Players",
name_location="middle",
name_gap="50",
name_textstyle_opts=pyecharts.options.TextStyleOpts(color="white"),
axislabel_opts=pyecharts.options.LabelOpts(rotate=45, color="white"),
axisline_opts=pyecharts.options.AxisLineOpts(
linestyle_opts=pyecharts.options.LineStyleOpts(color="rgba(128, 128, 128, 1)")
),
splitline_opts=pyecharts.options.SplitLineOpts(is_show=False)
),
yaxis_opts=pyecharts.options.AxisOpts(
name="Number of actions",
name_location="middle",
name_gap="30",
name_textstyle_opts=pyecharts.options.TextStyleOpts(color="white"),
axislabel_opts=pyecharts.options.LabelOpts(color="white"),
axisline_opts=pyecharts.options.AxisLineOpts(
linestyle_opts=pyecharts.options.LineStyleOpts(color="rgba(128, 128, 128, 1)")
),
splitline_opts=pyecharts.options.SplitLineOpts(
linestyle_opts=pyecharts.options.LineStyleOpts(
color="rgba(128, 128, 128, 1)",
type_="dotted",
width=1
),
is_show=True
)
),
tooltip_opts=pyecharts.options.TooltipOpts(trigger="item"),
legend_opts=pyecharts.options.LegendOpts(is_show=False),
)
.set_series_opts(
label_opts=pyecharts.options.LabelOpts(is_show=True, position="insideTop")
)
)
# Step 5: Export chart options to JSON
result = bar.dump_options()
Uses dataframe df
Creates a copy df1 = df.copy()
Embeds event linking into series values using dicts: {"value": ..., "event_list": [...]} when possible
Preserves original df order in event_list and avoids duplicates
Does not crash if event_uuid is missing
Ends with result = <chart>.dump_options()

Users can modify only this section to change titles/labels/colors/layout. Example:
Chart title must be: Invovlements of the players
X-axis title must be: Players with their jersey numbers
Y-axis title must be: Number of Involvements
Ensure the X-axis title is not cut off. Increase bottom padding / grid bottom margin (e.g., set grid bottom to ~20–25%).
Ensure the X-axis title is not cut off. Increase bottom padding / grid bottom margin (e.g., set grid bottom to ~20–25%).
Use dark background
Bars should be light yellow
Axis title font size must be 14px