没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:杨鹏连|2020-07-28 10:15:32.300|阅读 595 次
概述:在本教程中,我们将学习如何使用Firestore和官方的Highcharts Angular包装器可视化实时数据库更新。整个项目在此GitHub链接中。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Highcharts是一款纯JavaScript编写的图表库,为你的Web网站、Web应用程序提供直观、交互式图表。当前支持折线、曲线、区域、区域曲线图、柱形图、条形图、饼图、散点图、角度测量图、区域排列图、区域曲线排列图、柱形排列图、极坐标图等几十种图表类型。
在本教程中,我们将学习如何使用Firestore和官方的Highcharts Angular包装器可视化实时数据库更新。整个项目在此GitHub链接中。
我们将在本文中介绍以下几点:
1.要做的第一件事是创建一个项目,然后执行以下步骤:登录到//console.firebase.google.com
2.单击添加项目。
3.创建一个数据库。
4.选择“以测试模式启动”。
5.为数据库创建一个集合,使其具有多个文档来存储数据。
6.将文档添加到集合中。
7.将您的Angular应用名称添加到Firestore中。请确保选择“ Web”,因为我们目前正在使用Web 。
8.通过将Angular App Name注册到Firestore,我们将能够立即使用所有关键功能。

9.获取配置详细信息,然后firebaseConfig在angular应用程序中使用该对象。
使用Firestore设置Angular项目
要设置Angular项目,请按照此链接中的说明进行操作。
顺便说一句,创建完Angular项目后,请不要忘记运行以下命令,并说明执行该操作的原因:ng add @angular/fire
export const environment = {
production: false,
firebaseConfig: {
apiKey: "AIzaSyBaGUX7iwBRthIKOE_uhyzs1aPEuKPlEAE",
authDomain: "firestore-angular-highcharts.firebaseapp.com",
databaseURL: "//firestore-angular-highcharts.firebaseio.com",
projectId: "firestore-angular-highcharts",
storageBucket: "firestore-angular-highcharts.appspot.com",
messagingSenderId: "669023523724",
appId: "1:669023523724:web:43f04e6a2ce0a92c01fca9",
measurementId: "G-ZD6C3CEC85"
}
};
在此HighchartService中与Cloud Firestore API进行交互的最后一步(请参见下文):import {
Injectable
} from '@angular/core';
import {
Observable
} from 'rxjs';
import {
AngularFirestore,
AngularFirestoreCollection
} from "@angular/fire/firestore";
import {
map
} from "rxjs/operators";
@Injectable({
providedIn: 'root'
})
export class HighchartService {
private rateCollection: AngularFirestoreCollection < chartModal > ;
rates$: Observable < chartModal[] > ;
constructor(private readonly firestoreservice: AngularFirestore) {
this.rateCollection = firestoreservice.collection < chartModal > ('ChartData');
// .snapshotChanges() returns a DocumentChangeAction[], which contains
// a lot of information about "what happened" with each change. If you want to
// get the data and the id use the map operator.
this.rates$ = this.rateCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as chartModal;
const id = a.payload.doc.id;
return {
id,
...data
};
}))
);
}
}
export interface chartModal {
currency: string,
rate: number
}
将Highcharts与Angular和Firestore集成
为了使用Highcharts可视化我们项目上的数据更新,我们需要包含Highcharts Angular包装器。它允许我们访问highcharts库。是官方的角度包装器。要安装highcharts-angular和Highcharts库,只需运行以下指令:。要使用这些软件包,首先,必须导入它们。因此,在app.module.ts文件中,我们从highcharts-angular包中导入了模块。另外,我们导入并使用firebaseConfig(见下文):highchats-angular
npm install highcharts-angular highcharts
HighchartsChartModule
AngularFirestoreModuleinitializeApp
import {
BrowserModule
} from "@angular/platform-browser";
import {
NgModule
} from "@angular/core";
import {
HighchartsChartModule
} from "highcharts-angular";
import {
AppRoutingModule
} from "./app-routing.module";
import {
AppComponent
} from "./app.component";
import {
AngularFireModule
} from "@angular/fire";
import {
environment
} from "src/environments/environment";
import {
AngularFireAnalyticsModule
} from "@angular/fire/analytics";
import {
AngularFirestoreModule
} from "@angular/fire/firestore";
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
AppRoutingModule,
HighchartsChartModule,
AngularFireAnalyticsModule,
AngularFirestoreModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
让我们来看一下app.component.ts中的操作。
Highcharts从导入。从导入服务和模式。上,我们从文件存储数据库订阅的发光值,并推动新值数组,然后调用和初始化图表数据。import * as Highcharts from “highcharts”;
highchart.service
ngOnInit()chartdatagetChart()
import {
Component,
OnInit
} from "@angular/core";
import {
HighchartService,
chartModal
} from "./highchart.service";
import * as Highcharts from "highcharts";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"],
})
export class AppComponent implements OnInit {
title = "Firestore-Angular-Highcharts";
items$: chartModal[];
Highcharts: typeof Highcharts = Highcharts;
chardata: any[] = [];
chartOptions: any;
constructor(private highchartservice: HighchartService) {}
ngOnInit() {
this.highchartservice.rates$.subscribe((assets) => {
this.items$ = assets;
if (this.items$) {
this.items$.forEach((element) => {
this.chardata.push(element.rate);
});
this.getChart();
}
});
}
getChart() {
this.chartOptions = {
series: [{
data: this.chardata,
}, ],
chart: {
type: "bar",
},
title: {
text: "barchart",
},
};
}
}
该项目的最后一步是转到app.component.html添加指令和一些属性绑定以初始化图表数据和选项:highcharts-chart
[Highcharts]="Highcharts"
[options]="chartOptions"
style="width: 100%; height: 400px; display: block;">
</highcharts-chart>
如下面的GIF所示,条形图从Firebase上托管的数据库中获取数据。当使用Firebase UI将新值添加到数据库时,图表的数据将更新并显示。
同样,在下面的示例中,我们正在将具有新值的折线图绘制到同一折线图上。
好吧,就是这样。现在,您知道如何使用Firestore更新实时数据库,以及如何使用Highcharts可视化更新。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
文章转载自:



注意: Cogent DataHub 软件 v11 包含一些新功能,您的目标操作系统可能不支持这些功能。
本教程主要为大家介绍如何使用DevExpress WinForms数据网格控件进行数据排序的基础知识,欢迎下载最新版组件体验!
在使用Parasoft C/C++test执行BugDetective数据流分析时,可能会遇到用户自定义的资源API,那在这种情况下,若要判断是否存在资源问题,如资源泄露等,则需要手动配置测试配置。
大型SaaS系统的自动化测试常常受制于界面变化快、结构复杂、加载机制多变等因素。从元素识别到脚本管理,SmartBear TestComplete帮助Salesforce建了可靠的自动化测试体系。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
半岛外围网上直营 