• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

Adding Chart to Web Page

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,

D
0
TLN_CANADA
Asked:
TLN_CANADA
1 Solution
 
Ray PaseurCommented:
I've used JPGraph with very good success. http://jpgraph.net/
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
dimmergeekCommented:
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
0
 
TLN_CANADAAuthor Commented:
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,

D
0
 
TLN_CANADAAuthor Commented:
If it helps, our database table is called exercise_table and the fields are:

exercise_id (ai)
exercise_duration (int in minutes)
exercise_timestamp
user_id
0
 
TLN_CANADAAuthor Commented:
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.
0
 
dimmergeekCommented:
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.

<body>
    <%
        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
        rsCount.MoveFirst
        ReDim arrDate(arrSize)
        ReDim arrCount(arrSize)
        ReDim arrTally(arrSize)
        ReDim arrPercent(arrSize)
        ctr=0
        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
            rsCount.MoveNext
        Loop
        
        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
        rsTally.MoveFirst
        ctr=0
        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
            rsTally.MoveNext
        Loop
        
        'Response.Write("<br /><br /><br />")
        
        ctr=0
        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
        Loop
    %>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
        google.load("visualization", "1", { packages: ["corechart"] }); google.setOnLoadCallback(drawChart);
        function drawChart() {
            var data = google.visualization.arrayToDataTable([
            ['Date', 'Goal', 'Actual']
            <%=chartData%>
            ]);
            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'));
            chart.draw(data,options);
        }
    </script>
    
    <!--Div that will hold the chart-->    
    <center>
        <div id="chart_div" style="width: 1000px; height: 600px;"></div>
    </center>
</body>

Open in new window

0
 
TLN_CANADAAuthor Commented:
Hi dimmergeek, we are using PHP/MYSQL. Will this work in the example you presented also?
0
 
dimmergeekCommented:
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.
0
 
dimmergeekCommented:
Thanks for the points and good luck!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now