When trying to make pyecharts charts in jupyter notebook, I encountered a problem that it could not be displayed. There were various reasons for the results found online. They are listed here one by one so that everyone can troubleshoot and completely solve the problem.
The situation of this example data set:
Case 1: The chart cannot be displayed at all
Solution: Refer to this document
Note: It is mentioned in the steps that Git needs to be installed. The domestic official download is extremely slow. It is recommended to visit this website to download the domestic mirror.
Case 2: The chart can display the horizontal and vertical axes, but no data
As shown in the figure below:
Possibility 1. A data format not supported by pyecharts is used and needs to be converted.
pyecharts does not support numpy type fields, such as int64, float64, etc. (please refer to the official explanation of Echarts )
and you need to use astype() for conversion.
- int64 to int
- float64 to float
- Others that are not supported can be directly converted to strings or query related documents.
Possibility 2. There is a problem with the theme settings
Regarding this, you can refer to this blog , which has specific instructions.
Possibility 3. The data is not transferred to the list
Different from common graphics libraries such as pyecharts and matplotlib, there will be problems if you directly pass the dataframe fields into them. You need to use list() to convert, such as:
c1 = (
Line()
.add_xaxis(list(df["YearMonth"]))
.add_yaxis("SalesAmt", list(["SalesAmt"]), is_smooth=True)
.render("line_base.html")
)
The display is normal after conversion:
If there are other situations that cause this problem, please leave a message!