这里https://medium.com/@benjaminmbrown/real-time-data-visualization-with-d3-crossfilter-and-websockets-in-python-tutorial-dba5255e7f0e 是使用python加载随机数据并加载html网页的示例。我不知道如何使用websocket读取json文件数据。我在
上找到了这段代码def send_data(self):
print ("Sending Data")
#create a bunch of random data for various dimensions we want
qty = random.randrange(1,4)
total = random.randrange(30,1000)
tip = random.randrange(10, 100)
payType = paymentTypes[random.randrange(0,4)]
name = namesArray[random.randrange(0,4)]
spent = random.randrange(1,150);
year = random.randrange(2012,2016)
#create a new data point
point_data = {
'quantity': qty,
'total' : total,
'tip': tip,
'payType': payType,
'Name': name,
'Spent': spent,
'Year' : year,
'x': time.time()
}
print (point_data)
#write the json object to the socket
self.write_message(json.dumps(point_data))