AAChartModel / AAChartKit

📈📊🚀🚀🚀An elegant modern declarative data visualization chart framework for iOS, iPadOS and macOS. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types. 极其精美而又强大的现代化声明式数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
https://cocoapods.org/pods/AAChartKit
MIT License
4.71k stars 751 forks source link

Live update of AAChartTypeLine with two AASeriesElement #1478

Open SamH2022 opened 1 year ago

SamH2022 commented 1 year ago

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 IMG_789B0C851E75-1

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