Adding Chart to Web Page

Posted on 2012-12-29
Last Modified: 2013-01-22
We have a MYSQL/PHP database and want to add a chart to the web[age that shows the total amount of exercise per day over a period of time. Is there a nice chart plugin we could use for this?

The fields in the table are called exercise_id, exercise_time and exercise_timestamp.

Thanks for the help,

Question by:TLN_CANADA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 110

Expert Comment

by:Ray Paseur
ID: 38730708
I've used JPGraph with very good success.

Expert Comment

ID: 38731117
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users


Expert Comment

ID: 38756021
Google charts is very easy to work with and produces customizable charts that blend seamlessly with your existing pages.
I pull data from SQL server, populate into an array and send the array to a Google API to produce this chart:
Screen shot of chart

Author Comment

ID: 38757795
Thanks everyone,

I'm looking to make a simple chart that shows a person's exercise practice over time. User's can track their exercise times in minutes in the database. I would like to setup a simple line chart that shows on the vertical axis the minutes they exercised and on the horizontal axis the month of the year. If the chart could automatically resize to the amount of user data in the database that would be ideal. (E.g. if they have only exercised for one month it would show each day in details whereas if they have a year's worth of data it would show the data in months on the horizontal access). Could anyone provide a simple example of this? I have tried to do this myself using 3 of the programs suggest above (Float Chart, Google Charts and PHPChart) but as I'm not a seasoned PHP developer I'm finding it difficult to set it up.

Thanks for your help,


Author Comment

ID: 38757798
If it helps, our database table is called exercise_table and the fields are:

exercise_id (ai)
exercise_duration (int in minutes)

Author Comment

ID: 38757801
I can get all the necessary information from the database, I just can't figure out how to link it with the charts and the best chart system to use so that the view is automatically adjusted based on the amount of content for that user.

Accepted Solution

dimmergeek earned 500 total points
ID: 38774362
Here is the classic ASP page I used to generate the line chart above with GOogle API.  ALl you need to do is get the data from your database, populate your chart fields into an array and call the API.

        dim fso, rsCount, rsTally, i, arrSize, arrDate(), arrCount(), arrTally(), arrPercent(), chartData
        ' Create the ADO connection object
        set fso = CreateObject("ADODB.Connection")
        ' Create the recordsets
        set rsCount = Server.CreateObject("ADODB.Recordset")
        set rsTally = Server.CreateObject("ADODB.Recordset")
        ' Open the database
        fso.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("../../../../BR/LEAN/personalizationMetrics.mdb") & ";Persist Security Info=False;"
        mSQL = "SELECT entryDate, SUM([qty]) AS [SUM OF KEYPADS] FROM dataTable WHERE DateDiff('d', entryDate, Now()) <=30 AND (reqType = 0 OR reqType = 1) GROUP BY entryDate ORDER BY entryDate ASC;"
        rsCount.Open mSQL, fso, 1, 1
        arrSize = rsCount.RecordCount
        ReDim arrDate(arrSize)
        ReDim arrCount(arrSize)
        ReDim arrTally(arrSize)
        ReDim arrPercent(arrSize)
        Do While Not rsCount.eof
            If Not rsCount.eof Then
                arrDate(ctr) = rsCount("entryDate")
                arrCount(ctr) = rsCount("SUM OF KEYPADS")
                ctr = ctr+1
            End If
        mSQL = "SELECT entryDate, SUM([qty]) AS [SUM OF KEYPADS] FROM dataTable WHERE DateDiff('d', entryDate, Now()) <=30 AND (reqType = 0 OR reqType = 1) AND velocity = 0 GROUP BY entryDate ORDER BY entryDate ASC;"
        rsTally.Open mSQL, fso, 1, 1
        arrSize = rsTally.RecordCount
        Do While Not rsTally.eof
            If Not rsTally.eof Then
                arrTally(ctr) = rsTally("SUM OF KEYPADS")
                'Response.Write(ctr & ") " & arrDate(ctr) & ", " & arrCount(ctr) & ", " & arrTally(ctr) & "<br />")
                ctr= ctr+1
            End If
        'Response.Write("<br /><br /><br />")
        Do While ctr < arrSize
            arrPercent(ctr) = FormatNumber(eval((arrTally(ctr)/arrCount(ctr))*100),0)
            'Response.Write(ctr & ") " & arrDate(ctr) & ", " & arrPercent(ctr) & "<br />")
            chartData = chartData & ",['"&arrDate(ctr)&"', 100, "&arrPercent(ctr)&"]"
            ctr= ctr+1
    <!--Load the AJAX API-->
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        google.load("visualization", "1", { packages: ["corechart"] }); google.setOnLoadCallback(drawChart);
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
            ['Date', 'Goal', 'Actual']
            var options = {colors: ['#A90000','#028837'], title: 'Percentage of Orders Entered within 24 Hours', curveType: 'function', titleTextStyle: {fontSize: 24}, backgroundColor: '#F0F0F0', legend: 'bottom', hAxis: {slantedTextAngle: 90}, vAxis: {viewWindowMode:'explicit', viewWindow:{ max:110, min:0}}};
            var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
    <!--Div that will hold the chart-->    
        <div id="chart_div" style="width: 1000px; height: 600px;"></div>

Open in new window


Author Comment

ID: 38799698
Hi dimmergeek, we are using PHP/MYSQL. Will this work in the example you presented also?

Expert Comment

ID: 38801174
Yes, the data source does not matter.  Once you have your data, you just build an array table with it and then call the API.

Expert Comment

ID: 38805552
Thanks for the points and good luck!

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question