I want to make a pie chart and have looked at the documentation (it's in C, which I do not understand) and am having trouble. I have 8 slices of the pie and I want each a different color. Here is what I have so far, which produces at least one error (comes on the line: series.append("Auto", auto):
series = QPieSeries()
chart = QChart()
# Each slice's value
auto = self.expensesWindow.piechart[0]
employ = self.expensesWindow.piechart[1]
ins = self.expensesWindow.piechart[2]
hh = self.expensesWindow.piechart[3]
house = self.expensesWindow.piechart[4]
enter = self.expensesWindow.piechart[5]
util = self.expensesWindow.piechart[6]
other = self.expensesWindow.piechart[7]
#
# Set up the pie
series.append("Auto", auto)
series.append("Employ", employ)
series.append("Insurance", ins)
series.append("Household", hh)
series.append("House", house)
series.append("Entertainment", enter)
series.append("Utilities", util)
series.append("Other)", other)
#
chart.addSeries(series)
series = QPieSeries()
chart = QChart()
# Each slice's value
auto = self.expensesWindow.piechart[0]
employ = self.expensesWindow.piechart[1]
ins = self.expensesWindow.piechart[2]
hh = self.expensesWindow.piechart[3]
house = self.expensesWindow.piechart[4]
enter = self.expensesWindow.piechart[5]
util = self.expensesWindow.piechart[6]
other = self.expensesWindow.piechart[7]
#
# Set up the pie
series.append("Auto", auto)
series.append("Employ", employ)
series.append("Insurance", ins)
series.append("Household", hh)
series.append("House", house)
series.append("Entertainment", enter)
series.append("Utilities", util)
series.append("Other)", other)
#
chart.addSeries(series)
To copy to clipboard, switch view to plain text mode
Regarding the color of each slice, I came up with this example for one of the slices (but likely not correct) and don't know where to put it:
Auto = QPieSlice("Auto")
Auto.
setBrush(QPieSlice.
setColor(QColor('#00FF00')))
Auto = QPieSlice("Auto")
Auto.setBrush(QPieSlice.setColor(QColor('#00FF00')))
To copy to clipboard, switch view to plain text mode
To show the chart:
self.chartView = QChartView(chart)
self.ui.gridLayout.addWidget(self.chartView)
self.chartView = QChartView(chart)
self.ui.gridLayout.addWidget(self.chartView)
To copy to clipboard, switch view to plain text mode
I need help getting the construction of the pie chart to work. thanks
I want to make a pie chart and have looked at the documentation (it's in C, which I do not understand) and am having trouble. I have 8 slices of the pie and I want each a different color. Here is what I have so far, which produces at least one error (comes on the line: series.append("Auto", auto):
series = QPieSeries()
chart = QChart()
# Each slice's value
auto = self.expensesWindow.piechart[0]
employ = self.expensesWindow.piechart[1]
ins = self.expensesWindow.piechart[2]
hh = self.expensesWindow.piechart[3]
house = self.expensesWindow.piechart[4]
enter = self.expensesWindow.piechart[5]
util = self.expensesWindow.piechart[6]
other = self.expensesWindow.piechart[7]
#
# Set up the pie
series.append("Auto", auto)
series.append("Employ", employ)
series.append("Insurance", ins)
series.append("Household", hh)
series.append("House", house)
series.append("Entertainment", enter)
series.append("Utilities", util)
series.append("Other)", other)
#
chart.addSeries(series)
series = QPieSeries()
chart = QChart()
# Each slice's value
auto = self.expensesWindow.piechart[0]
employ = self.expensesWindow.piechart[1]
ins = self.expensesWindow.piechart[2]
hh = self.expensesWindow.piechart[3]
house = self.expensesWindow.piechart[4]
enter = self.expensesWindow.piechart[5]
util = self.expensesWindow.piechart[6]
other = self.expensesWindow.piechart[7]
#
# Set up the pie
series.append("Auto", auto)
series.append("Employ", employ)
series.append("Insurance", ins)
series.append("Household", hh)
series.append("House", house)
series.append("Entertainment", enter)
series.append("Utilities", util)
series.append("Other)", other)
#
chart.addSeries(series)
To copy to clipboard, switch view to plain text mode
Regarding the color of each slice, I came up with this example for one of the slices (but likely not correct) and don't know where to put it:
Auto = QPieSlice("Auto")
Auto.
setBrush(QPieSlice.
setColor(QColor('#00FF00')))
Auto = QPieSlice("Auto")
Auto.setBrush(QPieSlice.setColor(QColor('#00FF00')))
To copy to clipboard, switch view to plain text mode
To show the chart:
self.chartView = QChartView(chart)
self.ui.gridLayout.addWidget(self.chartView)
self.chartView = QChartView(chart)
self.ui.gridLayout.addWidget(self.chartView)
To copy to clipboard, switch view to plain text mode
I need help getting the construction of the pie chart to work. thanks
Added after 1 21 minutes:
Originally Posted by
dennisvz
I want to make a pie chart and have looked at the documentation (it's in C, which I do not understand) and am having trouble. I have 8 slices of the pie and I want each a different color. Here is what I have so far, which produces at least one error (comes on the line: series.append("Auto", auto):
series = QPieSeries()
chart = QChart()
# Each slice's value
auto = self.expensesWindow.piechart[0]
employ = self.expensesWindow.piechart[1]
ins = self.expensesWindow.piechart[2]
hh = self.expensesWindow.piechart[3]
house = self.expensesWindow.piechart[4]
enter = self.expensesWindow.piechart[5]
util = self.expensesWindow.piechart[6]
other = self.expensesWindow.piechart[7]
#
# Set up the pie
series.append("Auto", auto)
series.append("Employ", employ)
series.append("Insurance", ins)
series.append("Household", hh)
series.append("House", house)
series.append("Entertainment", enter)
series.append("Utilities", util)
series.append("Other)", other)
#
chart.addSeries(series)
series = QPieSeries()
chart = QChart()
# Each slice's value
auto = self.expensesWindow.piechart[0]
employ = self.expensesWindow.piechart[1]
ins = self.expensesWindow.piechart[2]
hh = self.expensesWindow.piechart[3]
house = self.expensesWindow.piechart[4]
enter = self.expensesWindow.piechart[5]
util = self.expensesWindow.piechart[6]
other = self.expensesWindow.piechart[7]
#
# Set up the pie
series.append("Auto", auto)
series.append("Employ", employ)
series.append("Insurance", ins)
series.append("Household", hh)
series.append("House", house)
series.append("Entertainment", enter)
series.append("Utilities", util)
series.append("Other)", other)
#
chart.addSeries(series)
To copy to clipboard, switch view to plain text mode
Regarding the color of each slice, I came up with this example for one of the slices (but likely not correct) and don't know where to put it:
Auto = QPieSlice("Auto")
Auto.
setBrush(QPieSlice.
setColor(QColor('#00FF00')))
Auto = QPieSlice("Auto")
Auto.setBrush(QPieSlice.setColor(QColor('#00FF00')))
To copy to clipboard, switch view to plain text mode
To show the chart:
self.chartView = QChartView(chart)
self.ui.gridLayout.addWidget(self.chartView)
self.chartView = QChartView(chart)
self.ui.gridLayout.addWidget(self.chartView)
To copy to clipboard, switch view to plain text mode
I need help getting the construction of the pie chart to work. thanks
UPDATE: I got the pie chart to work (the code was correct - there was an error in the data file), but I still need to know how to make each piece of the pie a color of my choosing.
SOLVED: Thanks for looking
_slice = series.append("Auto", self.expensesWindow.piechart[0])
_slice.
setBrush(QColor('#00FF00')) _slice = series.append("Employment", self.expensesWindow.piechart[1])
_slice.
setBrush(QColor('#1a8cff')) _slice = series.append("Insurance", self.expensesWindow.piechart[2])
_slice.
setBrush(QColor('#ff0000')) _slice = series.append("Household", self.expensesWindow.piechart[3])
_slice.
setBrush(QColor('#cccccc')) _slice = series.append("Housing", self.expensesWindow.piechart[4])
_slice.
setBrush(QColor('#00ffff')) _slice = series.append("Entertainment", self.expensesWindow.piechart[5])
_slice.
setBrush(QColor('#ff00ff')) _slice = series.append("Utilities", self.expensesWindow.piechart[6])
_slice.
setBrush(QColor('#ff7f50')) _slice = series.append("Other", self.expensesWindow.piechart[7])
_slice.
setBrush(QColor('#ffff00'))
_slice = series.append("Auto", self.expensesWindow.piechart[0])
_slice.setBrush(QColor('#00FF00'))
_slice = series.append("Employment", self.expensesWindow.piechart[1])
_slice.setBrush(QColor('#1a8cff'))
_slice = series.append("Insurance", self.expensesWindow.piechart[2])
_slice.setBrush(QColor('#ff0000'))
_slice = series.append("Household", self.expensesWindow.piechart[3])
_slice.setBrush(QColor('#cccccc'))
_slice = series.append("Housing", self.expensesWindow.piechart[4])
_slice.setBrush(QColor('#00ffff'))
_slice = series.append("Entertainment", self.expensesWindow.piechart[5])
_slice.setBrush(QColor('#ff00ff'))
_slice = series.append("Utilities", self.expensesWindow.piechart[6])
_slice.setBrush(QColor('#ff7f50'))
_slice = series.append("Other", self.expensesWindow.piechart[7])
_slice.setBrush(QColor('#ffff00'))
To copy to clipboard, switch view to plain text mode
Bookmarks