AAChartKit icon indicating copy to clipboard operation
AAChartKit copied to clipboard

iOS如何设置X轴滚动到最右边

Open siaschenbin opened this issue 9 months ago • 3 comments

.scrollablePlotAreaSet(
        AAScrollablePlotArea.new
        .minWidthSet([NSNumber numberWithFloat:maxX])
        .opacitySet(@1) //y轴透明度
        .minWidthSet(@(maxX))) //设置滚动区域
.seriesSet(eleArray);

maxX 是根据 X 轴数量 * 固定宽度算出来的 但是现在不生效了

siaschenbin avatar May 19 '25 02:05 siaschenbin

在线运行测试这段代码:

<!DOCTYPE html>
<html>
<head>
  <title>Highcharts Scrollable Plot Area Example</title>
  <script src="https://code.highcharts.com/highcharts.js"></script>
  <style>
    #container {
      width: 600px;
      height: 400px;
      margin: 0 auto;
    }
  </style>
</head>
<body>
  <div id="container"></div>
  <script>
    // 1. 生成示例数据(100个数据点)
    const categories = [];
    const data = [];
    for (let i = 1; i <= 100; i++) {
      categories.push(`Point ${i}`);
      data.push(Math.sin(i / 10) * 10);
    }

    // 2. Highcharts配置
    Highcharts.chart('container', {
      chart: {
        type: 'line',
        scrollablePlotArea: {
          minWidth: 1000,  // 必须大于容器宽度才能触发滚动
          scrollPositionX: 1  // 1表示滚动到最右侧
        }
      },
      title: { text: 'X轴滚动到最右侧的示例' },
      xAxis: {
        categories: categories,
        min: 90,  // 初始显示最后10个数据点(100-90=10)
        max: 100
      },
      yAxis: { title: { text: 'Value' } },
      series: [{
        name: 'Sample Data',
        data: data,
        color: '#4285F4'
      }],
      credits: { enabled: false }
    });
  </script>
</body>
</html>

运行后的最终图表📊效果:

Image

你会发现它已经自动滚动到了 x 轴的最右侧.

在线编辑器地址:

  • https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/chart/scrollable-plotarea

AAChartModel avatar May 19 '25 02:05 AAChartModel

其中的关键内容是:

          scrollPositionX: 1  // 1表示滚动到最右侧

在 iOS 中类似像下面👇这样配置即可:

    .scrollablePlotAreaSet(
        AAScrollablePlotArea.new
        .minWidthSet(@6000)
        .scrollPositionXSet(@1) // 1表示滚动到最右侧
)

AAChartModel avatar May 19 '25 02:05 AAChartModel

收到 感谢老板大大

siaschenbin avatar May 19 '25 05:05 siaschenbin