当前位置: 首页 > news >正文

Antv/G2 柱状图添加自定义点击事件

<!DOCTYPE html>
<html><head><meta charset="UTF-8"><title>柱状图点击事件</title></head><body><div id="container" /><script src="https://gw.alipayobjects.com/os/lib/antv/g2/4.2.8/dist/g2.min.js"></script><script src="https://gw.alipayobjects.com/os/antv/pkg/_antv.data-set-0.11.1/dist/data-set.js"></script><script><!-- 浏览器引入,请使用全局命名空间 G2,如 new Chart() 改为 new G2.Chart,即可运行。 -->const data = [{ month: 'Jan', city: 'Tokyo', temperature: 7 },{ month: 'Jan', city: 'London', temperature: 3.9 },{ month: 'Feb', city: 'Tokyo', temperature: 6.9 },{ month: 'Feb', city: 'London', temperature: 4.2 },{ month: 'Mar', city: 'Tokyo', temperature: 9.5 },{ month: 'Mar', city: 'London', temperature: 5.7 },{ month: 'Apr', city: 'Tokyo', temperature: 14.5 },{ month: 'Apr', city: 'London', temperature: 8.5 },{ month: 'May', city: 'Tokyo', temperature: 18.4 },{ month: 'May', city: 'London', temperature: 11.9 },{ month: 'Jun', city: 'Tokyo', temperature: 21.5 },{ month: 'Jun', city: 'London', temperature: 15.2 },{ month: 'Jul', city: 'Tokyo', temperature: 25.2 },{ month: 'Jul', city: 'London', temperature: 17 },{ month: 'Aug', city: 'Tokyo', temperature: 26.5 },{ month: 'Aug', city: 'London', temperature: 16.6 },{ month: 'Sep', city: 'Tokyo', temperature: 23.3 },{ month: 'Sep', city: 'London', temperature: 14.2 },{ month: 'Oct', city: 'Tokyo', temperature: 18.3 },{ month: 'Oct', city: 'London', temperature: 10.3 },{ month: 'Nov', city: 'Tokyo', temperature: 13.9 },{ month: 'Nov', city: 'London', temperature: 6.6 },{ month: 'Dec', city: 'Tokyo', temperature: 9.6 },{ month: 'Dec', city: 'London', temperature: 4.8 },];const chart = new G2.Chart({container: 'container',autoFit: true,height: 500,});chart.data(data);chart.tooltip({showCrosshairs: true,shared: true,});chart.axis('temperature', {label: {formatter: (val) => {return val + ' °C';},},});chart.interval().position('month*temperature').color('city').adjust([{type: 'dodge',marginRatio: 0,},])chart.interaction('active-region')chart.render();// 监听click事件chart.on('element:click',(ev)=>{const data=ev.data.data; console.log('ev data',data)        })</script></body>
</html>

页面效果:
在这里插入图片描述

http://www.lryc.cn/news/232440.html

相关文章:

  • Python---数据序列中的公共方法
  • 从0开始python学习-33.夹具@pytest.fixture(scope=““,params=““,autouse=““,ids=““,name=““)
  • vue3别名配置(vite)
  • 初学UE5 C++①
  • ElasticSearch6.8.1 常见错误
  • wx.canvasToTempFilePath生成图片保存到相册
  • HDU1276:士兵队列训练问题 ← STL queue
  • JS 读取excel文件内容 和 将json数据导出excel文件
  • ASP.NET限流器的简单实现
  • 汇编语言循环左移和循环右移如何实现的,详细的比喻一下
  • ChromeDriver 各版本下载地址
  • 计算机网络之物理层
  • 沉浸式航天vr科普馆VR太空主题馆展示
  • AI电话机器人能否代替人工?优缺点介绍
  • Java —— 多态
  • UI自动化测试(弹出框,多窗口)
  • Python爬虫程序网络请求及内容解析
  • C嘎嘎模板
  • 数据结构和算法八股与手撕
  • windiws docker 部署jar window部署docker 转载
  • 使用git上传代码至gitee入门(1)
  • 分类预测 | MATLAB实现基于Isomap降维算法与改进蜜獾算法IHBA的Adaboost-SVM集成多输入分类预测
  • 如何解决3d max渲染效果图全白这类异常问题?
  • 振南技术干货集:比萨斜塔要倒了,倾斜传感器快来!(2)
  • 图形学 -- Geometry几何
  • opencv中边缘检测的方法
  • DigitalVirt 洛杉矶 CMIN2 VPS 测评
  • Qt DragDrop拖动与放置
  • thinkphp8 多级控制器调用
  • 设计测试用例的6种基本原则