#!/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 lineChart, scatterChart, multiBarHorizontalChart
import math
import random

#Open File for test
output_file = open('test2.html', 'w')
#---------------------------------------
type = "lineChart"
chart = lineChart(name=type, date=False, height=350)

xdata = []
ydata = []
ydata2 = []

for i in range(0, 101):
    xdata.append(i)
    x = i * 0.1
    ydata.append(math.sin(math.pi * x))
    ydata2.append(0.5 * math.cos(math.pi * x))

extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}}
chart.add_serie(y=ydata, x=xdata, name='sine', extra=extra_serie)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(y=ydata2, x=xdata, name='cose', extra=extra_serie)

chart.buildhtml()

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

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

kwargs1 = {'shape': 'circle'}
kwargs2 = {'shape': 'cross'}
kwargs3 = {'shape': 'triangle-up'}

extra_serie = {"tooltip": {"y_start": "", "y_end": " calls"}}
chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie, **kwargs1)
chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie, **kwargs2)
chart.add_serie(name="serie 3", y=ydata3, x=xdata, extra=extra_serie, **kwargs3)

chart.buildhtml()

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



#close Html file
output_file.close()

@@ -1073,903 +1073,8 @@
 nt)%0A
-#---------------------------------------%0A%0Atype = %22scatterChart%22%0Achart = scatterChart(name=type, height=350, date=False)%0Achart.set_containerheader(%22%5Cn%5Cn%3Ch2%3E%22 + type + %22%3C/h2%3E%5Cn%5Cn%22)%0Anb_element = 50%0Axdata = %5Bi + random.randint(1, 10) for i in range(nb_element)%5D%0Aydata = %5Bi * random.randint(1, 10) for i in range(nb_element)%5D%0Aydata2 = map(lambda x: x * 2, ydata)%0Aydata3 = map(lambda x: x * 5, ydata)%0A%0Akwargs1 = %7B'shape': 'circle'%7D%0Akwargs2 = %7B'shape': 'cross'%7D%0Akwargs3 = %7B'shape': 'triangle-up'%7D%0A%0Aextra_serie = %7B%22tooltip%22: %7B%22y_start%22: %22%22, %22y_end%22: %22 calls%22%7D%7D%0Achart.add_serie(name=%22serie 1%22, y=ydata, x=xdata, extra=extra_serie, **kwargs1)%0Achart.add_serie(name=%22serie 2%22, y=ydata2, x=xdata, extra=extra_serie, **kwargs2)%0Achart.add_serie(name=%22serie 3%22, y=ydata3, x=xdata, extra=extra_serie, **kwargs3)%0A%0Achart.buildhtml()%0A%0Aoutput_file.write(chart.htmlcontent)%0A#---------------------------------------%0A%0A%0A
 %0A#cl

remove scatterChart example from example02