# Pie chart labels

**URL:** <https://forum.inductiveautomation.com/t/pie-chart-labels/37259>\
**Category:** Ignition\
**Tags:** ignition79, vision\
**Created:** [July 31, 2020, 2:18pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259 "2020-07-31T14:18:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [July 31, 2020, 2:18pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/1 "2020-07-31T14:18:59Z")

</div>

I have this situation:

 ![PieChatLabels](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/b/4b8043f9c1ba99504f2486cde3f2a8872bbafca4.png)  
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

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [July 16, 2021, 12:22pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/2 "2021-07-16T12:22:39Z")

</div>

Bump…

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 16, 2021, 4:23pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/3 "2021-07-16T16:23:20Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/3/d3f72f8fef916f8a6eb009057fea1b1eb9b68066.png)

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [July 16, 2021, 5:03pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/4 "2021-07-16T17:03:42Z")

</div>

That was one year ago… I don’t have it any more.  
But here is another one… from ‘Alarm Analysis’ from [Ignition Exhange](https://inductiveautomation.com/exchange/95/overview)

 ![Screenshot_17](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/d/cd692889f5848426d99629bc67c78653dae32cea.png)

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 16, 2021, 5:41pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/5 "2021-07-16T17:41:01Z")

</div>

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…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fdb71b6b925426b94fb83eb3115d51c4f30c9bf8.png)

```python
	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() 

```

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [July 16, 2021, 6:07pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/6 "2021-07-16T18:07:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 16, 2021, 6:32pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/7 "2021-07-16T18:32:26Z")

</div>

```auto
	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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/2/b2d9bef23d346782021921bcba4a5bfa8e32bf6c.png)

---

<div class="post-metadata">

**Author:** ![zxcslo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zxcslo/32/61610_2.png) [@zxcslo](https://forum.inductiveautomation.com/u/zxcslo)\
**Post date:** [July 16, 2021, 6:41pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/8 "2021-07-16T18:41:44Z")

</div>

That’s it! 👏 👍  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 16, 2021, 6:42pm UTC](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/9 "2021-07-16T18:42:56Z")

</div>

> [@paul-griffith](#):
>
> defaultValues[2]`

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