Skip to content

Commit 375df59

Browse files
committed
Add show_legend option to chart component
1 parent 298d86c commit 375df59

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
657657
('color', 'The name of a color in which to display the chart. If there are multiple series in the chart, this parameter can be repeated multiple times.', 'COLOR', TRUE, TRUE),
658658
('stacked', 'Whether to cumulate values from different series.', 'BOOLEAN', TRUE, TRUE),
659659
('toolbar', 'Whether to display a toolbar at the top right of the chart, that offers downloading the data as CSV.', 'BOOLEAN', TRUE, TRUE),
660+
('show_legend', 'Whether to display the legend listing all chart series. Defaults to true.', 'BOOLEAN', TRUE, TRUE),
660661
('logarithmic', 'Display the y-axis in logarithmic scale.', 'BOOLEAN', TRUE, TRUE),
661662
('horizontal', 'Displays a bar chart with horizontal bars instead of vertical ones.', 'BOOLEAN', TRUE, TRUE),
662663
('height', 'Height of the chart, in pixels. By default: 250', 'INTEGER', TRUE, TRUE),
@@ -702,7 +703,7 @@ INSERT INTO example(component, description, properties) VALUES
702703
{"series": "Asia", "label": "China", "value": 20},
703704
{"series": "Asia", "label": "Japan", "value": 10}
704705
]')),
705-
('chart', 'A bar chart with multiple series.', json('[{"component":"chart", "title": "Expenses", "type": "bar", "stacked": true, "toolbar": true, "ystep": 10}, '||
706+
('chart', 'A bar chart with multiple series.', json('[{"component":"chart", "title": "Expenses", "type": "bar", "stacked": true, "toolbar": true, "show_legend": false, "ystep": 10}, '||
706707
'{"series": "Marketing", "x": 2021, "value": 35}, '||
707708
'{"series": "Marketing", "x": 2022, "value": 15}, '||
708709
'{"series": "Human resources", "x": 2021, "value": 30}, '||

sqlpage/apexcharts.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ sqlpage_chart = (() => {
155155
theme: {
156156
palette: "palette4",
157157
},
158+
legend: {
159+
show: data.show_legend !== false,
160+
},
158161
dataLabels: {
159162
enabled: !!data.labels,
160163
dropShadow: {

sqlpage/templates/chart.handlebars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"xmax": {{stringify xmax}},
3232
"ymax": {{stringify ymax}},
3333
"toolbar": {{stringify toolbar}},
34+
"show_legend": {{stringify show_legend}},
3435
"logarithmic": {{stringify logarithmic}},
3536
"horizontal": {{stringify horizontal}},
3637
"stacked": {{stringify stacked}},

tests/end-to-end/official-site.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ test("chart", async ({ page }) => {
2424
await expect(page.locator(".apexcharts-canvas").first()).toBeVisible();
2525
});
2626

27+
test("chart supports hiding legend", async ({ page }) => {
28+
await page.goto(`${BASE}/documentation.sql?component=chart#component`);
29+
30+
const expensesChart = page.locator(".card", {
31+
has: page.getByRole("heading", { name: "Expenses" }),
32+
});
33+
34+
await expect(expensesChart.locator(".apexcharts-canvas")).toBeVisible();
35+
await expect(expensesChart.locator(".apexcharts-legend")).toBeHidden();
36+
});
37+
2738
test("map", async ({ page }) => {
2839
await page.goto(`${BASE}/documentation.sql?component=map#component`);
2940
await expect(page.getByText("Loading...")).not.toBeVisible();

0 commit comments

Comments
 (0)