0

I have tried for several days to get MySQL data in a Google chart but I can't seem to work out how to make a working page from the examples I've come across on the internet.

I've created some dummy data which randomly creates data in an SQLite-3.py file:

import sqlite3
import time
import datetime
import random

conn = sqlite3.connect('tutorial.db')
c = conn.cursor()

def create_table():
    c.execute('CREATE TABLE IF NOT EXISTS stuffToPlot(unix REAL, datestamp TEXT, keyword TEXT, value REAL)')

def dynamic_data_entry():
    unix = time.time()
    date = (datetime.datetime.fromtimestamp(unix).strftime('%Y-%M-%D %H: %M: %S'))
    keyword = 'Python'
    value = random.randrange(0, 10)
    c.execute("INSERT INTO stuffToPlot VALUES (?, ?, ?, ?)", (unix, date, keyword, value))
    conn.commit()

def read_from_db():
    c.execute('SELECT * FROM stuffToPlot') # * betekend dat je alles selecteert van ....
    # data = c.fetchall()
    # print(data)
    for row in c.fetchall():
        print(row)

This creates a datatable shown here in the SQLite explorer: datatable

I have also put in a Google cart which is shown on a webpage, created in graph.html, which right now has static data, but I want to put in the variable data from the database:

  var data = new google.visualization.DataTable();
    data.addColumn('string', 'Task')
    data.addColumn('number', 'Hours per Day')
    data.addRows([
    ['Work', 11],
    ['Eat', 2],
    ['Commute', 2],
    ['Watch TV', 2],
    ['Sleep', {v:7, f:'7.000'}]
    ]);

It is unclear to me how I can connect the database to the chart to make a working graph with the variable data.

Richard Wilson
  • 297
  • 4
  • 17
Tophat123
  • 1
  • 1