Hello!
I´ve got a Named Query with 2 columns binded to the data property of a Pie Chart.
It show the Pie Chart with the data for a second but later dissapear
Should I add a Transform Script to the Named Query to keep it stable?
Hello!
I´ve got a Named Query with 2 columns binded to the data property of a Pie Chart.
It show the Pie Chart with the data for a second but later dissapear
Should I add a Transform Script to the Named Query to keep it stable?
If the table was using a dataset you could use a simple expression function columnRearrange | Ignition User Manual to return just the two columns of interest.
In a quick test with the default table data the Pie Chart component seems to use the first column as labels and the first numeric column as values. This might not be correct.
It looks like you are using JSON so you'll need a script transform.
def transform(self, value, quality, timestamp):
pieData = []
for row in value:
pieData.append({
"city": row['city'],
"population": row['population']
})
return pieData
Thanks Transistor,
I just added the code, and I was able to put the data on the pie
def transform(self, value, quality, timestamp):
pieData = []
for row in value:
pieData.append({
"label": str(row['RIESGO']),
"value": float(row['TOTAL'])
})
return pieData
but the graph is not showing data,
no errors show on props.data, just java errors in the console
At the bottom of the docs, https://docs.inductiveautomation.com/docs/8.1/appendix/components/perspective-components/perspective-chart-palette/perspective-pie-chart#example,
Value types can vary as you can pass both "50" and 50 as counts and the Pie Chart will still be able to render the data correctly.
...
The query used must return two columns in any order where each column represents a string and a numeric value to be rendered by the chart.
The Pie Chart is trying to be smart. It sees that both label
and value
are numeric so it gets confused and doesn't know which is the label. Try this:
def transform(self, value, quality, timestamp):
pieData = []
for row in value:
pieData.append({
"label": "RIESGO " + str(row['RIESGO'])),
"value": row['TOTAL']
})
return pieData
Wow!, it works! thanks a lot Transistor.
def transform(self, value, quality, timestamp):
pieData = []
for row in value:
pieData.append({
"label": "RIESGO " + str(row['RIESGO']), # Convert RIESGO to string
"value": float(row['TOTAL']) # Ensure TOTAL is a number
})
return pieData
The str()
is required. I fixed my post.
The float()
is not required, I think. The doc suggests that the chart will take numbers or numeric strings and convert them.