javascript - highcharts: A chart with 1 or 0 in Y axis -


we have pcs , ip-cameras working , wrote python script check machines if or not pinging them. if machine result 1 , if it's down result 0. script writing current time.

there 2 tables.

  1. devices: keeps devices id, name, ip, etc
  2. ping: keeps ping results.

the script getting ip address , id of device devices table , pinging , writing results ping table. here code (i know it's verdantly):

# -*- coding: utf-8 -*- import subprocess, sys time import sleep try:     import mysqldb except:     print "please install python's mysqldb library"     sys.exit(0) class bcolors:     header = '\033[95m'     okblue = '\033[94m'     okgreen = '\033[92m'     warning = '\033[93m'     fail = '\033[91m'     endc = '\033[0m'  def cprint(txt, typ):     print "%s%s%s" %(typ, txt, bcolors.endc)  def ping(hname, verbose=false):     response = p = subprocess.popen(["ping", "-c1", hname], stdout=subprocess.pipe)     res = response.communicate()[0]     if not "100% packet loss" in res:         if verbose:             cprint("the host up.", bcolors.okgreen)         return true     else:         if verbose:             cprint("the host down.", bcolors.fail)         return false #code starts here: try:     db = mysqldb.connect(host="<the host>", user="<user name sql>", passwd="<password sql>", db="<database name>", charset="utf8")     cur = db.cursor()     cur.execute("select * devices")     row in cur.fetchall() :         devid = row[0]         devip = row[3]         if ping(devip):             cur.execute("""insert ping (id, date, status) values (%s, default, %s)""",(devid, 1))         else:             cur.execute("""insert ping (id, date, status) values (%s, default, %s)""",(devid, 0))     db.commit()     db.close() except:     cprint("no mysql connection." bcolors.fail) 

it works crontab every 10 minutes.

so have data here , wanted put in graph , decided use highcharts.

with line plot average line results.(ones , zeros)

with bar chart huge bar sum of results.(ones , zeros)

what kind of chart can advice me , how plot it. hoped there way plot like:

y axis: or down

x axis: time.

data want plot looks like:

[date.utc(2014, 09, 10, 22, 50, 11), 0], [date.utc(2014, 09, 10, 22, 40, 11), 0] 

a couple of options column chart or step line chart.

$(function () {     $('#container').highcharts({         xaxis: {             type: 'datetime'         },         yaxis: {             min:0,             max:1,             tickinterval: 1         },         legend: {             layout: 'vertical',             align: 'right',             verticalalign: 'middle',             borderwidth: 0         },         series: [{             type: 'line',             step: true, //            type: 'column',             data: [[date.utc(2014, 09, 10, 22, 50, 11), 0],                   [date.utc(2014, 09, 11, 22, 50, 11), 1],                    [date.utc(2014, 09, 12, 22, 50, 11), 0],                   [date.utc(2014, 09, 13, 22, 50, 11), 1],                   [date.utc(2014, 09, 14, 22, 50, 11), 1]]         }]     }); }); 

http://jsfiddle.net/tabrthca/1/


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -