I currently have a setup with DataTables and Highcharts working together where charts appear in expandable child rows. Right now my data comes from a JSON file but I need to switch the data source to Google Sheets instead. I’m wondering if this conversion is possible and how to modify my existing code to make it work.
The current implementation processes country and network data from JSON format. I need help updating the data fetching part to pull information directly from Google Spreadsheets while keeping the same table and chart functionality.
Charts.configure({
global: {
timezone: true
}
});
var dataset = location_info;
var regionList = [];
var sorted_regions = [];
var providerList = [];
var sorted_providers = [];
var display_container = "region_display";
var searchReset = false;
function buildDataTable(info, containerDiv, tableId, dataType) {
var columnConfig = [];
if (dataType == "regions") {
columnConfig = [
{"width": "20%", "title": "Position", "targets": 0, "visible": true, "searchable": false, "orderable": true},
{"width": "20%", "title": "Coverage %", "targets": 1, "visible": true, "searchable": false, "orderable": true},
{"width": "20%", "title": "Location", "targets": 2, "visible": true, "searchable": true, "orderable": true},
{"targets": 3, "visible": true, "searchable": false, "orderable": false}
];
}
var dataTable = $('#' + tableId).DataTable({
"data": info,
"ordering": [[1, "desc"]],
"paging": false,
"info": false,
"columns": columnConfig
});
return dataTable;
}
function createChart(element, settings, sourceData, rowIndex) {
settings.chart.renderTo = 'region_display' + rowIndex;
var location = $(element).children(':nth-child(3)').text();
settings.series = [];
var chartData = [];
for (region in sourceData) {
if (region == location) {
var seriesConfig = {
name: region,
type: 'line',
data: []
};
var dataPoints = sourceData[region];
for (timestamp in dataPoints) {
chartData.push([parseInt(timestamp), parseFloat(dataPoints[timestamp])]);
}
seriesConfig.data = chartData;
settings.series.push(seriesConfig);
}
}
var newChart = new Charts.Chart(settings);
return newChart;
}
How can I modify this code structure to fetch data from Google Sheets instead of the current JSON source?