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.72k stars 751 forks source link

请问 tooplip中point能否获取当前所在的索引,我需要根据索引从外部的数组中获取对应值显示到tooplip中 #1450

Closed Livjxbill993 closed 1 year ago

AAChartModel commented 1 year ago

参考相同问题:

AAChartModel commented 1 year ago

示例中的

    NSString *jsFormatterStr = [NSString stringWithFormat:@AAJSFunc(
function () {
    const 总时长数组 = %@;
    const 有效时长数组 = %@;
    const 看近时长数组 = %@;
    const 看中时长数组 = %@;
    const 看远时长数组 = %@;
    const 切换次数数组 = %@;
    const 停止次数数组 = %@;
    const 干预次数数组 = %@;
    const 时间单位后缀 = "min<br/>";
    const 频率单位后缀 = "次<br/>";

    const selectedSeries = this.points[0];
    const pointIndex = selectedSeries.point.index;
    const 单个总时长字符串 = "总时长: &nbsp &nbsp" + 总时长数组[pointIndex] + 时间单位后缀;
    const 单个有效时长字符串 = "有效时长: &nbsp" + 有效时长数组[pointIndex] + 时间单位后缀;
    const 单个看近时长字符串 = "看近时长: &nbsp" + 看近时长数组[pointIndex] + 时间单位后缀;
    const 单个看中时长字符串 = "看中时长: &nbsp" + 看中时长数组[pointIndex] + 时间单位后缀;
    const 单个看远时长字符串 = "看远时长: &nbsp" + 看远时长数组[pointIndex] + 时间单位后缀;
    const 单个切换次数字符串 = "切换次数: &nbsp" + 切换次数数组[pointIndex] + 频率单位后缀;
    const 单个停止次数字符串 = "停止次数: &nbsp" + 停止次数数组[pointIndex] + 频率单位后缀;
    const 单个干预次数字符串 = "干预次数: &nbsp" + 干预次数数组[pointIndex] + 频率单位后缀;

    const wholeContentStr =  单个总时长字符串 + 单个有效时长字符串 + 单个看近时长字符串 + 单个看中时长字符串 + 单个看远时长字符串 + 单个切换次数字符串 + 单个停止次数字符串 + 单个干预次数字符串;

    return wholeContentStr;
    }),总时长JS数组, 有效时长JS数组, 看近时长JS数组, 看中时长JS数组, 看远时长JS数组, 切换次数JS数组, 停止次数JS数组, 干预次数JS数组];

其中的

    const selectedSeries = this.points[0];
    const pointIndex = selectedSeries.point.index;

这个 pointIndex 应该就是你想要的.

AAChartModel commented 1 year ago

我需要根据索引从外部的数组中获取对应值显示到tooplip中

此示例正是为了实现这种需求.

AAChartModel commented 1 year ago
   aaOptions.tooltip
    //‼️以 this.point.index 这种方式获取选中的点的索引必须设置 tooltip 的 shared 为 false
    //‼️共享时是 this.points (由多个 point 组成的 points 数组)
    //‼️非共享时是 this.point 单个 point 对象
    .sharedSet(true)
    .useHTMLSet(true)
    .formatterSet(jsFormatterStr)
    .backgroundColorSet(AAColor.blackColor)//黑色背景色
    .borderColorSet(@"#FFD700")//边缘颜色纯金色
    .styleSet(AAStyleColorSize(@"#FFD700", 12))//文字颜色纯金色
    ;

注意这段示例代码中的 ‼️ 标注的注释内容.

//‼️以 this.point.index 这种方式获取选中的点的索引必须设置 tooltip 的 shared 为 false //‼️共享时是 this.points (由多个 point 组成的 points 数组) //‼️非共享时是 this.point 单个 point 对象

AAChartModel commented 1 year ago

AATooltipformatter 属性, 详细内容参考:

AAChartModel commented 1 year ago

另外参考饼图的相同需求示例:

参考其他相关问题:

AAChartModel commented 1 year ago

参考相同问题:

demo 中有此完整示例, 下载运行查看即可.

Livjxbill993 commented 1 year ago

谢谢!解决了