Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate Chart by Pyecharts in Django

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to generate charts in Django", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to generate charts in Django Pyecharts" article.

Because pyecharts is a visualization that supports python, but there are two main ways to put it into a web page

(1) if iframe in a web page, embed the web page in iframe (this method is not specifically described)

(2) use json to transmit to the front end and display it.

The second method is described as follows:

Suppose you draw a line chart with pyecharts

Def line (): attr = ['teacher', 'professor', 'associate professor', 'doctoral director', 'master director', 'national awards', 'provincial and ministerial awards', 'academicians', 'honorary scholars', 'patents'] v1 = [100,20,15,50,40,200,4,5,100] v2 = [150,30,40,50,30,250,200,1,2 ] line = Line (width=1834, height=400) line.add ('Peking University', attr, v1, mark_point= ['average',' max', 'min'], # Dot: average Maximum value Minimum mark_point_symbol='diamond', # Dimension points: Diamond shape mark_point_textcolor='#40ff27') # callout points: label text color line.add ('Tsinghua University', attr, v2, mark_point= ['average',' max', 'min'], mark_point_symbol='arrow', xaxis_name_size=20 Yaxis_name_size=20,) return line

Next, if you want to use it to pass it to the front end for display, you need to add code to the views.py of Django's app.

Def university_picture (request): template = loader.get_template ('search/test.html') l = line () # generate image instance context = dict (myechart=l.render_embed (), # must have host=REMOTE_HOST, # if the corresponding echarts library is loaded at the front end You don't need this sentence and the next sentence script_list=l.get_js_dependencies (). The purpose of the above two lines of code is to download some echarts libraries corresponding to the icon) return HttpResponse (template.render (context, request))

The back-end code is introduced here, and the front-end code needs to be introduced below.

The first step at the front end is to load the header file:

{for jsfile_name in script_list} {endfor}

The second step is to display the icon (Note: the class and id of the following code can be replaced according to their own web page structure, not the same)

{{myechart | safe}} above is the content of this article on "how to generate charts in Pyecharts in Django". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report