Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何默认选中折线图某个点 #1532

Closed
yl3066882156 opened this issue Jan 24, 2024 · 2 comments
Closed

如何默认选中折线图某个点 #1532

yl3066882156 opened this issue Jan 24, 2024 · 2 comments

Comments

@yl3066882156
Copy link

yl3066882156 commented Jan 24, 2024

WeChat95ef8ea5a7ae1e4d26770ae196ff4c16
WeChatcd1bf61b274dc4e5f9043c199347bf9d
第一张图是设计图,第二张时我添加的marker,以下是代码片段

//折线数组,多条线就增加元素
    NSMutableArray *series = [[NSMutableArray alloc]init];
    [self.temperatureDataSourceArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
        NSArray *array = obj;
        
        NSMutableArray *dataSource = [[NSMutableArray alloc]init];
        dataSource = array.mutableCopy;
        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
           
            CGFloat num = [[NSString stringWithFormat:@"%@", obj] floatValue];
            if (idx == array.count - 1) {
                
                AADataElement *singleSpecialData = AADataElement.new
                .markerSet(AAMarker.new
                           .lineColorSet(idx == 0 ? @"#0DBAFE" : @"#7DDAFF")//外边框颜色
                           .lineWidthSet(@5)//边框宽度
                           .fillColorSet(idx == 0 ? @"#0DBAFE" : @"#7DDAFF")//中心填充色
                           .radiusSet(@5)/*半径*/
                           )
                .ySet([NSNumber numberWithFloat:num]);
                
                [dataSource  replaceObjectAtIndex:idx withObject:singleSpecialData];
            }
        }];
        
        //折线数据1
        AASeriesElement *element1 = AASeriesElement.new
            .lineWidthSet(@2)
            .statesSet(AAStates.new
                       .hoverSet(AAHover.new
                                 .enabledSet(true)
                                 //手指盘旋或选中图表时,禁止线条变粗
                                 .lineWidthPlusSet(@0)))
            .markerSet(AAMarker.new
                       .radiusSet(@0)
                       .symbolSet(AAChartSymbolTypeCircle)
                       .statesSet(AAMarkerStates.new
                                  .hoverSet(AAMarkerHover.new
//                                            .enabledSet(false)
                                            .lineColorSet(idx == 0 ?@"#0DBAFE" : @"#7DDAFF")//外边框颜色
                                            .lineWidthSet(@5)//边框宽度
                                            .fillColorSet(idx == 0 ?@"#0DBAFE" : @"#7DDAFF")//中心填充色
                                            .radiusSet(@5)/*半径*/)))
            .dataSet(dataSource);
        
        //折线数组,多条线就增加元素
        [series addObject:element1];
        
    }];

但是我滑动时,添加的marker是不会消失的,还是半径5,怎么在滑动时,让他消失,也就是默认选中某个点,而不是我这样手动加上这个点,最终呈现这样的
WechatIMG19

@AAChartModel
Copy link
Owner

AAChartModel commented Jan 29, 2024

参考 demo 中的如下配置示例, 运行查看交互效果:

//https://api.highcharts.com/highcharts/plotOptions.series.marker.states.hover
//https://api.highcharts.com/highcharts/plotOptions.series.events.mouseOver
//https://api.highcharts.com/class-reference/Highcharts.Point#select
//https://github.com/AAChartModel/AAChartKit/issues/1532
+ (AAOptions *)defaultSelectedAPointForLineChart {
    AADataElement *defaultPointData = AADataElement.new
        .ySet(@29.9)
        .selectedSet(@true);

    NSArray *dataArr = @[@29.9, @71.5, @106.4, @129.2, @144.0, @176.0, @135.6, @148.5, @216.4, @194.1, @95.6, defaultPointData];
    NSInteger defaultPointIndex = dataArr.count - 1;

    AAOptions *options = AAOptions.new
        .xAxisSet(AAXAxis.new
            .categoriesSet(@[@"Jan", @"Feb", @"Mar", @"Apr", @"May", @"Jun", @"Jul", @"Aug", @"Sep", @"Oct", @"Nov", @"Dec"]))
        .plotOptionsSet(AAPlotOptions.new
            .seriesSet(AASeries.new
                .eventsSet(AASeriesEvents.new
                    .mouseOverSet([NSString stringWithFormat:@AAJSFunc(function () {
                        if(this.hasRun) return;

                        var series = this;
                        var defaultPointIndex = %ld;
                        if (series.data.length > defaultPointIndex) {
                            defaultPoint = series.data[defaultPointIndex];
                            defaultPoint.select(false);
                        }

                        this.hasRun = true;
                    }), (long)defaultPointIndex]))
                .allowPointSelectSet(@true)
                .markerSet(AAMarker.new
                    .statesSet(AAMarkerStates.new
                        .selectSet(AAMarkerSelect.new
                            .fillColorSet(@"red")
                            .lineWidthSet(@10)
                            .lineColorSet(@"yellow")
                            .radiusSet(@20))))))
        .seriesSet(@[
            AASeriesElement.new
                .dataSet(dataArr)
        ]);

    return options;
}

@AAChartModel
Copy link
Owner

  1. 想要查看以上的配置内容, 需要下载最新 demo 代码.
  2. 想要在你的项目中使用以上配置的话, 需要更新 AAChartKitpod 库.
    参考:

AAChartModel added a commit to AAChartModel/AAChartKit-Swift that referenced this issue Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants