我是nvd3及其python实现的新手。我正在尝试以an example给出的以下折线图,但它返回了**kwargs1
未定义的错误。
我不知道它是什么以及如何克服这个错误。
from nvd3 import lineChart
chart = lineChart(name="lineChart", x_is_date=False, x_axis_format="AM_PM")
xdata = range(24)
ydata = [0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 4, 3, 3, 5, 7, 5, 3, 16, 6, 9, 15, 4, 12]
ydata2 = [9, 8, 11, 8, 3, 7, 10, 8, 6, 6, 9, 6, 5, 4, 3, 10, 0, 6, 3, 1, 0, 0, 0, 1]
extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " calls"}}
chart.add_serie(y=ydata, x=xdata, name='sine', extra=extra_serie, **kwargs1)
extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}}
chart.add_serie(y=ydata2, x=xdata, name='cose', extra=extra_serie, **kwargs2)
chart.buildhtml()
当我尝试没有** kwargs时,它会返回None
。此外,所有其他示例(饼图除外)都会发生这种情况!我无法克服这一点。
答案 0 :(得分:0)
chart.add_serie(y=ydata, x=xdata, name='sine', extra=extra_serie, **kwargs1)
这一行在图表上调用add_serie方法,在里面传递一些参数。您不必在传递的参数中包含** kwargs1。我认为这个例子包含它告诉你可以传递更多参数。要使其工作,请尝试将行更改为:
chart.add_serie(y=ydata, x=xdata, name='sine', extra=extra_serie)
和
chart.add_serie(y=ydata2, x=xdata, name='cose', extra=extra_serie)
编辑: 第2行:
output_file = open('test-nvd3.html', 'w')
附加到文件末尾:
output_file.write(chart.htmlcontent)
output_file.close()
检查目录中的test-nvd3.html并将其加载到浏览器中。
答案 1 :(得分:0)
实际上这很尴尬。如果我写下面的代码:
from nvd3 import lineChart
type = 'lineChart'
chart = lineChart(name=type, x_is_date=False, x_axis_format="AM_PM")
xdata = range(24)
ydata = [0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 4, 3, 3, 5, 7, 5, 3, 16, 6, 9, 15, 4, 12]
ydata2 = [9, 8, 11, 8, 3, 7, 10, 8, 6, 6, 9, 6, 5, 4, 3, 10, 0, 6, 3, 1, 0, 0, 0, 1]
extra_serie = {"tooltip": {"y_start": "There are ", "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)
extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}}
chart.buildcontent()
print chart.htmlcontent
有效。只是第二行(type = 'lineChart'
)的差异,但为什么?