Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

317
Views
Highcharts and sessionStorage (JS)

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?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Your php file should be like this

<?php echo json_encode( php code or variable or function ); ?>

https://stackoverflow.com/a/31743698

about 4 years ago · Santiago Gelvez Report

0

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

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!