angular - 条形图未显示在 angular2+
问题描述
我有一个用 angular2+ 和 node.js 编写的应用程序。我想要一个页面来显示图形和图表。所以我从下拉列表中获取输入,然后将该选择发送到一个 http 请求,然后检索到一个像这里这样的变量 -
public barChartDataHighmark: any[] = [
{ data: [this.highmarkSuccessResult], label: 'Success' },
{ data: [this.highmarkErrorResult], label: 'Error' }
];
当我输入硬编码值时,条形图中的条出现,
例如 -
public barChartDataHighmark: any[] = [
{ data: [10,11,12], label: 'Success' },
{ data: [5,6,7], label: 'Error' }
];
但是当我将它设置为我的 http 请求的输出时,条不会出现。如何解决。
graphs.component.ts
viewHighmarkData(highmarkChoice) {
this.highmarkInterfaceNames = ['Highmark', 'Highmark Issue Request',
'Highmark Commercial Auth', 'Highmark Comm Issue Request'];
console.log("inside highmarkSuccess()");
var url = config.url;
var port = config.port;
this.highmarkSuccessChoice = {
'highmarkSuccess': highmarkChoice
}
this.http.post("http://" + url + ":" + port +
"/dashboard/highmarkSuccess/", this.highmarkSuccessChoice
, { headers: new Headers({ 'Authorization': 'Bearer ' +
localStorage.getItem('Token') }) })
.map(result => this.result = result.json(), )
.subscribe((res: Response) => {
// this.loading = false;
this.records = res;
console.log("xxxx view Highmark Success result data ",
this.result)
console.log("XXXXXXXXXXXX view Highmark Success res data ",
res);
this.highmarkSuccessResult = this.result.length;
console.log("this.highmarkSuccessResult = ",
this.highmarkSuccessResult)
});
console.log("inside viewHighmarkError()");
this.highmarkErrorChoice = {
'highmarkError': highmarkChoice
}
this.http.post("http://" + url + ":" + port +
"/dashboard/highmarkError/", this.highmarkErrorChoice
, { headers: new Headers({ 'Authorization': 'Bearer ' +
localStorage.getItem('Token') }) })
.map(result => this.result = result.json(), )
.subscribe((res: Response) => {
// this.loading = false;
this.records = res;
console.log("xxxx view Highmark Error result data ", this.result)
console.log("XXXXXXXXXXXX view Highmark Error res data ", res);
this.highmarkErrorResult = this.result.length;
console.log("this.highmarkErrorResult = ",
this.highmarkErrorResult)
});
}
组件.html
// Highmark BarChart
public barChartOptionsHighmark: any = {
scaleShowVerticalLines: false,
responsive: true
};
public barChartLabelsHighmark: string[] = ['Success', 'Error'];
public barChartTypeHighmark = 'bar';
public barChartLegendHighmark = true;
public barChartDataHighmark: any[] = [
{ data: [this.highmarkSuccessResult], label: 'Success' },
{ data: [this.highmarkErrorResult], label: 'Error' }
];
解决方案
推荐阅读
- c# - 使用 System.Text.Json 通过私有设置器反序列化属性
- c++ - Gtkmm 窗口是空白的,没有显示任何小部件或标题
- c# - 如何构建可查询以从数据库列中查找字符串数组的所有单词
- node.js - http 发布到“https”url 的主体是否在 HTTP 飞镖颤振包中或一般情况下被加密?不知道怎么问这个问题,请看下面的简要说明
- json - (预)处理存储在 json 中的大型数据集的最有效方法是什么?
- vuetify.js - 使用 v-checkbox Vuetify v-list - v-model 无法正常工作
- reactjs - 使用 React 传递动态 url
- python - Windows 10 上的 Python - 鼠标悬停时查找窗口名称
- python-2.7 - 列表理解:如果元素是同一列表中另一个元素的子字符串,则忽略该元素
- javascript - 从 .js 文件中获取数据