Halli Hallo,
habe mir einen Auswerteprogramm geschrieben, welches meine Messdaten in Excel ausgibt.
Ich würde gerne in einigen Excelsheets mit openpyxl Diagramme einzeichnen.
Die Diagramme sind alle an der richtigen Stelle. Nur mit dem Inhalt habe ich Probleme.
Zur Info ich benutze PyCharm 2018.1.2 / Python 3.6.6 und bin neu Dabei
Mein Code:
from openpyxl.chart import LineChart, Reference
.
.
.
if sheet.title == 'Scope' or sheet.title == 'Overview':
data = Reference(ws, min_col=1, min_row=1, max_col=17, max_row=77) <- Hier
chart = LineChart()
chart.add_data(data) <---- Hier
ws.add_chart(chart, "T15")
Ich muss die Spalten C und F ausgeben
Ich habe alles probiert klappt irgendwie nicht :S
Würde bei openpyxl bleiben, weil ich alles damit gemacht habe
Vielen Dank schonmal
Mit openpyxl Diagramm einzeichnen
Du könntest mal deine Lösung in Codetags einfügen, das könnte für andere auch interessant sein, Codetags wären ohne Leerzeichen, vor dem Code
[ python ]
und nach dem Code
[/ python ]
Danke!.
[ python ]
und nach dem Code
[/ python ]
Danke!.
from openpyxl import Workbook
from openpyxl.chart import ScatterChart, Reference, Series
.
.
.
# Add charts
if sheet.title == 'Scope':
last_row = (len(sheet.entries)+1)
x_values = Reference(ws, min_col=1, min_row=2, max_row=last_row)
# first chart
chart1 = ScatterChart()
chart1.title = "Distance"
chart1.x_axis.title = 'Time in s'
chart1.y_axis.title = 'Y-Axis'
chart1.x_axis.scaling.min = round(ws.cell(row=2, column=1).value, 0)
chart1.x_axis.scaling.max = ws.cell(row=last_row, column=1).value
y_values1 = Reference(ws, min_col=6, min_row=1, max_row=last_row)
series1 = Series(y_values1, x_values, title_from_data=True)
chart1.series.append(series1)
# second chart
chart2 = ScatterChart()
chart2.title = "Existence"
chart2.x_axis.title = 'Time in s'
chart2.y_axis.title = 'Y-Axis'
chart2.x_axis.scaling.min = round(ws.cell(row=2, column=1).value, 0)
chart2.x_axis.scaling.max = ws.cell(row=last_row, column=1).value
for i in (7, 8, 12):
y_values2 = Reference(ws, min_col=i, min_row=1, max_row=last_row)
series2 = Series(y_values2, x_values, title_from_data=True)
chart2.series.append(series2)
ws.add_chart(chart1, "O2")
ws.add_chart(chart2, "O18")
Verbesserungsvorschläge nehme ich dankend an
from openpyxl.chart import ScatterChart, Reference, Series
.
.
.
# Add charts
if sheet.title == 'Scope':
last_row = (len(sheet.entries)+1)
x_values = Reference(ws, min_col=1, min_row=2, max_row=last_row)
# first chart
chart1 = ScatterChart()
chart1.title = "Distance"
chart1.x_axis.title = 'Time in s'
chart1.y_axis.title = 'Y-Axis'
chart1.x_axis.scaling.min = round(ws.cell(row=2, column=1).value, 0)
chart1.x_axis.scaling.max = ws.cell(row=last_row, column=1).value
y_values1 = Reference(ws, min_col=6, min_row=1, max_row=last_row)
series1 = Series(y_values1, x_values, title_from_data=True)
chart1.series.append(series1)
# second chart
chart2 = ScatterChart()
chart2.title = "Existence"
chart2.x_axis.title = 'Time in s'
chart2.y_axis.title = 'Y-Axis'
chart2.x_axis.scaling.min = round(ws.cell(row=2, column=1).value, 0)
chart2.x_axis.scaling.max = ws.cell(row=last_row, column=1).value
for i in (7, 8, 12):
y_values2 = Reference(ws, min_col=i, min_row=1, max_row=last_row)
series2 = Series(y_values2, x_values, title_from_data=True)
chart2.series.append(series2)
ws.add_chart(chart1, "O2")
ws.add_chart(chart2, "O18")
Verbesserungsvorschläge nehme ich dankend an
Liebe Grüße
Serki92
Serki92
Code: Alles auswählen
from openpyxl import Workbook
from openpyxl.chart import ScatterChart, Reference, Series
#
#
#
# Add charts
if sheet.title == 'Scope':
last_row = (len(sheet.entries)+1)
x_values = Reference(ws, min_col=1, min_row=2, max_row=last_row)
# first chart
chart1 = ScatterChart()
chart1.title = "Distance"
chart1.x_axis.title = 'Time in s'
chart1.y_axis.title = 'Y-Axis'
chart1.x_axis.scaling.min = round(ws.cell(row=2, column=1).value, 0)
chart1.x_axis.scaling.max = ws.cell(row=last_row, column=1).value
y_values1 = Reference(ws, min_col=6, min_row=1, max_row=last_row)
series1 = Series(y_values1, x_values, title_from_data=True)
chart1.series.append(series1)
# second chart
chart2 = ScatterChart()
chart2.title = "Existence"
chart2.x_axis.title = 'Time in s'
chart2.y_axis.title = 'Y-Axis'
chart2.x_axis.scaling.min = round(ws.cell(row=2, column=1).value, 0)
chart2.x_axis.scaling.max = ws.cell(row=last_row, column=1).value
for i in (7, 8, 12):
y_values2 = Reference(ws, min_col=i, min_row=1, max_row=last_row)
series2 = Series(y_values2, x_values, title_from_data=True)
chart2.series.append(series2)
ws.add_chart(chart1, "O2")
ws.add_chart(chart2, "O18")
Liebe Grüße
Serki92
Serki92