【发布时间】:2019-07-22 16:07:53
【问题描述】:
我对 Angular 7 非常陌生。我在下面的代码行中遇到错误。我的代码有什么问题?
var x1 = 10, x2 = 100, x3 = datar.map(function (item) { return [ item.xmax ] })
.reduce(function(a, b) { return Math.max(a, b); }); //error
var y1 = 10, y2 = 100, y3 = datar.map(function (item) { return [ item.ymax ] })
.reduce(function(a, b) { return Math.max(a, b); }); //error
在上面的代码中我得到错误:number[] 类型的参数不能分配给number 类型的参数在'a,b'代码return Math.max(a, b)
var data = [ [0,0,0],[0,1,4],[0,2,1],[0,3,1]
,[1,0,0],[1,1,9],[1,2,4],[1,3,1]
,[2,0,0],[2,1,9],[2,2,9],[2,3,9]
,[3,0,0],[3,1,0],[3,2,0],[3,3,0] ];
data = data.map(function (item) { //error
return [item[1], item[0], item[2] || '-'];
});
在上面的代码中我得到错误:
Type (string | number)[][] is not assignable to type number[][].
在“数据”
var objseries = datar.map(function(x) {
return {
type: 'scatter',
symbol: 'diamond',
symbolSize: 10,
itemStyle:{
normal:{
color: x.color
}
},
data: x.data.map(function (item) {
return [
item[0] <= x1 ? 0 + ((item[0] - 0) / ((x1 - 0) / 100)) / 100 :
(item[0] <= x2 ? 1 + ((item[0] - x1) / ((x2 - x1) / 100)) / 100 :
(item[0] <= x3 ? 2 + ((item[0] - x2) / ((x3 - x2) / 100)) / 100 : 2)),//error
item[1] <= y1 ? 0 + ((item[1] - 0) / ((y1 - 0) / 100)) / 100 :
(item[1] <= y2 ? 1 + ((item[1] - y1) / ((y2 - y1) / 100)) / 100 :
(item[1] <= y3 ? 2 + ((item[1] - y2) / ((y3 - y2) / 100)) / 100 : 2)),//error
item[0], item[1]
];
}),
}
});
在上面的代码中我得到错误:
运算符'item[0] <= x3 ? 2 + ((item[0] - x2) / ((x3 - x2) / 100)) / 100 : 2))中'item[0]
和:
算术运算的左侧必须是代码“(x3-x2)”中的“any”、“number”、“bigint”或枚举类型at x3
已编辑
我在下面的代码中得到以下错误:
Type '(string | number)[][]' is not assignable to type 'number[][]'.
Type '(string | number)[]' is not assignable to type 'number[]'.
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.ts(2322)
chart.component.ts(77, 13): The expected type comes from property 'data' which is declared here on type '{ type: string; symbol: string; symbolSize: number; itemStyle: { normal: { color: string; }; }; data: number[][]; }'
var datar = [
{
name: 'TEST-A',
data: [
[4,4],[25,4],[700,4],[4,40],[25,40],[160,40]
],
xmax: 700,
ymax: 40,
color: 'purple',
},
{
name: 'TEST-B',
data: [
[10.0, 8.04],
[8.0, 6.95],
[13.0, 7.58],
[9.0, 8.81],
xmax: 160,
ymax: 400,
color: 'green',
}
];
var objseries = datar.map(function(x) {
return {
type: 'scatter',
symbol: 'diamond',
symbolSize: 10,
itemStyle:{
normal:{
color: x.color
}
},
data: x.data.map(function (item) {
return [
item[0] <= x1 ? 0 + ((item[0] - 0) / ((x1 - 0) / 100)) / 100 :
(item[0] <= x2 ? 1 + ((item[0] - x1) / ((x2 - x1) / 100)) / 100 :
(item[0] <= x3 ? 2 + ((item[0] - x2) / ((x3 - x2) / 100)) / 100 : 2)),
item[1] <= y1 ? 0 + ((item[1] - 0) / ((y1 - 0) / 100)) / 100 :
(item[1] <= y2 ? 1 + ((item[1] - y1) / ((y2 - y1) / 100)) / 100 :
(item[1] <= y3 ? 2 + ((item[1] - y2) / ((y3 - y2) / 100)) / 100 : 2)),
item[0], item[1]
];
}),
}
});
objseries.splice(0, 0, {
name: 'Severe Moderate Mild',
xAxisIndex : 1,
yAxisIndex : 1,
type: 'heatmap',
data: data, //error here
label: {
normal: {
show: false
}
}
});
然后,此代码将进入 'series' 属性 https://echarts.apache.org/examples/en/editor.html?c=doc-example/scatter-visualMap-categories&edit=1&reset=1 (此链接仅用于说明关系)
我该如何解决这个问题?
【问题讨论】:
标签: javascript angular typescript angular7