Skip to content

Commit ffc68be

Browse files
committed
Adding legends to charts
1 parent fe10e41 commit ffc68be

File tree

6 files changed

+40
-12
lines changed

6 files changed

+40
-12
lines changed

projects/charts/bar-chart/src/bar-chart.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ export class BarChartSample extends LitElement {
4040
{ franchise: "James Bond", totalRevenue: 7.12, highestGrossing: 1.11 },
4141
];
4242

43+
firstUpdated() {
44+
const legendEl = this.renderRoot.querySelector('#legend') as any;
45+
const chartEl = this.renderRoot.querySelector('igc-data-chart') as any;
46+
chartEl.legend = legendEl;
47+
}
48+
4349
render() {
4450
configureTheme("fluent");
4551

@@ -53,11 +59,11 @@ export class BarChartSample extends LitElement {
5359
<div class="legend-title">Highest Grossing Movie Franchises</div>
5460
5561
<div class="legend">
56-
<igc-legend orientation="Horizontal" id="legend"></igc-legend>
62+
<igc-legend orientation="Horizontal" id="legend" name="legend"></igc-legend>
5763
</div>
5864
5965
<div class="chart-wrapper">
60-
<igc-data-chart width="100%" height="100%" legend="legend">
66+
<igc-data-chart width="100%" height="100%">
6167
<igc-category-y-axis
6268
name="yAxis"
6369
label="franchise"

projects/charts/line-chart/src/line-chart.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export class LineChart extends LitElement {
2727
{ year: "2019", europe: 80, china: 96, america: 38 },
2828
];
2929

30+
firstUpdated() {
31+
const legendEl = this.renderRoot.querySelector('#legend') as any;
32+
const chartEl = this.renderRoot.querySelector('igc-category-chart') as any;
33+
chartEl.legend = legendEl;
34+
}
35+
3036
render() {
3137
configureTheme("bootstrap");
3238

@@ -58,7 +64,6 @@ export class LineChart extends LitElement {
5864
yAxisTitleRightMargin="5"
5965
yAxisLabelLeftMargin="0"
6066
computedPlotAreaMarginMode="Series"
61-
legend="legend"
6267
>
6368
</igc-category-chart>
6469
</div>

projects/charts/pie-chart/src/pie-chart.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export class PieChartSample extends LitElement {
4141
) => {
4242
args.isExploded = !args.isExploded;
4343
};
44+
45+
// Adding legend to the first pie chart
46+
const legendEl = this.renderRoot.querySelector('#legend') as any;
47+
const chartEl = this.renderRoot.querySelector('#chart') as any;
48+
chartEl.legend = legendEl;
4449
}
4550

4651
render() {
@@ -59,11 +64,13 @@ export class PieChartSample extends LitElement {
5964
Global Electricity Demand by Energy Use
6065
</div>
6166
62-
<igc-item-legend
63-
id="legend"
64-
name="legend"
65-
orientation="Horizontal"
66-
></igc-item-legend>
67+
<div class="legend">
68+
<igc-item-legend
69+
id="legend"
70+
name="legend"
71+
orientation="Horizontal"
72+
></igc-item-legend>
73+
</div>
6774
6875
<div class="pie-chart">
6976
<igc-pie-chart

projects/charts/polar-chart/src/polar-chart.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export class PolarChart extends LitElement {
3737
{ direction: 360, boatSpeed: 70, windSpeed: 90 },
3838
];
3939

40+
firstUpdated() {
41+
const legendEl = this.renderRoot.querySelector('#legend') as any;
42+
const chartEl = this.renderRoot.querySelector('igc-data-chart') as any;
43+
chartEl.legend = legendEl;
44+
}
45+
4046
render() {
4147
configureTheme("fluent");
4248

@@ -59,7 +65,6 @@ export class PolarChart extends LitElement {
5965
height="100%"
6066
name="chart"
6167
id="chart"
62-
legend="legend"
6368
.dataSource=${this.boatSailingData}
6469
is-horizontal-zoom-enabled="false"
6570
is-vertical-zoom-enabled="false"

projects/charts/step-chart/src/step-chart.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export class StepChart extends LitElement {
2828
{ year: "2019", europe: 80, china: 96, america: 38 },
2929
];
3030

31+
firstUpdated() {
32+
const legendEl = this.renderRoot.querySelector('#legend') as any;
33+
const chartEl = this.renderRoot.querySelector('igc-category-chart') as any;
34+
chartEl.legend = legendEl;
35+
}
36+
3137
render() {
3238
configureTheme("material");
3339

@@ -47,7 +53,6 @@ export class StepChart extends LitElement {
4753
<igc-category-chart
4854
id="chart"
4955
.dataSource=${this.countryRenewableElectricity}
50-
legend="legend"
5156
chart-type="StepArea"
5257
title-alignment="Left"
5358
title-left-margin="25"

src/views/home/home-view.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115

116116
.sample-actions {
117117
display: flex;
118-
gap: 8px;
118+
gap: 16px;
119119
align-items: center;
120120
line-height: 100%;
121121
font-size: 14px;
@@ -127,7 +127,7 @@
127127
font-weight: 600;
128128
letter-spacing: 0.15px;
129129
height: 40px;
130-
padding-right: 8px;
130+
padding-right: 16px;
131131
border-right: 1px solid #D6D6D6;
132132
}
133133

0 commit comments

Comments
 (0)