Ejemplo n.º 1
0
 def test_stackedAreaChart(self):
     """Test Stacked Area Chart"""
     type = "stackedAreaChart"
     chart = stackedAreaChart(name=type, height=400)
     nb_element = 100
     xdata = range(nb_element)
     xdata = list(map(lambda x: 100 + x, xdata))
     ydata = [i + random.randint(1, 10) for i in range(nb_element)]
     ydata2 = list(map(lambda x: x * 2, ydata))
     chart.add_serie(y=ydata, x=xdata)
     chart.add_serie(y=ydata2, x=xdata)
     chart.buildhtml()
Ejemplo n.º 2
0
 def test_stackedAreaChart(self):
     """Test Stacked Area Chart"""
     type = "stackedAreaChart"
     chart = stackedAreaChart(name=type, height=400)
     nb_element = 100
     xdata = list(range(nb_element))
     xdata = [100 + x for x in xdata]
     ydata = [i + random.randint(1, 10) for i in range(nb_element)]
     ydata2 = [x * 2 for x in ydata]
     chart.add_serie(y=ydata, x=xdata)
     chart.add_serie(y=ydata2, x=xdata)
     chart.buildhtml()
Ejemplo n.º 3
0
 def test_stackedAreaChart(self):
     """Test Stacked Area Chart"""
     type = "stackedAreaChart"
     chart = stackedAreaChart(name=type, height=400)
     nb_element = 100
     xdata = list(range(nb_element))
     xdata = [100 + x for x in xdata]
     ydata = [i + random.randint(1, 10) for i in range(nb_element)]
     ydata2 = [x * 2 for x in ydata]
     chart.add_serie(y=ydata, x=xdata)
     chart.add_serie(y=ydata2, x=xdata)
     chart.buildhtml()
Ejemplo n.º 4
0
 def test_stackedAreaChart(self):
     """Test Stacked Area Chart"""
     type = "stackedAreaChart"
     chart = stackedAreaChart(name=type, height=400)
     nb_element = 100
     xdata = range(nb_element)
     xdata = map(lambda x: 100 + x, xdata)
     ydata = [i + random.randint(1, 10) for i in range(nb_element)]
     ydata2 = map(lambda x: x * 2, ydata)
     chart.add_serie(y=ydata, x=xdata)
     chart.add_serie(y=ydata2, x=xdata)
     chart.buildhtml()
def compare_revisions(title1, title2, lang="en"):
  """
  Presents the recent revisions of the two given Wikipedia pages as an
  interactive NVD3 chart.
  """
  chart = nvd3.stackedAreaChart(name='stackedAreaChart',height=450,width=800,use_interactive_guideline=True, x_is_date=True, date_format="%d %b %Y")
  r1, r2 = get_two_revision_series(title1, title2, lang)
  
  x = [int(time.mktime(idx.timetuple()) * 1000) for idx in r1.index]
  y = [[int(count) for count in np.asarray(np.cumsum(r))] for r in [r1, r2]]
  
  chart.add_serie(name=title1, y=y[0], x=x)
  chart.add_serie(name=title2, y=y[1], x=x)
  chart.buildhtml()
  
  # Export the chart to a standalone HTML file in the special /cdn
  # folder.
  fname = "chart_%s_%s.html" % (title1, title2)
  file("/cdn/%s" % fname, "w").write(chart.htmlcontent)
  
  # Return an IPython HTML widget containing an IFrame tag. The iframe
  # contains a relative reference (no path) to the HTML file we just
  # created, which works because the file is in the special /cdn folder.
  return IPython.display.HTML("<iframe src='%s' width=1000px height=550px>" % fname)
extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"},
               "date_format": "%d %b %Y %I:%M:%S"}
# extra_serie = None
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 4", y=ydata4, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)

# ---------------------------------------

type = "stackedAreaChart"
chart = stackedAreaChart(height=400, width=800, x_is_date=True,
                         x_axis_format="%d %b %Y %I", jquery_on_ready=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")

xdata = list(range(nb_element))
xdata = [start_time + x * 1000000000 for x in xdata]
ydata = [i + random.randint(1, 10) for i in list(range(nb_element))]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"},
               "date_format": "%d %b %Y %I:%M:%S %p"}
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)
Ejemplo n.º 7
0
extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"},
               "date_format": "%d %b %Y %I:%M:%S"}
#extra_serie = None
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 4", y=ydata4, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)

#---------------------------------------

type = "stackedAreaChart"
chart = stackedAreaChart(name=type, height=350, date=True,
                         x_axis_format="%d %b %Y %I", jquery_on_ready=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")

xdata = list(range(nb_element))
xdata = [start_time + x * 1000000000 for x in xdata]
ydata = [i + random.randint(1, 10) for i in list(range(nb_element))]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"},
               "date_format": "%d %b %Y %I:%M:%S %p"}
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)
Ejemplo n.º 8
0
ydata2 = map(lambda x: x * 2, ydata)
ydata3 = map(lambda x: x * 3, ydata)
ydata4 = map(lambda x: x * 4, ydata)

chart.add_serie(y=ydata, x=xdata)
chart.add_serie(y=ydata2, x=xdata)
chart.add_serie(y=ydata3, x=xdata)
chart.add_serie(y=ydata4, x=xdata)
chart.buildhtml()

output_file.write(chart.htmlcontent)

#---------------------------------------

type = "stackedAreaChart"
chart = stackedAreaChart(name=type, height=350)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 100
xdata = range(nb_element)
xdata = map(lambda x: 100 + x, xdata)
ydata = [i + random.randint(1, 10) for i in range(nb_element)]
ydata2 = map(lambda x: x * 2, ydata)

chart.add_serie(y=ydata, x=xdata)
chart.add_serie(y=ydata2, x=xdata)
chart.buildhtml()

output_file.write(chart.htmlcontent)
#---------------------------------------

type = "linePlusBarChart"
Ejemplo n.º 9
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Examples for Python-nvd3 is a Python wrapper for NVD3 graph library.
NVD3 is an attempt to build re-usable charts and chart components
for d3.js without taking away the power that d3.js gives you.

Project location : https://github.com/areski/python-nvd3
"""

from nvd3 import stackedAreaChart

# Open File for test
output_file = open('test_StackedAreaChart.html', 'w')

chart = stackedAreaChart(name='stackedAreaChart', height=400, width=400)

xdata = [100, 101, 102, 103, 104, 105, 106]
ydata = [6, 11, 12, 7, 11, 10, 11]
ydata2 = [8, 20, 16, 12, 20, 28, 28]

extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " min"}}
chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="Serie 2", y=ydata2, x=xdata, extra=extra_serie)
chart.buildhtml()

output_file.write(chart.htmlcontent)

output_file.close()
Ejemplo n.º 10
0
ydata2 = map(lambda x: x * 2, ydata)
ydata3 = map(lambda x: x * 3, ydata)
ydata4 = map(lambda x: x * 4, ydata)

chart.add_serie(y=ydata, x=xdata)
chart.add_serie(y=ydata2, x=xdata)
chart.add_serie(y=ydata3, x=xdata)
chart.add_serie(y=ydata4, x=xdata)
chart.buildhtml()

output_file.write(chart.htmlcontent)

# ---------------------------------------

type = "stackedAreaChart"
chart = stackedAreaChart(name=type, height=350)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
nb_element = 100
xdata = range(nb_element)
xdata = map(lambda x: 100 + x, xdata)
ydata = [i + random.randint(1, 10) for i in range(nb_element)]
ydata2 = map(lambda x: x * 2, ydata)

chart.add_serie(y=ydata, x=xdata)
chart.add_serie(y=ydata2, x=xdata)
chart.buildhtml()

output_file.write(chart.htmlcontent)
# ---------------------------------------

type = "linePlusBarChart"
Ejemplo n.º 11
0
extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"},
               "date_format": "%d %b %Y %I:%M:%S"}
#extra_serie = None
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 4", y=ydata4, x=xdata, extra=extra_serie)

chart.buildhtml()

output_file.write(chart.htmlcontent)

#---------------------------------------

type = "stackedAreaChart"
chart = stackedAreaChart(name=type, height=350, date=True, x_axis_date_format="%d %b %Y %I")
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")

xdata = list(range(nb_element))
xdata = [start_time + x * 1000000000 for x in xdata]
ydata = [i + random.randint(1, 10) for i in list(range(nb_element))]
ydata2 = [x * 2 for x in ydata]

extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"},
               "date_format": "%d %b %Y %I:%M:%S %p"}
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)

chart.buildhtml()

output_file.write(chart.htmlcontent)
Ejemplo n.º 12
0
#extra_serie = None
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie)
chart.add_serie(name="serie 4", y=ydata4, x=xdata, extra=extra_serie)

chart.buildcontent()

output_file.write(chart.htmlcontent)

#---------------------------------------

type = "stackedAreaChart"
chart = stackedAreaChart(name=type,
                         height=350,
                         date=True,
                         x_axis_format="%d %b %Y %I",
                         jquery_on_ready=True)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")

xdata = list(range(nb_element))
xdata = [start_time + x * 1000000000 for x in xdata]
ydata = [i + random.randint(1, 10) for i in list(range(nb_element))]
ydata2 = [x * 2 for x in ydata]

extra_serie = {
    "tooltip": {
        "y_start": "There is ",
        "y_end": " calls"
    },
    "date_format": "%d %b %Y %I:%M:%S %p"
Ejemplo n.º 13
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Examples for Python-nvd3 is a Python wrapper for NVD3 graph library.
NVD3 is an attempt to build re-usable charts and chart components
for d3.js without taking away the power that d3.js gives you.

Project location : https://github.com/areski/python-nvd3
"""

from nvd3 import stackedAreaChart

# Open File for test
output_file = open('test_StackedAreaChart.html', 'w')

chart = stackedAreaChart(name='stackedAreaChart', height=400, width=400)

xdata = [100, 101, 102, 103, 104, 105, 106]
ydata = [6, 11, 12, 7, 11, 10, 11]
ydata2 = [8, 20, 16, 12, 20, 28, 28]

extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " min"}}
chart.add_serie(name="Serie 1", y=ydata, x=xdata, extra=extra_serie)
chart.add_serie(name="Serie 2", y=ydata2, x=xdata, extra=extra_serie)
chart.buildhtml()

output_file.write(chart.htmlcontent)

output_file.close()