Hi all,
I just started working with Dash and I developed a simple app for plotting some data from JSON file (almost 6000 data points). Unfortunately, it seems that I cannot plot last 100 entries in the dataset somehow. Has anyone encountered that kind of problem?
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas
import json
import time
from time import mktime
from datetime import datetime
import plotly
import plotly.graph_objs as go
def readJson_file():
with open(r"C:\Users\KWierzbowski\Documents\CPU_MONITOR_SCRIPTS\test_cpu\database_split_crontab_date_test.bk.json", 'r') as f:
readJson = json.load(f)
data = {'Monitor':{'service':{'cpu':{'usage': [], 'total': [], 'time':[]},'memory':{'usage': [], 'total': [], 'time':[]}}}}
for i in readJson['Monitor']:
if 'cpu' in i['service']:
data['Monitor']['service']['cpu']['usage'].append(i['service']['cpu']['data']['cpu usage'])
data['Monitor']['service']['cpu']['total'].append(i['service']['cpu']['data']['total cpu usage'])
data['Monitor']['service']['cpu']['time'].append(datetime.fromtimestamp(mktime(time.localtime(float(i['service']['cpu']['date'])))))
elif 'memory' in i['service']:
#data['Monitor']['service']['memory']['usage'].append(i['service']['memory']['data']['cpu usage'])
#data['Monitor']['service']['memory']['total'].append(i['service']['memory']['data']['total cpu usage'])
data['Monitor']['service']['memory']['time'].append(datetime.fromtimestamp(mktime(time.localtime(float(i['service']['memory']['date'])))))
return data
app = dash.Dash()
df_json = pandas.DataFrame(readJson_file())
app.layout = html.Div([
dcc.Graph(
id='cpu usage vs date',
figure={
'data': [
go.Scatter(
x=sorted(df_json['Monitor']['service']['cpu']['time']),
y=df_json['Monitor']['service']['cpu']['usage'],
text='Cpu',
)
],
'layout': go.Layout(
title='CPU monitor',
xaxis={'title': 'Date'},
yaxis={'title': 'CPU usage'},
legend={'x': 0, 'y': 1},
hovermode='closest'
)
}
)
])
if __name__ == '__main__':
app.run_server()`Preformatted text`