nvd3中的kwargs1未定义错误

2024-06-16 14:43:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我对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。此外,所有其他示例(饼图除外)都会出现这种情况!我无法克服这一点。你知道吗


Tags: nameadd错误chartextrastartendnvd3
2条回答
chart.add_serie(y=ydata, x=xdata, name='sine', extra=extra_serie, **kwargs1)

此行调用图表上的add\u 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目录并将其加载到浏览器中。你知道吗

这其实很尴尬。如果我写以下代码:

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')的区别,但为什么?你知道吗

相关问题 更多 >