📅  最后修改于: 2023-12-03 15:13:19.057000             🧑  作者: Mango
AmCharts Angular Universal is a powerful tool for developing interactive, data-driven charts and graphs for use in web applications. This library provides a set of Angular components and directives for displaying charts created with the AmCharts library, and is designed to work seamlessly with Angular Universal for server-side rendering.
To use AmCharts Angular Universal, you first need to install the library and its dependencies:
npm install @amcharts/amcharts4 @amcharts/amcharts4-ngx --save
You can then import the AmCharts Angular Universal modules into your application:
import { AmChartsModule } from '@amcharts/amcharts4-ngx';
import { AmChartsAngularUniversalModule } from '@amcharts/amcharts4-ngx/angular-universal';
@NgModule({
declarations: [AppComponent],
imports: [
AmChartsModule.forRoot(),
AmChartsAngularUniversalModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
You can now use the AmCharts components and directives in your Angular templates:
<am4chart [chart]="chart"></am4chart>
To create a chart with AmCharts, you first need to define the chart configuration in TypeScript, using the am4core
namespace:
import * as am4core from '@amcharts/amcharts4/core';
import * as am4charts from '@amcharts/amcharts4/charts';
export class AppComponent {
chart: am4charts.XYChart;
constructor() {
this.chart = am4core.create('chartdiv', am4charts.XYChart);
// Define chart configuration here
}
}
You can then use the chart configuration to create a chart instance:
this.chart = am4core.create('chartdiv', am4charts.XYChart);
this.chart.data = [
{ date: new Date(2021, 0, 1), value: 100 },
{ date: new Date(2021, 0, 2), value: 120 },
{ date: new Date(2021, 0, 3), value: 140 },
{ date: new Date(2021, 0, 4), value: 160 },
{ date: new Date(2021, 0, 5), value: 180 },
{ date: new Date(2021, 0, 6), value: 200 }
];
let dateAxis = this.chart.xAxes.push(new am4charts.DateAxis());
let valueAxis = this.chart.yAxes.push(new am4charts.ValueAxis());
let series = this.chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = "value";
series.dataFields.dateX = "date";
series.tooltipText = "{value}"
AmCharts Angular Universal provides a wide range of features to help you create powerful, interactive charts and graphs:
AmCharts Angular Universal is a powerful tool for creating interactive charts and graphs in your web applications. With its seamless integration with Angular Universal and wide range of features, you can easily create dynamic and engaging data-driven visualizations that not only look great, but also provide valuable insights and information to your users.