Hi,
Am using apex chart for daisply values but when i click for chart redirect to another page with parameter value.
Hi,
Am using apex chart for daisply values but when i click for chart redirect to another page with parameter value.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 20, 2023, 2:09 AM EDT
var options = { chart: { type: 'line', events: { dataPointSelection: function(event, chartContext, config) { // Get the selected data point's value and redirect to another page var selectedValue = config.w.globals.series[config.seriesIndex][config.dataPointIndex]; window.location.href = 'another-page.aspx?selectedValue=' + selectedValue; } } }, // Other chart options // ... } var chart = new ApexCharts(document.querySelector('#chart'), options); chart.render();raja n101 reputationPosted Apr 20, 2023, 3:10 AM EDT
@rajkiran thanks for your reply
am using apex chart (radialbar) but your code used return value is "undefined"
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 22, 2023, 10:44 PM EDT
Here's a modified and complete version of the code:
// Define chart options var options = { chart: { type: 'line', events: { // Add a dataPointSelection event handler dataPointSelection: function(event, chartContext, config) { // Get the selected data point's value var selectedValue = config.w.globals.series[config.seriesIndex][config.dataPointIndex]; javascript Copy code // Redirect to another page with the selected value as a query parameter var url = 'another-page.aspx?selectedValue=' + selectedValue; window.location.href = url; } } }, series: [{ name: 'Sales', data: [30, 40, 35, 50, 49, 60, 70, 91, 125] }], xaxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'] } }; // Create a new ApexCharts instance with the chart options and render it var chart = new ApexCharts(document.querySelector('#chart'), options); chart.render();This code creates a line chart using ApexCharts library and adds an event listener to redirect to another page when a data point is selected. This code first defines the chart options, including setting the chart type to line and adding an event listener for data point selection. The dataPointSelection event fires when a data point is clicked, and it receives three parameters: event, chartContext, and config. Inside the event listener function, we use config to get the selected data point's value and then redirect to another page by setting window.location.href. We pass the selected value as a query string parameter to the another-page.aspx page. The code creates a new ApexCharts instance with the specified options and renders the chart on the page by calling the render() method on the chart object.