我正在尝试使用角度绘制直方图。以下jsfiddle链接仅供参考。我试图为角度直方图高图创建一个系列对象,以匹配示例中显示的对象。我当前的代码给我一个错误,无法设置undefined的属性名称。在for循环中的第一个属性赋值中发生此错误。有些人可以告诉我哪里出错了吗
http://jsfiddle.net/x51b6pvs/52/
我的角色代码
chartSeries:any [];
this.results[0].data = [3.5, 3, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3.4, 3, 3, 4, 4.4, 3.9, 3.5, 3.8, 3.8, 3.4, 3.7, 3.6, 3.3, 3.4, 3, 3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.6, 3, 3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3, 3.8, 3.2, 3.7, 3.3, 3.2, 3.2, 3.1, 2.3, 2.8, 2.8, 3.3, 2.4, 2.9, 2.7, 2, 3, 2.2, 2.9, 2.9, 3.1, 3, 2.7, 2.2, 2.5, 3.2, 2.8, 2.5, 2.8, 2.9, 3, 2.8, 3, 2.9, 2.6, 2.4, 2.4, 2.7, 2.7, 3, 3.4, 3.1, 2.3, 3, 2.5, 2.6, 3, 2.6, 2.3, 2.7, 3, 2.9, 2.9, 2.5, 2.8, 3.3, 2.7, 3, 2.9, 3, 3, 2.5, 2.9, 2.5, 3.6, 3.2, 2.7, 3, 2.5, 2.8, 3.2, 3, 3.8, 2.6, 2.2, 3.2, 2.8, 2.8, 2.7, 3.3, 3.2, 2.8, 3, 2.8, 3, 2.8, 3.8, 2.8, 2.8, 2.6, 3, 3.4, 3.1, 3, 3.1, 3.1, 3.1, 2.7, 3.2, 3.3, 3, 2.5, 3, 3.4, 3];
this.results[1].data = [4.5, 4, 5.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 5.7, 3.4, 3, 3, 4, 4.4, 3.9, 3.5, 3.8, 3.8, 5.4, 3.7, 3.6, 3.3, 3.4, 3, 3.4, 3.5, 3.4, 3.2, 3.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2.8, 3.3, 2.7, 3, 2.9, 3, 3, 2.5, 2.9, 2.5, 3.6, 3.2, 2.7, 3, 2.5, 2.8, 3.2, 3, 3.8, 2.6, 2.2, 3.2, 2.8, 2.8, 2.7, 3.3, 3.2, 2.8, 3, 2.8, 3, 2.8, 3.8, 2.8, 2.8, 2.6, 7, 3.4, 8.1, 3, 6.1, 9.1, 3.1, 2.7, 3.2, 3.3, 3, 2.5, 3, 3.4, 3];
this.results[3].data = [4.5, 4, 5.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 5.7, 3.4, 3, 3, 4, 4.4, 3.9, 3.5, 3.8, 3.8, 5.4, 3.7, 3.6, 3.3, 3.4, 3, 3.4, 3.5, 3.4, 3.2, 3.1, 3.4, 4.1, 4.2, 3.1, 3.2, 3.5, 3.6, 3, 3.4, 3.5, 2.3, 3.2, 3.5, 3.8, 3, 3.8, 5.2, 3.7, 3.3, 3.2, 3.2, 3.1, 2.3, 2.8, 5.8, 3.3, 2.4, 2.9, 2.7, 2, 3, 2.2, 2.9, 5.9, 3.1, 3, 2.7, 2.2, 2.5, 3.2, 2.8, 5.5, 2.8, 2.9, 3, 2.8, 3, 2.9, 2.6, 2.4, 5.4, 2.7, 2.7, 3, 3.4, 3.1, 2.3, 3, 2.5, 2.6, 3, 2.6, 2.3, 2.7, 3, 2.9, 2.9, 2.5, 2.8, 5.3, 2.7, 3, 2.9, 3, 3, 2.5, 2.9, 2.5, 3.6, 5.2, 2.7, 3, 2.5, 7.8, 7.2, 3, 5.8, 5.6, 5.2, 3.2, 2.8, 2.8, 5.7, 6.3, 8.2, 2.8, 3, 5.8, 3, 2.8, 7.8, 8.8, 9.8, 4.6, 3, 8.4, 7.1, 8, 4.1, 3.1, 3.1, 2.7, 3.2, 3.3, 3, 2.5, 3, 3.4, 3];
for(let i=0; i<this.results.length; i++)
{
var objHistogram:any;
objHistogram.name="Histogram" + i;
objHistogram.type="histogram";
objHistogram.xAxis = 1;
objHistogram.yAxis = 1;
objHistogram.baseSeries="s"+i;
objHistogram.zIndex=-1;
var objectData:any;
objectData.name="Data" + i;
objectData.showInLegend= false;
objectData.data=this.results[i].data;
objectData.id="s"+i;
this.chartSeries[2*i]=objHistogram;
this.chartSeries[2*i+1]=objectData;
}
答案 0 :(得分:0)
我只想在一个声明中创建对象
// First, make the chartSeries an empty array
chartSeries: any[] = [];
for(let i=0; i<this.results.length; i++)
{
let objHistogram = {
name: "Histogram" + i,
type: "histogram",
xAxis: 1,
yAxis: 1,
baseSeries: "s"+i,
zIndex: -1
}
let objectData = {
name: "Data" + i,
showInLegend: false,
data: this.results[i].data,
id: "s"+i
};
// I dont know what you want the chartSeries array to look like, but you may as well just push onto the array.
this.chartSeries.push(objHistogram);
this.chartSeries.push(objectData);
}