我使用 Kendo UI 创建了一个堆积条形图。我想在堆叠条形图中显示每个图块的工具提示,并为此使用另一个数组,其中包含要显示为工具提示的值。
例如:当我将鼠标悬停在 2000 年的美国时,工具提示应显示,NYC:60% 和 SFO:40%(如图所示)。
这是一个小提琴。
这就是我想要实现的目标(在这种情况下显示美国 2000 年的工具提示):
问题是当我使用series click
or时series hover events
,我无法识别图块(在堆积条形图中),这使得显示工具提示变得更加困难。
这是代码:
html { 字体大小:14px; 字体系列:Arial、Helvetica、sans-serif;}
<script src="https://kendo.cdn.telerik.com/2019.1.115/js/jquery.min.js"></script> <script src="https://kendo.cdn.telerik.com/2019.1.115/js/kendo.all.min.js"></script>
var CityData = [{country: "USA", children:[{"NYC": ["60%", "70%", "80%"]}, {"SFO": ["40%", "30%", "20%"]}]}, {country: "Mexico", children:[{"Mexico City": ["80%", "80%", "80%"]}, {"Cancun": ["20%", "20%", "20%"]}]}, {country: "Canada", children:[{"Toronto": ["50%", "60%", "60%"]}, {"Vancouver": ["50%",
"40%", "40%"]}]}
]; function createChart() { $("#chart").kendoChart({ title: { text: "City data" }, legend: { visible: false }, seriesDefaults: { type: "column", stack: { type: "100%" } }, series: [{ name: "USA", stack: { group: "Country" }, data: [854622, 925844, 984930] }, { name: "Canada", stack: { group: "Country" }, data: [490550, 555695, 627763] }, { name: "Mexico", stack: { group: "Country" }, data: [379788, 411217, 447201] } ], seriesColors: ["yellow", "green", "red"], valueAxis: { line: { visible: false } }, categoryAxis: { categories: [2000, 2005, 2010], majorGridLines: { visible: false } }, tooltip: { visible: true, template: "#= series.stack.group #, city #= series.name #" } }); } $(document).ready(createChart); $(document).bind("kendo:skinChange", createChart); </script>