Example controls guidance and components demo. For internal use only.
When creating examples, you may wish to add example controls. These can be used to show user interactions, code option changes, event code output, or for any other reason.
Below is a very simple guide on how to add controls to your examples, some best practice tips, and a demo of all currently available controls.
Container elements Copy Link
To add controls to your example, add the appropriate elements to your example’s index.html file.
All example controls should be wrapped in a div with an example-controls class. Each row of controls should be wrapped in a div with the controls-row class. Elements outside the example-controls will not receive any standard controls styling.
The chart element should sit outside the example-controls div.
<div class="style-guide example-controls">
<div class="controls-row">
<!-- Your example controls elements... -->
</div>
<div class="controls-row">
<!-- A second row of example controls elements.. -->
</div>
</div>
<div id="myChart"></div> Controls layout Copy Link
The controls-row div is a flexbox container. All elements within the controls-row div will lay out horizontally with a gap, and be vertically centred. Elements will wrap vertically within the controls row container.
There are four classes you can apply to elements within a controls row to manipulate the row layout. See below for examples of these classes in use.
The classes gap-left and gap-right can be added to create a gap on either side of the element to group elements within a row. Prefer gap-right for better wrapping within the row.
The classes push-left and push-right can be added to push an element to the far side of a row. For example, a “Reset” button can be pushed to the far right of the row to separate it from other controls.
Showing code Copy Link
If you want to show that a button or input is triggering a code change, you can wrap the relevant content with a <code> tag within the element.
<button onclick="myFunction()">Apply <code>'{ myValue: 30 }'</code></button> Showing state Copy Link
Where a control applies one of several mutually exclusive options, use a button group so the applied option stays visible. A button group is a set of radio inputs styled as a joined row of buttons — each input is immediately followed by its own label, and the checked input's label is highlighted.
<div class="button-group" role="group" aria-label="Rotation">
<input type="radio" id="auto" name="rotation" value="auto" checked onchange="rotationChange(event)" />
<label for="auto">Auto</label>
<input type="radio" id="fixed" name="rotation" value="fixed" onchange="rotationChange(event)" />
<label for="fixed">Fixed</label>
</div>Prefer a button group over a row of buttons that each apply a different value, and over a select where there are few enough options to show them all at once. Radio inputs are keyboard navigable with the arrow keys, and no script is needed to keep the highlight in sync.
A row can hold as many groups as it needs. Give each group its own name — inputs sharing a name form one set, so a repeated name makes two groups behave as one. Only split options across groups when they are separate controls. One set of mutually exclusive options belongs in a single group — split across two, each group shows a selection and implies both apply.
Where one group only applies while another has a particular value, wrap it in a disabled control-group fieldset and toggle disabled from the handler. The group keeps its own selection while disabled.
For a single option that is either on or off, use a button with aria-pressed. Update the attribute when the option changes.
<button aria-pressed="true" onclick="toggleTooltip(event)">Tooltip</button> Additional styles Copy Link
You should not need to apply any additional styles in an example’s styles.css file in order to style your example controls. CSS in styles.css should be reserved for code that is relevant to the function of the example.
If you need to use an input or element that’s not covered below, please speak to the website team and we can style new controls.
Example controls demo Copy Link
What to test:
- Every control variant (buttons, inputs, selects, code-wrapped buttons) renders with the standard styling.
gap-left,gap-right,push-leftandpush-rightclasses lay out as documented and wrap cleanly at narrow widths.- Controls remain vertically centred within their row at all viewport sizes.
- Button group segments share a single border, the checked segment is highlighted, and the arrow keys move the selection.
- Two groups in one row hold their selections independently, and a group inside a disabled
control-groupkeeps its own. - Disabled controls, disabled button group segments and disabled
control-groupfieldsets are all dimmed.
import { Component } from "@angular/core";
import { AgCharts } from "ag-charts-angular";
import {
AgChartOptions,
AllCommunityModule,
ModuleRegistry,
} from "ag-charts-community";
import { getData } from "./data";
ModuleRegistry.registerModules(AllCommunityModule);
@Component({
selector: "my-app",
standalone: true,
imports: [AgCharts],
template: `<div class="style-guide example-controls">
<div class="style-guide-item">
<code>p</code>
<p>I'm a paragraph.</p>
<p>I'm a paragraph with <code>some code</code></p>
</div>
<div class="style-guide-item">
<code>label</code>
<label>I'm a label</label>
</div>
<div class="style-guide-item">
<code>pre</code>
<pre>I'm a pre</pre>
</div>
<div class="style-guide-item">
<code>button</code>
<div class="controls-row">
<button>I'm a button</button>
<button>I'm a button with <code>some code</code></button>
</div>
</div>
<div class="style-guide-item">
<code>input type="submit"</code>
<input type="submit" value="I'm a submit input">
</div>
<div class="style-guide-item">
<code>input type="text"</code>
<input type="text" placeholder="I'm a text input">
</div>
<div class="style-guide-item">
<code>input type="checkbox"</code>
<div class="controls-row">
<label for="checked-c">I'm a checked checkbox with label:</label>
<input type="checkbox" id="checked-c" name="checked" checked="true">
<label for="unchecked-c">I'm an unchecked checkbox with label:</label>
<input type="checkbox" id="unchecked-c" name="unchecked">
</div>
</div>
<div class="style-guide-item">
<code>input type="radio"</code>
<div class="controls-row">
<label for="checked-r">I'm a checked radio button with label:</label>
<input type="radio" id="checked-r" name="radio" checked="true">
<label for="unchecked-r">I'm an unchecked radio button with label:</label>
<input type="radio" id="unchecked-r" name="radio">
</div>
</div>
<div class="style-guide-item">
<code>div class="button-group"</code>
<div class="controls-row">
<span>I'm a button group:</span>
<div class="button-group" role="group" aria-label="Button group">
<input type="radio" id="bg-alpha" name="button-group" value="alpha" checked="">
<label for="bg-alpha">Alpha</label>
<input type="radio" id="bg-beta" name="button-group" value="beta">
<label for="bg-beta">Beta</label>
<input type="radio" id="bg-gamma" name="button-group" value="gamma">
<label for="bg-gamma">Gamma</label>
</div>
</div>
<div class="controls-row">
<span>I'm a button group containing code:</span>
<div class="button-group" role="group" aria-label="Button group with code">
<input type="radio" id="bg-code-left" name="button-group-code" value="left" checked="">
<label for="bg-code-left"><code>'left'</code></label>
<input type="radio" id="bg-code-center" name="button-group-code" value="center">
<label for="bg-code-center"><code>'center'</code></label>
<input type="radio" id="bg-code-right" name="button-group-code" value="right">
<label for="bg-code-right"><code>'right'</code></label>
</div>
</div>
<div class="controls-row">
<span>I'm a button group with a disabled option:</span>
<div class="button-group" role="group" aria-label="Button group with a disabled option">
<input type="radio" id="bg-disabled-on" name="button-group-disabled" value="on" checked="">
<label for="bg-disabled-on">Available</label>
<input type="radio" id="bg-disabled-off" name="button-group-disabled" value="off" disabled="">
<label for="bg-disabled-off">Unavailable</label>
</div>
</div>
<div class="controls-row">
<span>I'm two button groups in one row:</span>
<div class="button-group gap-right" role="group" aria-label="First button group">
<input type="radio" id="bg-first-one" name="button-group-first" value="one" checked="">
<label for="bg-first-one">One</label>
<input type="radio" id="bg-first-two" name="button-group-first" value="two">
<label for="bg-first-two">Two</label>
</div>
<div class="button-group" role="group" aria-label="Second button group">
<input type="radio" id="bg-second-three" name="button-group-second" value="three">
<label for="bg-second-three">Three</label>
<input type="radio" id="bg-second-four" name="button-group-second" value="four" checked="">
<label for="bg-second-four">Four</label>
</div>
</div>
<div class="controls-row">
<fieldset class="control-group" disabled="">
<span>I'm a button group in a disabled control-group:</span>
<div class="button-group" role="group" aria-label="Button group in a disabled control group">
<input type="radio" id="bg-fieldset-selected" name="button-group-fieldset" value="selected" checked="">
<label for="bg-fieldset-selected">Selected</label>
<input type="radio" id="bg-fieldset-other" name="button-group-fieldset" value="other">
<label for="bg-fieldset-other">Other</label>
</div>
</fieldset>
</div>
</div>
<div class="style-guide-item">
<code>button aria-pressed</code>
<div class="controls-row">
<button aria-pressed="true">I'm a pressed toggle button</button>
<button aria-pressed="false">I'm an unpressed toggle button</button>
</div>
</div>
<div class="style-guide-item">
<code>disabled</code>
<div class="controls-row">
<button disabled="">I'm a disabled button</button>
<select disabled="">
<option value="Alpha">I'm a disabled select</option>
</select>
<input type="text" placeholder="I'm a disabled text input" disabled="">
<input type="checkbox" disabled="">
</div>
<div class="controls-row">
<fieldset class="control-group" disabled="">
<label for="disabled-group-range">I'm a disabled control-group:</label>
<input type="range" id="disabled-group-range" min="0" max="10" step="1" value="5">
<span>5</span>
</fieldset>
</div>
</div>
<div class="style-guide-item">
<code>input type="number"</code>
<div class="controls-row">
<label for="number">I'm a number input with label:</label>
<input type="number" id="number" value="999">
</div>
</div>
<div class="style-guide-item">
<code>input type="range"</code>
<div class="controls-row">
<label for="number">I'm a range input (slider) with label: </label>
<input type="range" min="0" max="10" step="1" value="5">
</div>
</div>
<div class="style-guide-item">
<code>textarea</code>
<textarea placeholder="I'm a textarea"></textarea>
</div>
<div class="style-guide-item">
<code>select</code>
<label for="select">I'm a select with a label:</label>
<select name="select" id="select">
<option value="Alpha">Alpha</option>
<option value="Beta">Beta</option>
<option value="Gamma">Alpha</option>
</select>
</div>
<div class="style-guide-item">
<code>div class="controls-row"</code>
<div class="controls-row">
<button>Wrap</button>
<button>With</button>
<button>Row</button>
<label for="">To Vertically Center</label>
<button>Items</button>
</div>
</div>
<div class="style-guide-item">
<code>div class="controls-row center"</code>
<div class="controls-row center">
<button>Center</button>
<button>The</button>
<button>Row</button>
</div>
</div>
<div class="style-guide-item">
<code>button class="push-right"</code>
<div class="controls-row">
<button>Push</button>
<label>An item to the </label>
<button class="push-right">Right</button>
</div>
</div>
<div class="style-guide-item">
<code>button class="gap-left"</code>
<div class="controls-row">
<button>Add</button>
<button>A</button>
<button class="gap-left">Gap</button>
<label for="">To the left of the item</label>
</div>
</div>
</div>
<ag-charts
[options]="options"
></ag-charts>
`,
})
export class AppComponent {
public options;
constructor() {
this.options = {
title: {
text: "Apple's Revenue by Product Category",
},
subtitle: {
text: "In Billion U.S. Dollars",
},
data: getData(),
series: [
{
type: "bar",
xKey: "quarter",
yKey: "iphone",
yName: "iPhone",
},
{
type: "bar",
xKey: "quarter",
yKey: "mac",
yName: "Mac",
},
{
type: "bar",
xKey: "quarter",
yKey: "ipad",
yName: "iPad",
},
{
type: "bar",
xKey: "quarter",
yKey: "wearables",
yName: "Wearables",
},
{
type: "bar",
xKey: "quarter",
yKey: "services",
yName: "Services",
},
],
};
}
}