📜  amcharts angular universal - TypeScript (1)

📅  最后修改于: 2023-12-03 15:13:19.057000             🧑  作者: Mango

AmCharts Angular Universal - TypeScript

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.

Getting Started

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>
Creating Charts with AmCharts

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}"
Features

AmCharts Angular Universal provides a wide range of features to help you create powerful, interactive charts and graphs:

  • Seamless integration with Angular Universal for server-side rendering
  • Provides a set of Angular components and directives for displaying charts in your templates
  • Complete support for the AmCharts library, with all chart types and options available
  • Provides a simple and easy-to-use API for creating and configuring charts in your TypeScript code
  • Support for data-driven charts with real-time updates
  • Built-in support for a wide range of data formats, including JSON, CSV, and XML
  • Flexible and powerful chart layout options, with support for full-screen and fixed-size charts
  • Advanced data visualization features, including annotations, custom user interface elements, and dynamic backgrounds
Conclusion

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.