我正在尝试向 chartXY 添加点数组,但图表未正确绘制。Y 值看起来很适合 Axis,但 x 值不是。该系列像一条线一样出现在图表的中间。
生成图表并添加点的代码如下:
this.chart1 = lightningChart().ChartXY({ containerId: this.chartId1, defaultAxisXTickStrategy: AxisTickStrategies.Numeric })
.setBackgroundFillStyle(new SolidFill({color: ColorHEX( '#C6C2C1' )}))
.setChartBackgroundFillStyle(new SolidFill({color: ColorHEX( '#FFFFFF' )}))
.setTitle('LightningCharts 1')
.setTitleFillStyle(new SolidFill({color: ColorHEX( '#000000' )}));
// Fijo las propiedades del eje y
this.chart1.getDefaultAxisY()
.setTitle('mV')
.setScrollStrategy(AxisScrollStrategies.fitting)
.setAnimationScroll(false)
.fit(true)
.setAnimationZoom(undefined)
.setTitleFillStyle(new SolidFill({color: ColorHEX( '#000000' )}))
.setTickStyle(new VisibleTicks({ labelFillStyle: new SolidFill({ color: ColorHEX('#000000')}), tickLength: 20 }));
// Fijo las propiedades del eje x
this.chart1.getDefaultAxisX()
.setTitle('milliseconds')
.setScrollStrategy(AxisScrollStrategies.fitting)
.setAnimationScroll(false)
.fit(true)
.setAnimationZoom(undefined)
.setTitleFillStyle(new SolidFill({color: ColorHEX( '#000000' )}))
.setTickStyle(new VisibleTicks({ labelFillStyle: new SolidFill({ color: ColorHEX('#000000')}) }));
// Añado las series al chart
// tslint:disable-next-line:max-line-length
this.lineSeries1 = this.chart1.addPointLineSeries({ dataPattern: DataPatterns.horizontalProgressive, xAxis: this.chart1.getDefaultAxisX() })
.setName('Serie 1')
.setStrokeStyle( new SolidLine({
thickness: 2,
fillStyle: new SolidFill({ color: ColorHEX( '#E72B1C' ) })
}))
.setMouseInteractions(false);
this.lineSeries1.add(this.points);
我用这段代码生成的点数组:
this.points = [];
// const sign = Math.floor(Math.random() * (1 + 1)) === 0 ? -1 : 1;
const firstX = Date.now();
for (let i = 0; i < 4000; i++) {
const point = {
x: firstX + (i * 1000),
y: Math.floor(Math.random() * (5000 + 1))
};
this.points.push(point);
}
如何查看适合 x 轴的数据?