【发布时间】:2017-05-12 23:42:02
【问题描述】:
我将在 python 中使用 nvd3 来构建折线图。代码如下:
from nvd3 import lineChart
chart = lineChart(name="lineChart", x_is_date=True, x_axis_format="%Y")
xdata = [599644800000,694252800000,788947200000,883641600000,1167638400000,1199174400000,1230796800000,1262332800000,1357027200000]
ydata = [26.2, 22.4, 17.7, 14.8, 9.29, 8.08, 7.48, 6.96, 5.5]
extra_serie = {"tooltip": {"y_start": "There are ", "y_end": " calls"}}
chart.add_serie(y=ydata, x=xdata, name='Current Smokers ', extra=extra_serie, **kwargs1)
chart
我有三个问题:
- x 轴有 9 个元素,但图表仅显示其中 3 个。如何更改代码以显示所有 9 个元素?
- y 轴元素的类型是百分比。如何将 % 添加到 y 轴?
- 看起来 nvd3 不接受常规格式的日期,我不得不将它们转换为毫秒,这有点烦人。我怎样才能摆脱那些毫秒日期格式并简单地使用 1998、1995 等等?
【问题讨论】: