All Ignite UI for Web Components charts include options to configure many axis layout options such as location as well as having the ability to share axis between series or have multiple axes in the same chart. These features are demonstrated in the examples given below.
the following examples can be applied to IgcCategoryChartComponent as well as IgcFinancialChartComponent controls.
Axis Locations Example
For all axes, you can specify axis location in relationship to chart plot area. The xAxisLabelLocation property of the Web Components charts, allows you to position x-axis line and its labels on above or below plot area. Similarly, you can use the yAxisLabelLocation property to position y-axis on left side or right side of plot area.
The following example depicts the amount of renewable electricity produced since 2009, represented by a Line Chart. There is a drop-down that lets you configure the yAxisLabelLocation so that you can visualize what the axes look like when the labels are placed on the left or right side on the inside or outside of the chart's plot area.
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample"><divclass="options vertical"><igc-property-editor-paneldescription-type="CategoryChart"is-horizontal="true"is-wrapping-enabled="false"name="propertyEditorPanel1"id="propertyEditorPanel1"><igc-property-editor-property-descriptionproperty-path="YAxisLabelLocation"name="YAxisLabelLocation"id="YAxisLabelLocation"label="Y Axis - Label Location"primitive-value="OutsideRight"></igc-property-editor-property-description></igc-property-editor-panel></div><divclass="legend-title">
Renewable Electricity Generated
</div><divclass="legend"><igc-legendname="legend"id="legend"orientation="Horizontal"></igc-legend></div><divclass="container fill"><igc-category-chartname="chart"id="chart"computed-plot-area-margin-mode="Series"included-properties="year, europe, china, america"chart-type="Line"y-axis-title="Labels Location"is-horizontal-zoom-enabled="false"is-vertical-zoom-enabled="false"x-axis-interval="1"y-axis-label-location="OutsideRight"></igc-category-chart></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
Axis Advanced Scenarios
For more advanced axis layout scenarios, you can use Web Components Data Chart to share axis, add multiple y-axis and/or x-axis in the same plot area, or even cross axes at specific values. The following examples show how to use these features of the IgcDataChartComponent.
Axis Sharing Example
You can share and add multiple axes in the same plot area of the Web Components IgcDataChartComponent. It a common scenario to use share IgcTimeXAxisComponent and add multiple IgcNumericYAxisComponent to plot many data sources that have wide range of values (e.g. stock prices and stock trade volumes).
The following example depicts a stock price and trade volume chart with a Stock Chart and a Column Chart plotted. In this case, the Y-Axis on the left is used by the Column Chart and the Y-Axis on the right is used by the Stock Chart, while the X-Axis is shared between the two.
EXAMPLE
DATA
TS
HTML
CSS
exportclassSharedAxisFinancialData{
publicstatic create(items?: number): any[] {
// initial valueslet v = 10000;
let o = 500;
let h = Math.round(o + (Math.random() * 5));
let l = Math.round(o - (Math.random() * 5));
let c = Math.round(l + (Math.random() * (h - l)));
if (items === undefined) {
items = 400;
}
const today = newDate();
const end = newDate(today.getFullYear(), today.getMonth(), today.getDay());
let time = this.addDays(end, -items);
const data: any[] = [];
for (let i = 0; i < items; i++) {
const date = time.toDateString();
const label = this.getShortDate(time, false);
// adding new data item
data.push({"Time": time, "Date": date, "Label": label, "Close": c, "Open": o, "High": h, "Low": l, "Volume": v});
// generating new valuesconst mod = Math.random() - 0.49;
o = Math.round(o + (mod * 20));
o = Math.max(o, 500);
o = Math.min(o, 675);
v = Math.round(v + (mod * 500));
h = Math.round(o + (Math.random() * 5));
l = Math.round(o - (Math.random() * 5));
c = Math.round(l + (Math.random() * (h - l)));
time = this.addDays(time, 1);
}
return data;
}
publicstatic addDays(dt: Date, days: number): Date {
returnnewDate(dt.getTime() + days * 24 * 60 * 60 * 1000);
}
publicstatic getShortDate(dt: Date, showYear: boolean): string {
const months = [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
];
const ind = dt.getMonth();
const day = dt.getDay() + 1;
let label = months[ind] + " " + day;
if (showYear) {
label += " " + dt.getFullYear();
}
return label;
}
}
ts
<!DOCTYPE html><html><head><title>DataChartAxisSharing</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample"><igc-data-chartid="chart"width="100%"height="100%"is-horizontal-zoom-enabled="true"is-vertical-zoom-enabled="true"><igc-category-x-axisname="xAxisShared"label="Label"></igc-category-x-axis><igc-numeric-y-axisname="yAxisRight"label-location="OutsideRight"minimum-value="400"title="Stock Price ($)"maximum-value="700"></igc-numeric-y-axis><igc-numeric-y-axisname="yAxisLeft"label-location="OutsideLeft"minimum-value="5000"title="Trade Volume"maximum-value="45000"major-stroke-thickness="0"abbreviate-large-numbers="true"></igc-numeric-y-axis><igc-column-seriesname="volumeSeries"x-axis-name="xAxisShared"y-axis-name="yAxisLeft"value-member-path="Volume"></igc-column-series><igc-financial-price-seriesname="stockSeries"x-axis-name="xAxisShared"y-axis-name="yAxisRight"display-type="Candlestick"high-member-path="High"low-member-path="Low"close-member-path="Close"open-member-path="Open"></igc-financial-price-series></igc-data-chart></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Axis Crossing Example
In addition to placing axes outside plot area, the Web Components IgcDataChartComponent also provides options to position axes inside of plot area and make them cross at specific values. For example, you can create trigonometric chart by setting crossingAxis and crossingValue properties on both x-axis and y-axis to render axis lines and axis labels such that they are crossing at (0, 0) origin point.
The following example shows a Sin and Cos wave represented by a Scatter Spline Chart with the X and Y axes crossing each other at the (0, 0) origin point.
EXAMPLE
TS
HTML
CSS
// data chart's modules:import { IgcDataChartCoreModule, IgcDataChartScatterModule, IgcDataChartScatterCoreModule, IgcDataChartInteractivityModule,
IgcDataChartComponent, IgcLegendComponent, IgcNumericXAxisComponent, IgcNumericYAxisComponent } from'igniteui-webcomponents-charts';
import { ModuleManager } from'igniteui-webcomponents-core';
ModuleManager.register(
IgcDataChartCoreModule,
IgcDataChartScatterModule,
IgcDataChartScatterCoreModule,
IgcDataChartInteractivityModule,
);
exportclassDataChartAxisCrossing{
private chart: IgcDataChartComponent;
private xAxis: IgcNumericXAxisComponent;
private yAxis: IgcNumericYAxisComponent;
private xAxisCrossLabel: HTMLLabelElement;
private yAxisCrossLabel: HTMLLabelElement;
private data: any[] = [];
constructor() {
this.onXAxisSliderChanged = this.onXAxisSliderChanged.bind(this);
this.onYAxisSliderChanged = this.onYAxisSliderChanged.bind(this);
this.initData();
this.chart = document.getElementById('chart') as IgcDataChartComponent;
this.xAxis = document.getElementById("xAxis") as IgcNumericXAxisComponent;
this.yAxis = document.getElementById("yAxis") as IgcNumericYAxisComponent;
this.xAxis.crossingAxis = this.yAxis;
this.yAxis.crossingAxis = this.xAxis;
this.xAxisCrossLabel = document.getElementById("xAxisCrossLabel") as HTMLLabelElement;
this.yAxisCrossLabel = document.getElementById("yAxisCrossLabel") as HTMLLabelElement;
const xAxisSlider = document.getElementById("xAxisCrossingSlider") as HTMLInputElement;
xAxisSlider.addEventListener("input", this.onXAxisSliderChanged);
const yAxisSlider = document.getElementById("yAxisCrossingSlider") as HTMLInputElement;
yAxisSlider.addEventListener("input", this.onYAxisSliderChanged);
this.chart.dataSource = this.data;
}
publicinitData() {
for (let i = -360; i <= 360; i += 10) {
const radians = (i * Math.PI) / 180;
const sin = Math.sin(radians);
const cos = Math.cos(radians);
this.data.push({ X: i, sinValue: sin, cosValue: cos });
}
}
publiconXAxisSliderChanged(e: any) {
const value = e.target.value;
this.yAxis.crossingValue = value;
this.xAxisCrossLabel.textContent = value;
}
publiconYAxisSliderChanged(e: any) {
const value = e.target.value;
this.xAxis.crossingValue = value;
this.yAxisCrossLabel.textContent = value;
}
}
new DataChartAxisCrossing();
ts
<!DOCTYPE html><html><head><title>DataChartAxisCrossing</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample"><divclass="options horizontal"><labelclass="option-label">X-Axis Crossing Value: </label><labelclass="options-value"id="xAxisCrossLabel">0</label><inputclass="options-slider"id="xAxisCrossingSlider"type="range"min="-360"max="360"step="10"value="0"/><labelclass="option-label">Y-Axis Crossing Value: </label><labelclass="options-value"id="yAxisCrossLabel">0</label><inputclass="options-slider"id="yAxisCrossingSlider"type="range"min="-1.25"max="1.25"step="0.125"value="0"/></div><divclass="container"style="height: calc(100% - 3rem)"><igc-data-chartid="chart"width="100%"height="100%"is-horizontal-zoom-enabled="true"is-vertical-zoom-enabled="true"plot-area-margin-bottom="60"plot-area-margin-top="60"plot-area-margin-left="30"plot-area-margin-right="30"><igc-numeric-x-axisid="xAxis"name="xAxis"interval="40"minimum-value="-360"maximum-value="360"label-location="InsideBottom"label-top-margin="10"crossing-axis-name="yAxis"crossing-value="0"stroke-thickness="1"stroke="Black"></igc-numeric-x-axis><igc-numeric-y-axisid="yAxis"name="yAxis"minimum-value="-1.25"maximum-value="1.25"interval="0.25"label-location="InsideLeft"label-right-margin="10"crossing-axis-name="xAxis"crossing-value="0"stroke-thickness="1"stroke="Black"></igc-numeric-y-axis><igc-scatter-spline-seriesx-axis-name="xAxis"y-axis-name="yAxis"marker-type="Circle"x-member-path="X"y-member-path="sinValue"></igc-scatter-spline-series><igc-scatter-spline-seriesx-axis-name="xAxis"y-axis-name="yAxis"marker-type="Circle"x-member-path="X"y-member-path="cosValue"></igc-scatter-spline-series></igc-data-chart><div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Additional Resources
You can find more information about related chart features in these topics: