I am trying to play with highcharts and pass data between a couple of pages depending on what element of a graph is clicked.
I have an array built up (from JIRA) which has all my data - and I use that to create a pie chart. That all works as expected.
I have added in an events block to the series block of my data
events: {
click: function () {
location.href = 'severity_data.php';
}
}
and that works as expected.
I then set at a high level a simple
sessionStorage.setItem("faveFilm", "shrek");
and on the PHP page, which at the moment is just a boilerplate html, I added
// var favoriteMovie = sessionStorage.getItem('faveFilm');
// console.log(favoriteMovie)
and saw "shrek" in the console.
I modified the code to send a the JSON and decoded it and saw the data was there. Everything great so far.
I then tried to use this within highcharts.
My first attempt was to insert a key
key: sessionStorage.setItem("severity", sessionStorage.setItem("majorArray", JSON.stringify(major_data)););
however, this didn't work as I got some form of {} mismatch (guessing this was to do with the array and it messing up the structure of the highcharts code. (and my thinking was each element of the graph would send a different array)
Then I thought I could take a step backwards, maybe set all the data in session and in the key just send the word for the graph element I clicked:
{
name: 'Major',
y: majorCount,
key: sessionStorage.setItem("severity", "Major");
}
However, when I run this I get:
Uncaught SyntaxError: missing } after property listseverity2.php:93:58
note: { opened at line 90, column 11
Line 93 (on generated output) is key: sessionStorage.setItem("severity", "Major");
Any ideas what I am doing wrong?
Your php file should be like this
<?php echo json_encode( php code or variable or function ); ?>
First of all, you can not use a semicolon in an object notation. You need to remove ; at the end of the key value. However, the below notation:
{
name: 'Major',
y: majorCount,
key: sessionStorage.setItem("severity", "Major")
}
will of course save the specific value in a session storage, but it will result in:
{
name: 'Major',
y: majorCount,
key: undefined
}
The same situation with:
sessionStorage.setItem(
"severity",
sessionStorage.setItem("majorArray", JSON.stringify(major_data))
);
You should use both setItem and getItem methods and remember that setItem will return undefined.
Docs: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage