AAChartKit
AAChartKit copied to clipboard
同时设置了AAChartModel和AAOptions时,应该用哪个方法刷新数据?
定义全局变量:
AAChartModel *aaChartModel;
初始化时的代码:
aaChartModel = AAObject(AAChartModel)
.chartTypeSet(AAChartTypeColumn)//设置图表的类型
.categoriesSet(self.xArr)//图表横轴的内容
.zoomTypeSet(AAChartZoomTypeX)//允许x轴缩放
.yAxisLineWidthSet(0)//隐藏y轴
.yAxisMinSet(0)//设置y轴最小值为0
.seriesSet(@[
AAObject(AASeriesElement)
.nameSet(LocalizedString(@"里程"))
.dataSet(self.yArr)])
;
/*Custom Tooltip Style --- 自定义图表浮动提示框样式及内容*/
AAOptions *aaOptions = aaChartModel.aa_toAAOptions;
aaOptions.chart
.resetZoomButtonSet(AAResetZoomButton.new
.themeSet(@{
@"display":@"none"//隐藏图表缩放后的默认显示的缩放按钮
}));
//设置图例的属性
aaOptions.legend
.itemStyleSet(AAItemStyle.new
.colorSet(@"#555555")//字体颜色
.fontSizeSet(@"12px")//字体大小
.fontWeightSet(AAChartFontWeightTypeThin)//字体为细体字
);
AATooltip *tooltip = aaOptions.tooltip;
tooltip
.followTouchMoveSet(false)//单指滑动
.backgroundColorSet(AARgbaColor(255, 255, 255, 0.8))
.borderWidthSet(@0)
.styleSet(AAStyleColorSizeWeight(@"#333333", 12, AAChartFontWeightTypeThin))
;
[_aaChartView aa_drawChartWithOptions:aaOptions];
刷新时的代码:
aaChartModel.categoriesSet(self.xArr);
aaChartModel.seriesSet(@[
AAObject(AASeriesElement)
.nameSet(LocalizedString(@"里程"))
.dataSet(self.yArr)]);
[_aaChartView aa_refreshChartWithChartModel:aaChartModel];
数据刷新时x轴的数据也会变化,因此没法使用aa_onlyRefreshTheChartDataWithChartModelSeries方法,使用aa_refreshChartWithChartModel方法刷新,会使得之前设置的AAOptions失效,那么应该使用哪个方法刷新数据呢,还是说我初始化的代码写的有问题?感谢赐教!
目前的解决方法是把初始化方法一并放在数据刷新的地方,但是这样写肯定是不规范的,每次数据刷新都会重新初始化一遍
数据刷新时x轴的数据也会变化,因此没法使用aa_onlyRefreshTheChartDataWithChartModelSeries方法,
AAChartView 有专门更新 x 轴内容的下面👇 这个方法,
/// Update the X axis categories of chart
/// @param categories The X axis categories array
/// @param redraw Redraw whole chart or not
- (void)aa_updateXAxisCategories:(NSArray *)categories redraw:(BOOL)redraw;
你试试在调用 aa_onlyRefreshTheChartDataWithChartModelSeries 方法之前先调用这个 aa_updateXAxisCategories:redraw 方法, 注意 redraw 参数传 NO 。
看看是否可行。