Data not showing in the RadialBar chart. #4075
Replies: 1 comment
-
Found bug in the JS code. Fixed |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m at a dead end to try fix this issue. I am trying to get data from a database to show in the radialbar chart. All is working correctly apart from the chart displaying the data.
In the console I can see the data coming through from the DB in JSON format.
Parsed JSON data: Object { OutBound: 24, InBound: 76, Generic: 0 }’ ‘Series data to be updated: Array(3) [ 76, 24, 0 ] 0: 76 1: 24 2: 0 length: 3
In the NETWORK tab I click the URL and I have this in Response:
OutBound | 24 InBound | 76 Generic | 0
So the data is there, but not showing. The Radialbar works fine with hard coded data in the JS, so i know all the correct files (JS / CSS) are being called. But not when I try get the data from the DB into the chart.
Here is my JS code for the Radialbar:
`document.getElementById('dataForm').addEventListener('submit', function(event) {
console.log("Form submitted");
event.preventDefault();
let startDate = document.getElementById('rangeCalendarFlatpickr').value.split(' to ')[0];
let endDate = document.getElementById('rangeCalendarFlatpickr').value.split(' to ')[1];
let userId = document.getElementById('operatorSelect').value;
console.log("Start Date:", startDate);
console.log("End Date:", endDate);
console.log("User ID:", userId);
// Fetch and update the chart data
fetchChartData();
});
function fetchChartData() {
let startDate = document.getElementById('rangeCalendarFlatpickr').value.split(' to ')[0];
let endDate = document.getElementById('rangeCalendarFlatpickr').value.split(' to ')[1];
let userId = document.getElementById('operatorSelect').value;
let chartDataUrl =
../src/php/radialbar.php?start_date=${startDate}&end_date=${endDate}&user_id=${userId}
;console.log("Fetching chart data from URL:", chartDataUrl);
fetch(chartDataUrl)
.then(response => {
if (!response.ok) {
throw new Error(
HTTP error! status: ${response.status}
);}
return response.text();
})
.then(text => {
console.log("Raw response text:", text);
try {
const data = JSON.parse(text);
console.log("Parsed JSON data:", data);
}
// Initialize the Donut Chart
var optionsCircle = {
chart: {
type: "radialBar",
height: 500,
offsetX: 0
},
plotOptions: {
radialBar: {
inverseOrder: false,
hollow: {
margin: 5,
size: "48%",
background: "transparent"
},
track: {
show: true,
background: "#40475D",
strokeWidth: "10%",
opacity: 1,
margin: 3 // margin is in pixels
}
}
},
series: [],
labels: ["InBound", "OutBound", "Generic"],
legend: {
show: true,
position: "bottom",
offsetX: -30,
offsetY: -10,
formatter: function(val, opts) {
return val + " - " + Math.round(opts.w.globals.series[opts.seriesIndex]) + "%";
}
},
fill: {
type: "gradient",
gradient: {
shade: "dark",
type: "horizontal",
shadeIntensity: 0.5,
inverseColors: true,
opacityFrom: 1,
opacityTo: 1,
stops: [0, 100]
}
}
};
var chartCircle = new ApexCharts(
document.querySelector("#circlechart2"),
optionsCircle
);
chartCircle.render();
console.log(chartCircle);`
Beta Was this translation helpful? Give feedback.
All reactions