| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="https://cdn.amcharts.com/lib/5/index.js"></script> |
| <script src="https://cdn.amcharts.com/lib/5/xy.js"></script> |
| <script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script> |
| <script src="https://cdn.amcharts.com/lib/5/themes/Responsive.js"></script> |
| <style> |
| #chartdiv { |
| width: 1050PX; |
| height: 350px; |
| } |
| </style> |
| </head> |
| <body> |
| <div id="chartdiv"></div> |
| <script> |
| am5.ready(function() { |
| |
| |
| |
| var root = am5.Root.new("chartdiv"); |
| |
| |
| |
| root.setThemes([ |
| am5themes_Animated.new(root) |
| ]); |
| |
| |
| |
| var chart = root.container.children.push(am5xy.XYChart.new(root, { |
| panX: false, |
| panY: false, |
| wheelX: "panX", |
| wheelY: "zoomX", |
| paddingLeft: 0, |
| layout: root.verticalLayout |
| })); |
| |
| |
| var colors = chart.get("colors"); |
| |
| var data = [{ |
| country: "US", |
| visits: 725, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/united-states.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "UK", |
| visits: 625, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/united-kingdom.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "China", |
| visits: 602, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/china.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "Japan", |
| visits: 509, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/japan.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "Germany", |
| visits: 322, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/germany.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "France", |
| visits: 214, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/france.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "India", |
| visits: 204, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/india.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "Spain", |
| visits: 198, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/spain.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "Netherlands", |
| visits: 165, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/netherlands.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "South Korea", |
| visits: 93, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/south-korea.svg", |
| columnSettings: { fill: colors.next() } |
| }, { |
| country: "Canada", |
| visits: 41, |
| icon: "https://www.amcharts.com/wp-content/uploads/flags/canada.svg", |
| columnSettings: { fill: colors.next() } |
| }]; |
| |
| |
| |
| var xRenderer = am5xy.AxisRendererX.new(root, { |
| minGridDistance: 30, |
| minorGridEnabled: true |
| }) |
| |
| var xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, { |
| categoryField: "country", |
| renderer: xRenderer, |
| bullet: function (root, axis, dataItem) { |
| return am5xy.AxisBullet.new(root, { |
| location: 0.5, |
| sprite: am5.Picture.new(root, { |
| width: 24, |
| height: 24, |
| centerY: am5.p50, |
| centerX: am5.p50, |
| src: dataItem.dataContext.icon |
| }) |
| }); |
| } |
| })); |
| |
| xRenderer.grid.template.setAll({ |
| location: 1 |
| }) |
| |
| xRenderer.labels.template.setAll({ |
| paddingTop: 20 |
| }); |
| |
| xAxis.data.setAll(data); |
| |
| var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, { |
| renderer: am5xy.AxisRendererY.new(root, { |
| strokeOpacity: 0.1 |
| }) |
| })); |
| |
| |
| |
| var series = chart.series.push(am5xy.ColumnSeries.new(root, { |
| xAxis: xAxis, |
| yAxis: yAxis, |
| valueYField: "visits", |
| categoryXField: "country" |
| })); |
| |
| series.columns.template.setAll({ |
| tooltipText: "{categoryX}: {valueY}", |
| tooltipY: 0, |
| strokeOpacity: 0, |
| templateField: "columnSettings" |
| }); |
| |
| series.data.setAll(data); |
| |
| |
| |
| series.appear(); |
| chart.appear(1000, 100); |
| |
| }); |
| </script> |
| </body> |
| </html> |
点击查看详情

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-04-26 Mybatis入门(五):缓存
2022-04-26 Mybatis入门(四):动态sql
2022-04-26 idea不能识别yaml文件
2022-04-26 docker容器通讯