Gideon
Gideon

Reputation: 1886

Highcharts not being drawn in some cases when using data from MySQL (page elements created before database query complete?) PHP / MySQL

I have a page which needs to fetch several different datasets from a MySQL database, and then use that data to define some jquery in such a way that graphs are drawn using that data (HighCharts to describe MySQL data).

Some users are reporting that the graphs are not loading, it is not a browser issue, nor is it consistent.

I've tried everything I can think of to debug the issue, and am left with the conclusion that the page is being loaded before the calls to the database are being completed in some cases, and so the graphs are not loaded.

As such I've resolved to put in a buffering page: the user selects which data they want to view, this is posted to a page with briefly "loads" (fetches all the data and stores it in $_SESSION), and then after a few seconds they are sent on to the page which draws the graphs, which now instead of drawing graphs based on database calls, is drawing them based on data stored in SESSION.

Is this a sensible way to proceed, or does this seem ridiculous to anyone more experienced?

Thank you

PS: My code is a few thousand lines long, and there's no one specific part which is not working (it works in 90% of cases), so I'm not sure how to usefully include code in this question.

Upvotes: 0

Views: 111

Answers (1)

Kylie
Kylie

Reputation: 11749

Here ya go...

 $('#container').highcharts({
    data: {
        table: document.getElementById('datatable')
    }....//other chart details....

<table id="datatable">
<thead>
    <tr>
        <th></th>
        <th>Jane</th>
        <th>John</th>
    </tr>
</thead>
<tbody>
    <tr>
        <th>Apples</th>
        <td>3</td>
        <td>4</td>
    </tr>
    <tr>
        <th>Pears</th>
        <td>2</td>
        <td>0</td>
    </tr>
    <tr>
        <th>Plums</th>
        <td>5</td>
        <td>11</td>
    </tr>
    <tr>
        <th>Bananas</th>
        <td>1</td>
        <td>1</td>
    </tr>
    <tr>
        <th>Oranges</th>
        <td>2</td>
        <td>4</td>
    </tr>
</tbody>

You can grab data from HTML tables, and use them in your charts... Hopefully doing it that way will be better than storing it in Session variables..

Upvotes: 1

Related Questions