บทนำ
Visualization ช่วยเข้าใจข้อมูล Pygal: แพ็กเกจ Python โค้ดเปิด สร้างกราฟโต้ตอบ SVG ปรับแต่งได้ ดาวน์โหลดคุณภาพสูง ฝังในเว็บได้
Line Chart
แสดงข้อมูลเป็นชุดจุดบนเส้นโค้ง เข้าใจแนวโน้มง่าย
การติดตั้ง
pip install Pygal
ตัวอย่าง: สร้าง Line Chart
import pygal
from pygal.style import Style
custom_style = Style(colors=('#E80080', '#404040', '#9BC850', '#E81190'))
line_chart = pygal.Line(height=400, width=300, style=custom_style)
line_chart.title = "Line Chart"
line_chart.add("Label 1", [0.4, 0.45, 0.5, 0.56])
line_chart.add("Label 2", [1.2, 1.3, 1.4, 1.45])
line_chart.add("Label 3", [1.5, 1.56, 1.58, 1.6])
line_chart.add("Label 4", [0.7, 0.8, 0.9, 1.0])
line_chart.render_in_browser()
ผลลัพธ์

คำอธิบาย
- นำเข้า pygal และ Style
- สร้าง Line chart กำหนด height, width, style
- กำหนดสี custom style
- ตั้งค่า title และเพิ่มข้อมูลหลาย series
- เรียก
render_in_browser()แสดงผล