Help with CS chart / JSON Data Loading
Using c3 library, if I manually set the data in the index.js file to be this:
data: {
xs: {
'Detached': 'x1',
'Semi Detached': 'x2',
'Flat / Maisonette': 'x3',
'Terrace': 'x4',
'All': 'x5',
},
columns: [
['x1', '2023 - Jan', '2023 - Feb', '2023 - Mar', '2023 - Apr', '2023 - May', '2023 - June'],
['x2', '2023 - Jan', '2023 - Feb', '2023 - Mar', '2023 - Apr', '2023 - May', '2023 - June'],
['x3', '2023 - Jan', '2023 - Feb', '2023 - Mar', '2023 - Apr', '2023 - May', '2023 - June'],
['x4', '2023 - Jan', '2023 - Feb', '2023 - Mar', '2023 - Apr', '2023 - May', '2023 - June'],
['x5', '2023 - Jan', '2023 - Feb', '2023 - Mar', '2023 - Apr', '2023 - May', '2023 - June'],
['Detached', 30, 200, 100, 400, 150, 250], ['Semi Detached', 30, 200, 100, 343, 150, 250], ['Flat / Maisonette', 30, 200, 100, 888, 150, 250], ['Terrace', 50, 200, 343, 400, 123, 250], ['All', 56, 456, 240, 100, 555] ]},
Everything works fine.
But I’m trying (obviously) to load the data from the Filemaker tables. I’ve made a script which creates the following JSON payload:
{
"columns" :
[
[
"x1",
"2021-01",
"2021-02",
"2021-03",
"2021-04",
"2021-05",
"2021-06",
"2021-07",
"2021-08",
"2021-09",
"2021-10",
"2021-11",
"2021-12",
"2022-01",
"2022-02",
"2022-03",
"2022-04",
"2022-05",
"2022-06",
"2022-07",
"2022-08",
"2022-09",
"2022-10",
"2022-11",
"2022-12",
"2023-01",
"2023-02",
"2023-03",
"2023-04",
"2023-05",
"2023-06"
],
[
"x2",
"2021-01",
"2021-02",
"2021-03",
"2021-04",
"2021-05",
"2021-06",
"2021-07",
"2021-08",
"2021-09",
"2021-10",
"2021-11",
"2021-12",
"2022-01",
"2022-02",
"2022-03",
"2022-04",
"2022-05",
"2022-06",
"2022-07",
"2022-08",
"2022-09",
"2022-10",
"2022-11",
"2022-12",
"2023-01",
"2023-02",
"2023-03",
"2023-04",
"2023-05",
"2023-06"
],
[
"All Houses",
"129.3",
"129.9",
"130.9",
"131.1",
"131.4",
"133.5",
"133.9",
"135.6",
"136.4",
"138",
"139.3",
"139.2",
"140.9",
"141.8",
"142.8",
"143.7",
"145.1",
"146.6",
"148.8",
"150.6",
"152.3",
"152.8",
"153",
"152.6",
"152.1",
"151.4",
"150.5",
"150.1",
"",
""
],
[
"All Regions",
"129.3",
"129.9",
"130.9",
"131.1",
"131.4",
"133.5",
"133.9",
"135.6",
"136.4",
"138",
"139.3",
"139.2",
"140.9",
"141.8",
"142.8",
"143.7",
"145.1",
"146.6",
"148.8",
"150.6",
"152.3",
"152.8",
"153",
"152.6",
"152.1",
"151.4",
"150.5",
"150.1",
"",
""
]
],
"xs" :
{
"All House Types" : "x1",
"All Regions" : "x2"
}
}
And I have defined a function like this:
window.loadData = function (json) {
const obj = JSON.parse(json);
const columns = obj.data.columns;
const xs = obj.data.xs;
chart.load ({
columns: columns,
xs: xs,
});
}
But when I try to run this, I get an error in the Console: ‘ReferenceError: Can't find variable: loadData‘
I have’t played around with this environment for so long, I can’t for the life of me see what I’m doing wrong. Can anyone help?!
(Apologies if the formatting of the code above is hard to read, couldn’t work out how to paste in code in a formatted manner)
Have attached the relevant files from the JS environment…
Archive.zip