Pie chart labels

I have this situation:


The upper table and Piechart shows the values for the duration in seconds.
And the labels on the Piechart shows ok.
The lower table and Pierchart show are showing the duration in more ‘readable’ format (hours:minutes:seconds).
But the labels on the Piechart are not showing, what is in the table…?

Is it possible somehow to show the duration in Piechart labels like HH:MM:SS?

EDIT: Ignition 7.9.14

Bump…

What’s the datatype of your duration field in the second example?
I can’t get a mockup to behave the same way:

That was one year ago… I don’t have it any more.
But here is another one… from ‘Alarm Analysis’ from Ignition Exhange

It’s string. It’s comming from SQL query:

SELECT 
	RIGHT(a.source,- POSITION('alm:' in a.source)-3) alarm,
    TO_CHAR((SUM(EXTRACT(EPOCH FROM (COALESCE(c.eventtime, CURRENT_TIMESTAMP) - a.eventtime))) || ' second')::interval, 'HH24:MI:SS') AS duration
FROM 
	alarm_events a 
		LEFT JOIN alarm_events c ON c.eventid = a.eventid AND c.eventtype = 1 
WHERE a.eventtype = 0 AND a.eventflags != 1
GROUP BY 
	a.source
ORDER BY 
	duration desc, a.source ASC

What I’m trying to do is show a more readable time format in the Pie Chart label…
Ah, and this is now in Ignition Vision 8.1.7.

There’s really no great solution. Even in the exchange template, notice how the label is showing 0 or 1? The value has already been coerced into a number by this point, so precision has already been lost. You can technically go ‘back’ to the original dataset via configureChart, but it’s not great…

	from org.jfree.chart.labels import PieSectionLabelGenerator
	
	class LabelGenerator(PieSectionLabelGenerator):
		def generateSectionLabel(this, dataset, key):
			return "{0}: {1} ({2})".format(
				key,
				dataset.getValue(key),
				self.data.getValueAt(dataset.getIndex(key), 1),
			)
	chart.plot.labelGenerator = LabelGenerator() 
1 Like

That is very very … close… except that inside the parenthesis, there is no percentage but the first number from that string…

	from org.jfree.chart.labels import StandardPieSectionLabelGenerator
	
	class LabelGenerator(StandardPieSectionLabelGenerator):
		def __init__(self, component):
			self.component = component
			StandardPieSectionLabelGenerator.__init__(self, "")
			
		def generateSectionLabel(self, dataset, key):
			defaultValues = self.createItemArray(dataset, key)
			return "{0}: {1} ({2})".format(
				key,
				self.component.data.getValueAt(dataset.getIndex(key), 1),
				defaultValues[2]
			)
	chart.plot.labelGenerator = LabelGenerator(self)

image

3 Likes

That’s it! :clap: :+1:
Thank you very much.

For some explanation, you can change the index in this line to get access to the original {0}, {1}, {2}, {3} values.

1 Like