Líneas de cuadrícula de eje Angular
Todos los gráficos Ignite UI for Angular incluyen la capacidad incorporada para modificar la apariencia de las líneas de los ejes, así como la frecuencia de las líneas de cuadrícula principales/menores y las marcas de verificación que se representan en los ejes X e Y.
the following examples can be applied to IgxCategoryChartComponent as well as IgxFinancialChartComponent controls.
Las líneas de cuadrícula del eje principal son líneas largas que se extienden horizontalmente a lo largo del eje Y o verticalmente a lo largo del eje X desde las ubicaciones de las etiquetas de los ejes y se representan en el área de trazado del gráfico. Las líneas de cuadrícula del eje menor son líneas que se representan entre las líneas de cuadrícula del eje mayor.
Las marcas de graduación de los ejes se muestran a lo largo de todos los ejes horizontales y verticales en cada etiqueta en todas las posiciones de línea principales del gráfico Angular.
Angular Axis Gridlines Example
Este ejemplo muestra cómo configurar la línea de cuadrícula del eje para mostrar líneas de cuadrícula mayores y menores en intervalos específicos:
EXAMPLE
DATA
MODULES
TS
HTML
SCSS
export class CountryRenewableElectricityItem {
public constructor (init: Partial<CountryRenewableElectricityItem> ) {
Object .assign(this , init);
}
public year: string ;
public europe: number ;
public china: number ;
public america: number ;
}
export class CountryRenewableElectricity extends Array <CountryRenewableElectricityItem > {
public constructor (items: Array <CountryRenewableElectricityItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new CountryRenewableElectricityItem(
{
year : `2009` ,
europe : 34 ,
china : 21 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2010` ,
europe : 43 ,
china : 26 ,
america : 24
}),
new CountryRenewableElectricityItem(
{
year : `2011` ,
europe : 66 ,
china : 29 ,
america : 28
}),
new CountryRenewableElectricityItem(
{
year : `2012` ,
europe : 69 ,
china : 32 ,
america : 26
}),
new CountryRenewableElectricityItem(
{
year : `2013` ,
europe : 58 ,
china : 47 ,
america : 38
}),
new CountryRenewableElectricityItem(
{
year : `2014` ,
europe : 40 ,
china : 46 ,
america : 31
}),
new CountryRenewableElectricityItem(
{
year : `2015` ,
europe : 78 ,
china : 50 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2016` ,
europe : 13 ,
china : 90 ,
america : 52
}),
new CountryRenewableElectricityItem(
{
year : `2017` ,
europe : 78 ,
china : 132 ,
america : 50
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2019` ,
europe : 80 ,
china : 96 ,
america : 38
}),
];
super (...newItems.slice(0 ));
}
}
}
ts コピー import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { CommonModule } from "@angular/common" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { IgxPropertyEditorPanelModule } from 'igniteui-angular-layouts' ;
import { IgxLegendModule, IgxCategoryChartModule } from 'igniteui-angular-charts' ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxPropertyEditorPanelModule,
IgxLegendModule,
IgxCategoryChartModule
],
providers : [],
schemas : []
})
export class AppModule {}
ts コピー import { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core' ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, LegendDescriptionModule, CategoryChartDescriptionModule } from 'igniteui-angular-core' ;
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity' ;
import { IgxLegendComponent, IgxCategoryChartComponent } from 'igniteui-angular-charts' ;
import { IgxPropertyEditorPanelComponent, IgxPropertyEditorPropertyDescriptionComponent } from 'igniteui-angular-layouts' ;
import { defineAllComponents } from 'igniteui-webcomponents' ;
defineAllComponents();
@Component ({
standalone : false ,
selector : "app-root" ,
styleUrls : ["./app.component.scss" ],
templateUrl : "./app.component.html" ,
changeDetection : ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild ("legend" , { static : true } )
private legend: IgxLegendComponent
@ViewChild ("propertyEditorPanel1" , { static : true } )
private propertyEditorPanel1: IgxPropertyEditorPanelComponent
@ViewChild ("xAxisStroke" , { static : true } )
private xAxisStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("xAxisMajorStroke" , { static : true } )
private xAxisMajorStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("yAxisStroke" , { static : true } )
private yAxisStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("yAxisMajorStroke" , { static : true } )
private yAxisMajorStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("yAxisMinorStroke" , { static : true } )
private yAxisMinorStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("chart" , { static : true } )
private chart: IgxCategoryChartComponent
private _countryRenewableElectricity: CountryRenewableElectricity = null ;
public get countryRenewableElectricity (): CountryRenewableElectricity {
if (this ._countryRenewableElectricity == null )
{
this ._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this ._countryRenewableElectricity;
}
private _componentRenderer: ComponentRenderer = null ;
public get renderer (): ComponentRenderer {
if (this ._componentRenderer == null ) {
this ._componentRenderer = new ComponentRenderer();
var context = this ._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
LegendDescriptionModule.register(context);
CategoryChartDescriptionModule.register(context);
}
return this ._componentRenderer;
}
public constructor (private _detector: ChangeDetectorRef )
{
}
public ngAfterViewInit(): void
{
}
}
ts コピー <div class ="container vertical sample" >
<div class ="options vertical" >
<igx-property-editor-panel
[componentRenderer ]="renderer"
[target ]="chart"
descriptionType ="CategoryChart"
isHorizontal ="true"
isWrappingEnabled ="true"
name ="propertyEditorPanel1"
#propertyEditorPanel1 >
<igx-property-editor-property-description
propertyPath ="XAxisStroke"
name ="XAxisStroke"
#xAxisStroke
label ="X Axis Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="gray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="XAxisMajorStroke"
name ="XAxisMajorStroke"
#xAxisMajorStroke
label ="X Axis Major Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="darkslategray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="YAxisStroke"
name ="YAxisStroke"
#yAxisStroke
label ="Y Axis Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="gray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="YAxisMajorStroke"
name ="YAxisMajorStroke"
#yAxisMajorStroke
label ="Y Axis Major Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="darkslategray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="YAxisMinorStroke"
name ="YAxisMinorStroke"
#yAxisMinorStroke
label ="Y Axis Minor Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="gray" >
</igx-property-editor-property-description >
</igx-property-editor-panel >
</div >
<div class ="legend-title" >
Renewable Electricity Generated
</div >
<div class ="legend" >
<igx-legend
name ="legend"
#legend
orientation ="Horizontal" >
</igx-legend >
</div >
<div class ="container fill" >
<igx-category-chart
name ="chart"
#chart
computedPlotAreaMarginMode ="Series"
[dataSource ]="countryRenewableElectricity"
includedProperties ="year, europe, china, america"
chartType ="Line"
[legend ]="legend"
isHorizontalZoomEnabled ="false"
isVerticalZoomEnabled ="false"
xAxisStroke ="rgba(145, 145, 145, 1)"
xAxisStrokeThickness ="2"
xAxisInterval ="1"
xAxisMajorStroke ="rgba(71, 71, 71, 1)"
xAxisMajorStrokeThickness ="0.5"
yAxisStroke ="gray"
yAxisStrokeThickness ="2"
yAxisInterval ="20"
yAxisMajorStroke ="darkslategray"
yAxisMajorStrokeThickness ="1"
yAxisMinorInterval ="5"
yAxisMinorStroke ="gray"
yAxisMinorStrokeThickness ="0.5"
thickness ="2" >
</igx-category-chart >
</div >
</div >
html コピー
Like this sample? Get access to our complete Ignite UI for Angular toolkit and start building your own apps in minutes. Download it for free.
Angular Axis Gridlines Properties
Establecer la propiedad de intervalo de eje especifica con qué frecuencia se representan las principales líneas de cuadrícula y etiquetas de eje en un eje. De manera similar, la propiedad de intervalo menor del eje especifica con qué frecuencia se representan las líneas de cuadrícula menores en un eje.
Para mostrar líneas de cuadrícula menores que corresponden a intervalos menores, debe configurar las propiedades xAxisMinorStroke
y xAxisMinorStrokeThickness
en el eje. Esto se debe a que las líneas de cuadrícula menores no tienen un color o grosor predeterminado y no se mostrarán sin asignarlas primero.
Puede personalizar cómo se muestran las líneas de cuadrícula en su gráfico Angular configurando las siguientes propiedades:
Con respecto al intervalo mayor y menor en la tabla anterior, es importante tener en cuenta que el intervalo mayor para las etiquetas de los ejes también se establecerá según este valor, mostrando una etiqueta en el punto del eje asociado con el intervalo. Las líneas de la cuadrícula del intervalo menor siempre se representan entre las líneas de la cuadrícula principal y, como tal, las propiedades del intervalo menor siempre deben establecerse en algo mucho más pequeño (generalmente entre 2 y 5 veces más pequeño) que el valor de las propiedades del intervalo mayor.
En los ejes de categorías, los intervalos se representan como un índice entre el primer elemento y el último elemento de categoría. Generalmente, este valor debe ser igual al 10-20% del número total de elementos de categoría para el intervalo principal, de modo que todas las etiquetas de los ejes encajen en el eje y no queden recortadas por otras etiquetas de ejes. Para intervalos menores, esto se representa como una fracción de las propiedades del intervalo mayor. Este valor generalmente debe estar entre 0,25 y 0,5.
En los ejes numéricos, los valores del intervalo se representan como un doble entre el valor mínimo del eje y el valor máximo del eje. De forma predeterminada, los ejes numéricos calcularán automáticamente y encontrarán un intervalo agradable y redondo basado en los valores mínimos y máximos del eje.
En los ejes de fecha y hora, este valor se representa como un lapso de tiempo entre el valor mínimo del eje y el valor máximo del eje.
El siguiente ejemplo demuestra cómo personalizar las líneas de la cuadrícula configurando las propiedades anteriores:
EXAMPLE
DATA
MODULES
TS
HTML
SCSS
export class CountryRenewableElectricityItem {
public constructor (init: Partial<CountryRenewableElectricityItem> ) {
Object .assign(this , init);
}
public year: string ;
public europe: number ;
public china: number ;
public america: number ;
}
export class CountryRenewableElectricity extends Array <CountryRenewableElectricityItem > {
public constructor (items: Array <CountryRenewableElectricityItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new CountryRenewableElectricityItem(
{
year : `2009` ,
europe : 34 ,
china : 21 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2010` ,
europe : 43 ,
china : 26 ,
america : 24
}),
new CountryRenewableElectricityItem(
{
year : `2011` ,
europe : 66 ,
china : 29 ,
america : 28
}),
new CountryRenewableElectricityItem(
{
year : `2012` ,
europe : 69 ,
china : 32 ,
america : 26
}),
new CountryRenewableElectricityItem(
{
year : `2013` ,
europe : 58 ,
china : 47 ,
america : 38
}),
new CountryRenewableElectricityItem(
{
year : `2014` ,
europe : 40 ,
china : 46 ,
america : 31
}),
new CountryRenewableElectricityItem(
{
year : `2015` ,
europe : 78 ,
china : 50 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2016` ,
europe : 13 ,
china : 90 ,
america : 52
}),
new CountryRenewableElectricityItem(
{
year : `2017` ,
europe : 78 ,
china : 132 ,
america : 50
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2019` ,
europe : 80 ,
china : 96 ,
america : 38
}),
];
super (...newItems.slice(0 ));
}
}
}
ts コピー import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { CommonModule } from "@angular/common" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { IgxPropertyEditorPanelModule } from 'igniteui-angular-layouts' ;
import { IgxLegendModule, IgxCategoryChartModule } from 'igniteui-angular-charts' ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxPropertyEditorPanelModule,
IgxLegendModule,
IgxCategoryChartModule
],
providers : [],
schemas : []
})
export class AppModule {}
ts コピー import { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core' ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, LegendDescriptionModule, CategoryChartDescriptionModule } from 'igniteui-angular-core' ;
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity' ;
import { IgxLegendComponent, IgxCategoryChartComponent } from 'igniteui-angular-charts' ;
import { IgxPropertyEditorPanelComponent, IgxPropertyEditorPropertyDescriptionComponent } from 'igniteui-angular-layouts' ;
import { defineAllComponents } from 'igniteui-webcomponents' ;
defineAllComponents();
@Component ({
standalone : false ,
selector : "app-root" ,
styleUrls : ["./app.component.scss" ],
templateUrl : "./app.component.html" ,
changeDetection : ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild ("legend" , { static : true } )
private legend: IgxLegendComponent
@ViewChild ("propertyEditorPanel1" , { static : true } )
private propertyEditorPanel1: IgxPropertyEditorPanelComponent
@ViewChild ("xAxisStroke" , { static : true } )
private xAxisStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("xAxisMajorStroke" , { static : true } )
private xAxisMajorStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("yAxisStroke" , { static : true } )
private yAxisStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("yAxisMajorStroke" , { static : true } )
private yAxisMajorStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("yAxisMinorStroke" , { static : true } )
private yAxisMinorStroke: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("chart" , { static : true } )
private chart: IgxCategoryChartComponent
private _countryRenewableElectricity: CountryRenewableElectricity = null ;
public get countryRenewableElectricity (): CountryRenewableElectricity {
if (this ._countryRenewableElectricity == null )
{
this ._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this ._countryRenewableElectricity;
}
private _componentRenderer: ComponentRenderer = null ;
public get renderer (): ComponentRenderer {
if (this ._componentRenderer == null ) {
this ._componentRenderer = new ComponentRenderer();
var context = this ._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
LegendDescriptionModule.register(context);
CategoryChartDescriptionModule.register(context);
}
return this ._componentRenderer;
}
public constructor (private _detector: ChangeDetectorRef )
{
}
public ngAfterViewInit(): void
{
}
}
ts コピー <div class ="container vertical sample" >
<div class ="options vertical" >
<igx-property-editor-panel
[componentRenderer ]="renderer"
[target ]="chart"
descriptionType ="CategoryChart"
isHorizontal ="true"
isWrappingEnabled ="true"
name ="propertyEditorPanel1"
#propertyEditorPanel1 >
<igx-property-editor-property-description
propertyPath ="XAxisStroke"
name ="XAxisStroke"
#xAxisStroke
label ="X Axis Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="gray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="XAxisMajorStroke"
name ="XAxisMajorStroke"
#xAxisMajorStroke
label ="X Axis Major Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="darkslategray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="YAxisStroke"
name ="YAxisStroke"
#yAxisStroke
label ="Y Axis Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="gray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="YAxisMajorStroke"
name ="YAxisMajorStroke"
#yAxisMajorStroke
label ="Y Axis Major Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="darkslategray" >
</igx-property-editor-property-description >
<igx-property-editor-property-description
propertyPath ="YAxisMinorStroke"
name ="YAxisMinorStroke"
#yAxisMinorStroke
label ="Y Axis Minor Stroke"
shouldOverrideDefaultEditor ="true"
valueType ="EnumValue"
dropDownNames ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
dropDownValues ="gray, darkslategray, salmon, cornflowerblue, darkgreen"
primitiveValue ="gray" >
</igx-property-editor-property-description >
</igx-property-editor-panel >
</div >
<div class ="legend-title" >
Renewable Electricity Generated
</div >
<div class ="legend" >
<igx-legend
name ="legend"
#legend
orientation ="Horizontal" >
</igx-legend >
</div >
<div class ="container fill" >
<igx-category-chart
name ="chart"
#chart
computedPlotAreaMarginMode ="Series"
[dataSource ]="countryRenewableElectricity"
includedProperties ="year, europe, china, america"
chartType ="Line"
[legend ]="legend"
isHorizontalZoomEnabled ="false"
isVerticalZoomEnabled ="false"
xAxisStroke ="rgba(145, 145, 145, 1)"
xAxisStrokeThickness ="2"
xAxisInterval ="1"
xAxisMajorStroke ="rgba(71, 71, 71, 1)"
xAxisMajorStrokeThickness ="0.5"
yAxisStroke ="gray"
yAxisStrokeThickness ="2"
yAxisInterval ="20"
yAxisMajorStroke ="darkslategray"
yAxisMajorStrokeThickness ="1"
yAxisMinorInterval ="5"
yAxisMinorStroke ="gray"
yAxisMinorStrokeThickness ="0.5"
thickness ="2" >
</igx-category-chart >
</div >
</div >
html コピー
Los ejes de IgxDataChartComponent
también tienen la capacidad de colocar una matriz de guiones en las líneas de cuadrícula mayor y menor utilizando las propiedades majorStrokeDashArray
y minorStrokeDashArray
, respectivamente. La línea del eje real también puede ser discontinua configurando la propiedad strokeDashArray
del eje correspondiente. Estas propiedades toman una serie de números que describirán la longitud de los guiones de las líneas de cuadrícula correspondientes.
El siguiente ejemplo demuestra un IgxDataChartComponent
con las propiedades de matriz de guiones establecidas anteriormente:
EXAMPLE
DATA
MODULES
TS
HTML
SCSS
export class CountryRenewableElectricityItem {
public constructor (init: Partial<CountryRenewableElectricityItem> ) {
Object .assign(this , init);
}
public year: string ;
public europe: number ;
public china: number ;
public america: number ;
}
export class CountryRenewableElectricity extends Array <CountryRenewableElectricityItem > {
public constructor (items: Array <CountryRenewableElectricityItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new CountryRenewableElectricityItem(
{
year : `2009` ,
europe : 34 ,
china : 21 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2010` ,
europe : 43 ,
china : 26 ,
america : 24
}),
new CountryRenewableElectricityItem(
{
year : `2011` ,
europe : 66 ,
china : 29 ,
america : 28
}),
new CountryRenewableElectricityItem(
{
year : `2012` ,
europe : 69 ,
china : 32 ,
america : 26
}),
new CountryRenewableElectricityItem(
{
year : `2013` ,
europe : 58 ,
china : 47 ,
america : 38
}),
new CountryRenewableElectricityItem(
{
year : `2014` ,
europe : 40 ,
china : 46 ,
america : 31
}),
new CountryRenewableElectricityItem(
{
year : `2015` ,
europe : 78 ,
china : 50 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2016` ,
europe : 13 ,
china : 90 ,
america : 52
}),
new CountryRenewableElectricityItem(
{
year : `2017` ,
europe : 78 ,
china : 132 ,
america : 50
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2019` ,
europe : 80 ,
china : 96 ,
america : 38
}),
];
super (...(newItems.slice(0 , items)));
}
}
}
ts コピー import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { CommonModule } from "@angular/common" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { IgxLegendModule, IgxDataChartCategoryModule, IgxDataChartInteractivityModule } from 'igniteui-angular-charts' ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxLegendModule,
IgxDataChartCategoryModule,
IgxDataChartInteractivityModule
],
providers : [],
schemas : []
})
export class AppModule {}
ts コピー import { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core' ;
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity' ;
import { IgxLegendComponent, IgxDataChartComponent, IgxCategoryXAxisComponent, IgxNumericYAxisComponent, IgxLineSeriesComponent } from 'igniteui-angular-charts' ;
@Component ({
standalone : false ,
selector : "app-root" ,
styleUrls : ["./app.component.scss" ],
templateUrl : "./app.component.html" ,
changeDetection : ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild ("legend" , { static : true } )
private legend: IgxLegendComponent
@ViewChild ("chart" , { static : true } )
private chart: IgxDataChartComponent
@ViewChild ("xAxis" , { static : true } )
private xAxis: IgxCategoryXAxisComponent
@ViewChild ("yAxis" , { static : true } )
private yAxis: IgxNumericYAxisComponent
@ViewChild ("lineSeries1" , { static : true } )
private lineSeries1: IgxLineSeriesComponent
@ViewChild ("lineSeries2" , { static : true } )
private lineSeries2: IgxLineSeriesComponent
@ViewChild ("lineSeries3" , { static : true } )
private lineSeries3: IgxLineSeriesComponent
private _countryRenewableElectricity: CountryRenewableElectricity = null ;
public get countryRenewableElectricity (): CountryRenewableElectricity {
if (this ._countryRenewableElectricity == null )
{
this ._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this ._countryRenewableElectricity;
}
public constructor (private _detector: ChangeDetectorRef )
{
}
public ngAfterViewInit(): void
{
}
}
ts コピー <div class ="container vertical sample" >
<div class ="legend-title" >
Renewable Electricity Generated
</div >
<div class ="legend" >
<igx-legend
name ="Legend"
#legend
orientation ="Horizontal" >
</igx-legend >
</div >
<div class ="container fill" >
<igx-data-chart
name ="chart"
#chart
[legend ]="legend"
computedPlotAreaMarginMode ="Series" >
<igx-category-x-axis
name ="xAxis"
#xAxis
[dataSource ]="countryRenewableElectricity"
label ="year"
interval ="1"
majorStroke ="rgba(71, 71, 71, 1)"
majorStrokeThickness ="0.5"
stroke ="rgba(145, 145, 145, 1)"
strokeThickness ="2"
strokeDashArray ="5, 5"
majorStrokeDashArray ="5, 5"
tickLength ="0" >
</igx-category-x-axis >
<igx-numeric-y-axis
name ="yAxis"
#yAxis
stroke ="gray"
strokeThickness ="2"
interval ="20"
majorStroke ="darkslategray"
majorStrokeThickness ="1"
minorInterval ="5"
minorStroke ="gray"
minorStrokeThickness ="0.5"
strokeDashArray ="5, 5"
majorStrokeDashArray ="5, 5"
minorStrokeDashArray ="2.5, 2.5"
tickLength ="0" >
</igx-numeric-y-axis >
<igx-line-series
name ="LineSeries1"
#lineSeries1
title ="Europe"
[xAxis ]="xAxis"
[yAxis ]="yAxis"
markerType ="Circle"
[dataSource ]="countryRenewableElectricity"
valueMemberPath ="europe"
showDefaultTooltip ="true" >
</igx-line-series >
<igx-line-series
name ="LineSeries2"
#lineSeries2
title ="China"
[xAxis ]="xAxis"
[yAxis ]="yAxis"
markerType ="Circle"
[dataSource ]="countryRenewableElectricity"
valueMemberPath ="china"
showDefaultTooltip ="true" >
</igx-line-series >
<igx-line-series
name ="LineSeries3"
#lineSeries3
title ="America"
[xAxis ]="xAxis"
[yAxis ]="yAxis"
markerType ="Circle"
[dataSource ]="countryRenewableElectricity"
valueMemberPath ="america"
showDefaultTooltip ="true" >
</igx-line-series >
</igx-data-chart >
</div >
</div >
html コピー
Angular Axis Tickmarks Example
Las marcas de graduación del eje se habilitan estableciendo las propiedades xAxisTickLength
y yAxisTickLength
en un valor mayor que 0. Estas propiedades especifican la longitud de los segmentos de línea que forman las marcas de graduación.
Las marcas de graduación siempre se extienden desde la línea del eje y apuntan a la dirección de las etiquetas. Las etiquetas están compensadas por el valor de la longitud de las marcas para evitar superposiciones. Por ejemplo, con la propiedad yAxisTickLength
establecida en 5, las etiquetas de los ejes se desplazarán hacia la izquierda en esa cantidad.
El siguiente ejemplo demuestra cómo personalizar las marcas configurando las propiedades anteriores:
EXAMPLE
DATA
MODULES
TS
HTML
SCSS
export class CountryRenewableElectricityItem {
public constructor (init: Partial<CountryRenewableElectricityItem> ) {
Object .assign(this , init);
}
public year: string ;
public europe: number ;
public china: number ;
public america: number ;
}
export class CountryRenewableElectricity extends Array <CountryRenewableElectricityItem > {
public constructor (items: Array <CountryRenewableElectricityItem> | number = -1 ) {
if (Array .isArray(items)) {
super (...items);
} else {
const newItems = [
new CountryRenewableElectricityItem(
{
year : `2009` ,
europe : 34 ,
china : 21 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2010` ,
europe : 43 ,
china : 26 ,
america : 24
}),
new CountryRenewableElectricityItem(
{
year : `2011` ,
europe : 66 ,
china : 29 ,
america : 28
}),
new CountryRenewableElectricityItem(
{
year : `2012` ,
europe : 69 ,
china : 32 ,
america : 26
}),
new CountryRenewableElectricityItem(
{
year : `2013` ,
europe : 58 ,
china : 47 ,
america : 38
}),
new CountryRenewableElectricityItem(
{
year : `2014` ,
europe : 40 ,
china : 46 ,
america : 31
}),
new CountryRenewableElectricityItem(
{
year : `2015` ,
europe : 78 ,
china : 50 ,
america : 19
}),
new CountryRenewableElectricityItem(
{
year : `2016` ,
europe : 13 ,
china : 90 ,
america : 52
}),
new CountryRenewableElectricityItem(
{
year : `2017` ,
europe : 78 ,
china : 132 ,
america : 50
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2018` ,
europe : 40 ,
china : 134 ,
america : 34
}),
new CountryRenewableElectricityItem(
{
year : `2019` ,
europe : 80 ,
china : 96 ,
america : 38
}),
];
super (...newItems.slice(0 ));
}
}
}
ts コピー import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { CommonModule } from "@angular/common" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { IgxPropertyEditorPanelModule } from 'igniteui-angular-layouts' ;
import { IgxLegendModule, IgxCategoryChartModule } from 'igniteui-angular-charts' ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
CommonModule,
FormsModule,
IgxPropertyEditorPanelModule,
IgxLegendModule,
IgxCategoryChartModule
],
providers : [],
schemas : []
})
export class AppModule {}
ts コピー import { AfterViewInit, Component, ViewChild, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core' ;
import { ComponentRenderer, PropertyEditorPanelDescriptionModule, LegendDescriptionModule, CategoryChartDescriptionModule } from 'igniteui-angular-core' ;
import { CountryRenewableElectricityItem, CountryRenewableElectricity } from './CountryRenewableElectricity' ;
import { IgxLegendComponent, IgxCategoryChartComponent } from 'igniteui-angular-charts' ;
import { IgxPropertyEditorPanelComponent, IgxPropertyEditorPropertyDescriptionComponent } from 'igniteui-angular-layouts' ;
import { defineAllComponents } from 'igniteui-webcomponents' ;
defineAllComponents();
@Component ({
standalone : false ,
selector : "app-root" ,
styleUrls : ["./app.component.scss" ],
templateUrl : "./app.component.html" ,
changeDetection : ChangeDetectionStrategy.OnPush
})
export class AppComponent implements AfterViewInit
{
@ViewChild ("legend" , { static : true } )
private legend: IgxLegendComponent
@ViewChild ("propertyEditorPanel1" , { static : true } )
private propertyEditorPanel1: IgxPropertyEditorPanelComponent
@ViewChild ("xAxisTickLength" , { static : true } )
private xAxisTickLength: IgxPropertyEditorPropertyDescriptionComponent
@ViewChild ("chart" , { static : true } )
private chart: IgxCategoryChartComponent
private _countryRenewableElectricity: CountryRenewableElectricity = null ;
public get countryRenewableElectricity (): CountryRenewableElectricity {
if (this ._countryRenewableElectricity == null )
{
this ._countryRenewableElectricity = new CountryRenewableElectricity();
}
return this ._countryRenewableElectricity;
}
private _componentRenderer: ComponentRenderer = null ;
public get renderer (): ComponentRenderer {
if (this ._componentRenderer == null ) {
this ._componentRenderer = new ComponentRenderer();
var context = this ._componentRenderer.context;
PropertyEditorPanelDescriptionModule.register(context);
LegendDescriptionModule.register(context);
CategoryChartDescriptionModule.register(context);
}
return this ._componentRenderer;
}
public constructor (private _detector: ChangeDetectorRef )
{
}
public ngAfterViewInit(): void
{
}
}
ts コピー <div class ="container vertical sample" >
<div class ="options vertical" >
<igx-property-editor-panel
[componentRenderer ]="renderer"
[target ]="chart"
descriptionType ="CategoryChart"
isHorizontal ="true"
isWrappingEnabled ="true"
name ="propertyEditorPanel1"
#propertyEditorPanel1 >
<igx-property-editor-property-description
propertyPath ="XAxisTickLength"
name ="XAxisTickLength"
#xAxisTickLength
label ="X Axis Tick Length"
shouldOverrideDefaultEditor ="true"
valueType ="Slider"
min ="0"
max ="20"
primitiveValue ="10" >
</igx-property-editor-property-description >
</igx-property-editor-panel >
</div >
<div class ="legend-title" >
Renewable Electricity Generated
</div >
<div class ="legend" >
<igx-legend
name ="legend"
#legend
orientation ="Horizontal" >
</igx-legend >
</div >
<div class ="container fill" >
<igx-category-chart
name ="chart"
#chart
[dataSource ]="countryRenewableElectricity"
includedProperties ="year, europe, china, america"
[legend ]="legend"
chartType ="Line"
computedPlotAreaMarginMode ="Series"
isHorizontalZoomEnabled ="false"
isVerticalZoomEnabled ="false"
xAxisTickLength ="10"
xAxisTickStrokeThickness ="1"
xAxisTickStroke ="gray"
yAxisTickLength ="0"
yAxisTickStrokeThickness ="0"
yAxisTickStroke ="rgba(0, 0, 0, 0)" >
</igx-category-chart >
</div >
</div >
html コピー
Angular Axis Tickmarks Properties
Puedes personalizar cómo se muestran las marcas de graduación del eje en nuestros chats Angular configurando las siguientes propiedades:
Additional Resources
Puede encontrar más información sobre las funciones de gráficos relacionadas en estos temas:
API References
La siguiente es una lista de miembros de API mencionados en las secciones anteriores: