pygal charts not displaying tooltips in Jupyter / IPython notebook

隐身守侯 提交于 2019-12-06 11:36:24

My workaround involved setting up the HTML with the necessary javascript and chart svg like so:

import pygal
from IPython.display import display, HTML

base_html = """
<!DOCTYPE html>
<html>
  <head>
  <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
  <script type="text/javascript" src="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js""></script>
  </head>
  <body>
    <figure>
      {rendered_chart}
    </figure>
  </body>
</html>
"""

def galplot(chart):
    rendered_chart = chart.render(is_unicode=True)
    plot_html = base_html.format(rendered_chart=rendered_chart)
    display(HTML(plot_html))

bar_chart = pygal.StackedBar()
bar_chart.add('Bars', [1,2,3,4,5])

galplot(bar_chart)

Not the prettiest solution, but it works

Found this on the Google search that led me to this question. If you read the pygal documentation or look at an example SVG it generates, you'll see it includes pygal.js, which is missing in your notebook.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!