如何在图表中配置一个能够在移动端响应的DataZoom组件?

阅读 2.8k
2 个回答

解决方案 Solution

不同图表库的解决方案不一样,根据你给的demo,在VChart中只需要配置 dataZoom ,就会展示组件;为了移动端的交互更加友好,可以开启roam: true的配置。

image.png

代码示例 Code Example

const spec = {
  type: "line",
  data: {
    values: [
      {
        time: "2:00",
        value: 8
      },
      {
        time: "4:00",
        value: 9
      },
      {
        time: "6:00",
        value: 11
      },
      {
        time: "8:00",
        value: 14
      },
      {
        time: "10:00",
        value: 16
      },
      {
        time: "12:00",
        value: 17
      },
      {
        time: "14:00",
        value: 17
      },
      {
        time: "16:00",
        value: 16
      },
      {
        time: "18:00",
        value: 15
      }
    ]
  },
  xField: "time",
  yField: "value",
  dataZoom: [
    {
      orient: "bottom",
      filterMode: "filter",
      roam: true
    }
  ]
};

结果展示 Results

在线效果参考:https://codesandbox.io/s/line-chart-datazoom-wzk8n7
Sep-12-2023 14-17-56.gif

相关文档 Related Documentation

DataZoom demo:https://www.visactor.io/vchart/demo/data-zoom/preview-data?ke...

DataZoom教程:https://www.visactor.io/vchart/guide/tutorial_docs/Chart_Conc...

相关配置:https://www.visactor.io/vchart/option/lineChart#dataZoom.valu...

github:https://github.com/VisActor/VChart

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题