Live update of AAChartTypeLine with two AASeriesElement
Hello, I have a line chart with two series elements. both series represent RSSI updates from BLE hardware every 1 second. Here's How I create the series: `AASeriesElement *sensorSeries = AASeriesElement.new; sensorSeries.name = @"Sensor"; sensorSeries.size = [NSNumber numberWithInt:15];
sensorSeries.data = @[@-10];
sensorSeries.colorSet([AAColor colorWithRed:224 green:64 blue:251 alpha:1]);//accent color
sensorSeries.dataLabelsSet(AAObject(AADataLabels)
.enabledSet(true)
.styleSet(AAObject(AAStyle)
.fontSizeSet(@"10")
.textOutlineSet(@"0px 0px contrast")
.colorSet([AAColor colorWithRed:224 green:64 blue:251 alpha:1])));
AASeriesElement *streamingSeries = AASeriesElement.new;
streamingSeries.name = @"Streaming";
streamingSeries.size = [NSNumber numberWithInt:15];
streamingSeries.data = @[@-10];
streamingSeries.colorSet([AAColor colorWithRed:40 green:173 blue:226 alpha:1]);//curious blue
streamingSeries.dataLabelsSet(AAObject(AADataLabels)
.enabledSet(true)
.styleSet(AAObject(AAStyle)
.fontSizeSet(@"10")
.textOutlineSet(@"0px 0px contrast")
.colorSet([AAColor colorWithRed:40 green:173 blue:226 alpha:1])));`
Added Both to the model then draw the chart as below:
self.aaChartModel = AAChartModel.new .chartTypeSet(AAChartTypeLine) .titleSet(@"RSSI data") //.subtitleSet(@"virtual data") .categoriesSet(@[@"1", @"2", @"3", @"4",@"5", @"6", @"7", @"8", @"9", @"10",@"11", @"12", @"13", @"14",@"15"]) //.yAxisTitleSet(@"y axis") .seriesSet(@[ sensorSeries, streamingSeries ]);
`self.aaChartModel.yAxisMin = [NSNumber numberWithInt:-100];
self.aaChartModel.yAxisMax = [NSNumber numberWithInt:-10];
self.aaChartModel.backgroundColor = @"black";
self.aaChartModel.xAxisLabelsStyleSet(AAObject(AAStyle).colorSet(AAColor.whiteColor));
self.aaChartModel.yAxisLabelsStyleSet(AAObject(AAStyle).colorSet(AAColor.whiteColor));
//draw with model
[self.aaChartView aa_drawChartWithChartModel:self.aaChartModel];`
When trying to update the chart with RSSI live data, it doesn't respect the series data size, the second series doesn't look right as it shrinks to the left and the chart clumps up if I keep it running for long time.
Using one series working fine though!!
Please check the attached picture
EDIT: update method: ` -(void)updateChart{ NSArray<AASeriesElement *> *series = self.aaChartModel.series;
//sensor
AASeriesElement *sensorSeries = [series objectAtIndex:0];
NSArray *sensorData = sensorSeries.data;
if(self.sensorRangingArray.count >= 15){
[self.sensorRangingArray removeObjectAtIndex:0];
}
sensorData = [self.sensorRangingArray copy];
sensorSeries.data = sensorData;
//streaming
AASeriesElement *streamingSeries = [series objectAtIndex:1];
NSArray *streamingData = streamingSeries.data;
if(self.streamingArray.count >= 15){
[self.streamingArray removeObjectAtIndex:0];
}
streamingData = [self.streamingArray copy];
streamingSeries.data = streamingData;
[self.aaChartView aa_onlyRefreshTheChartDataWithChartModelSeries:series];
}`
What I'm doing wrong? Thanks in advance for taking the time to look into it