In Kendo UI for jQuery, you can enable the click event for bars in a Kendo Chart. When a bar is clicked, you can perform actions such as displaying additional information or handling custom logic. Here's an example of how you can achieve this:
<!DOCTYPE html>
<html>
<head>
<title>Kendo Chart - Click on Bar</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.1.330/styles/kendo.common.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2021.1.330/styles/kendo.default.min.css" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2021.1.330/js/kendo.all.min.js"></script>
</head>
<body>
<div id="chart"></div>
<script>
$(document).ready(function() {
var chartData = [
{ category: "A", value: 5 },
{ category: "B", value: 8 },
{ category: "C", value: 3 },
{ category: "D", value: 12 },
{ category: "E", value: 6 }
];
$("#chart").kendoChart({
dataSource: {
data: chartData
},
seriesDefaults: {
type: "bar"
},
series: [{
field: "value",
categoryField: "category"
}],
categoryAxis: {
labels: {
rotation: -45
}
},
legend: {
visible: false
},
chartArea: {
height: 400
}
});
// Handle bar click event
$("#chart").data("kendoChart").bind("seriesClick", function(e) {
var dataItem = e.dataItem;
console.log("Clicked on bar:", dataItem.category, dataItem.value);
// Perform custom actions or display additional information
});
});
</script>
</body>
</html>
In the above example, we create a bar chart using Kendo UI's kendoChart
function. The chart data is provided as an array of objects with category
and value
properties. We bind the seriesClick
event to the chart, which will be triggered when a bar is clicked. Inside the event handler, we access the clicked bar's dataItem
to retrieve the corresponding category and value. You can modify the event handler to suit your specific requirements.
Ensure that you include the necessary CSS and JavaScript files from the Kendo UI CDN, as shown in the example, and customize the chart data and event handling logic as needed.
Comments
Post a Comment