লাইন চার্ট (Line Chart) টাইম সিরিজ ডেটা, ট্রেন্ড এবং ক্রমাগত ডেটা পয়েন্টের পরিবর্তন দেখানোর জন্য আদর্শ। XlsxWriter দিয়ে লাইন চার্ট তৈরির উদাহরণ।
সম্পূর্ণ উদাহরণ
import xlsxwriter
workbook = xlsxwriter.Workbook('chart_line.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})
headings = ['Number', 'Batch 1', 'Batch 2']
data = [
[2, 3, 4, 5, 6, 7],
[80, 80, 100, 60, 50, 100],
[60, 50, 60, 20, 10, 20]
]
worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])
# লাইন চার্ট অবজেক্ট
chart1 = workbook.add_chart({'type': 'line'})
# প্রথম সিরিজ
chart1.add_series({
'name': '=Sheet1!$B$1',
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$B$2:$B$7',
})
# দ্বিতীয় সিরিজ
chart1.add_series({
'name': ['Sheet1', 0, 2],
'categories': ['Sheet1', 1, 0, 6, 0],
'values': ['Sheet1', 1, 2, 6, 2],
})
chart1.set_title({'name': 'Results of Data Analysis'})
chart1.set_x_axis({'name': 'Test Number'})
chart1.set_y_axis({'name': 'Data Length (mm)'})
chart1.set_style(11)
worksheet.insert_chart('D2', chart1, {'x_offset': 25, 'y_offset': 10})
workbook.close()
print("লাইন চার্ট তৈরি হয়েছে: chart_line.xlsx")
লাইন চার্ট সাব-টাইপস
| সাব-টাইপ | বিবরণ | প্যারামিটার |
|---|---|---|
| Standard Line | সরাসরি লাইন (ডিফল্ট) | {'type': 'line'} |
| Line with Markers | পয়েন্টে মার্কার | {'type': 'line', 'subtype': 'with_markers'} |
| Stacked Line | স্ট্যাকড লাইন (যোগফল) | {'type': 'line', 'subtype': 'stacked'} |
| 100% Stacked Line | শতকরা স্ট্যাকড | {'type': 'line', 'subtype': 'percent_stacked'} |
| 3D Line | ৩D লাইন | {'type': 'line', 'subtype': '3d'} |
লাইন কাস্টমাইজেশন
chart1.add_series({
'name': '=Sheet1!$B$1',
'categories': '=Sheet1!$A$2:$A$7',
'values': '=Sheet1!$B$2:$B$7',
'line': {
'color': 'blue',
'width': 2.25,
'dash_type: 'dash', # 'solid', 'dash', 'dot', 'dash_dot', 'long_dash'
},
'marker': {
'type': 'square',
'size': 6,
'fill': {'color': 'blue'},
'border': {'color': 'white'}
},
'smooth': True # স্মুথ কার্ভ (স্প্লাইন)
})
স্ট্যাকড লাইন চার্ট (যোগফল ট্রেন্ড)
chart1 = workbook.add_chart({'type': 'line', 'subtype': 'stacked'})
# এখন সিরিজগুলো একে অপরের ওপর স্ট্যাক হবে
# মোট ট্রেন্ড বোঝার জন্য উপযোগী
সেরা অনুশীলন
- টাইম সিরিজ ডেটার জন্য লাইন চার্ট সেরা।
- অनेक সিরিজ থাকলে মার্কার ব্যবহার করুন পয়েন্ট আলাদা করার জন্য।
smooth=Trueদিয়ে স্প্লাইন ইন্টারপোলেশন (দৃষ্টিনন্দন কিন্তু ডেটা পয়েন্ট পরিবর্তন করতে পারে)।- স্ট্যাকড লাইন ব্যবহার করুন যখন সিরিজগুলোর যোগফল অর্থবহ হয় (যেমন: টোটাল সেলস = অনলাইন + অফলাইন)।