Joe Bell
Joe Bell

Reputation: 209

How could I display a line graph which is linked to a MySQL database?

I have never used javascript or jscript and I was wondering how i could display a graph on my website. I have had a look at google charts but that doesnt accomodate for linking too a dataset.

Hope you can help.

Upvotes: 0

Views: 328

Answers (2)

Ruan Mendes
Ruan Mendes

Reputation: 92274

Mmm... You don't know JS, but you want a JS based solution? Here's a link to flot, a good free charting lib (jquery plugin) that I use: http://people.iola.dk/olau/flot/examples/

Here's how to build a simple chart with it, see the linked codeenter image description here

// http://people.iola.dk/olau/flot/examples/basic.html
$(function () {
    var d1 = [];
    for (var i = 0; i < 14; i += 0.5)
        d1.push([i, Math.sin(i)]);

    var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];

    // a null signifies separate line segments
    var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];

    $.plot($("#placeholder"), [ d1, d2, d3 ]);
});

All you need to do is be able to output json arrays from whatever server side language you're using. So in a php file, you could do the following:

var d2 = <?= json_encode(array(array(0,3), array(3,5), array(6,7))) ?>

Upvotes: 1

Raynos
Raynos

Reputation: 169391

take a look at grapheal.js

This should allow you to nicely draw graphs of data.

The real issue is how to get your data from your mySQL database into the client. This depends on your server side platform.

Either way you should be able to simply use ajax to fetch data and pass it onto grapheal in a format it understands.

Upvotes: 2

Related Questions