# Pie Chart label format

**URL:** <https://forum.inductiveautomation.com/t/pie-chart-label-format/50789>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [September 9, 2021, 6:53pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789 "2021-09-09T18:53:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 9, 2021, 6:53pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/1 "2021-09-09T18:53:41Z")

</div>

Using this post as inspiration, [Pie chart labels - #6 by zxcslo](https://forum.inductiveautomation.com/t/pie-chart-labels/37259/6),  
I have data from a SQL query, two columns, name and seconds (sum). I want to display the seconds as HH:mm:ss. I tried the following code, it doesn’t work, it locks the designer.

```auto
from org.jfree.chart.labels import StandardPieSectionLabelGenerator
import datetime	
		
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,
			defaultValues[1],
			str(datetime.timedelta(seconds=defaultValues[2]))
		)
			
	def generatedAttributedSectionLabel(self, dataset, key):
		return null
chart.plot.labelGenerator = LabelGenerator(self)

```

I also tried returning from SQL as string in HH:mm:ss, but then the value is displaysed as date from 1970 (I just want HH:mm:ss). I tried to format or parse in the above code and that also locked up the designer. What else can I do on this?

---

<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:** [September 14, 2021, 3:19pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/2 "2021-09-14T15:19:06Z")

</div>

‘Locking’ the designer is odd, that probably means the script is going into an infinite loop somehow.  
What if you change `generateSectionLabel` to return a constant string? e.g.

```auto
	def generateSectionLabel(self, dataset, key):
		return "test"

```

Does that still lock up?

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 14, 2021, 3:38pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/3 "2021-09-14T15:38:27Z")

</div>

That works fine, also so does this:

```auto
def generateSectionLabel(self, dataset, key):
			defaultValues = self.createItemArray(dataset, key)
			return "{0}: {1} ({2})".format(
				key,
				defaultValues[1],
				defaultValues[2]
			)

```

Replace `defaultValues[2]` with `str(datetime.timedelta(seconds=defaultValues[2]))` and the window will start blinking and then get unresponsive.

---

<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:** [September 14, 2021, 3:44pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/4 "2021-09-14T15:44:41Z")

</div>

It sounds like there might be an uncaught exception happening in your `timedelta` code then. Try wrapping it in a `try: except:` block? To see if you can find out the error; it won’t actually fix anything.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 14, 2021, 3:54pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/5 "2021-09-14T15:54:52Z")

</div>

Even if I use code from this post:

> [@Convert seconds to HH MM SS](https://forum.inductiveautomation.com/t/convert-seconds-to-hh-mm-ss/8739/18):
>
> If your talking doing the same thing but through a script it is identical but using script functions. You would need to do a system.tag.read(tag path).value to get your seconds and store it in a variable but then you would insert your variable into the script. Then it depends where the script is to how to put it in the label. time = system.date.format(system.date.addSeconds(system.date.midnight(system.date.now()),insert your seconds val here),"HH:mm:ss")

```auto
m,s = divmod(defaultValues[2], 60)
h,m = divmod(m, 60)
time = '{hr:02d}:{mn:02d}:{sc:02d}'.format(hr=h,mn=m,sc=s)

```

It goes bonkers. The interesting thing is I can't interact with anything on the window, but I can the project browser. I can edit the component in the browser, by disabling the extension. But, even after disabling, the window is still "locked' up. I have to restart the designer. I guess I will give IA a call.

---

<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:** [September 14, 2021, 4:08pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/6 "2021-09-14T16:08:30Z")

</div>

I threw it into the IDE and get this:

```auto
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
  File "<extension-method configureChart>", line 21, in generateSectionLabel
  File "C:\Users\pgriffith\Projects\ignition\IDE-Launchers\gateway-launcher\src\main\home\user-lib\pylib\datetime.py", line 500, in __new__
    seconds += minutes*60 + hours*3600
TypeError: cannot concatenate 'unicode' and 'int' objects

```

Try

```auto
	def generateSectionLabel(self, dataset, key):
		defaultValues = self.createItemArray(dataset, key)
		return "{0}: {1} ({2})".format(
			key,
			defaultValues[1],
			str(datetime.timedelta(seconds=int(defaultValues[2])))
		)

```

EDIT: Nope, still not quite there:

```auto
Exception in thread "AWT-EventQueue-0" Traceback (most recent call last):
  File "<extension-method configureChart>", line 21, in generateSectionLabel
ValueError: invalid literal for int() with base 10: '15%'

```

---

<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:** [September 14, 2021, 4:16pm UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/7 "2021-09-14T16:16:11Z")

</div>

There it is:

```auto
	from org.jfree.chart.labels import StandardPieSectionLabelGenerator
	import datetime	
			
	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} \n({2})".format(
				key,
				defaultValues[1],
				str(datetime.timedelta(seconds=dataset.getValue(key)))
			)

		def generatedAttributedSectionLabel(self, dataset, key):
			return null
	chart.plot.labelGenerator = LabelGenerator(self)

```

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

---

<div class="post-metadata">

**Author:** ![Meena\_M](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@Meena\_M](https://forum.inductiveautomation.com/u/Meena_M)\
**Post date:** [September 30, 2024, 4:55am UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/8 "2024-09-30T04:55:30Z")

</div>

Dear Team,  
I attempted this. But i wa unable to get the desired outcome.Could you please assist me.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/4/a43f3085d41190fc554f32e24626efd8d20bfdd5.png)  
 ![Screenshot 2024-09-30 101054](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/019620faa74b5a1b579b79af59b8837be27aa295.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 30, 2024, 11:48am UTC](https://forum.inductiveautomation.com/t/pie-chart-label-format/50789/9 "2024-09-30T11:48:32Z")

</div>

Show your code.

Otherwise, you've just posted pretty pictures.

EDIT: Also, note that the scripting in this thread is for Vision, and is incompatible with perspective.
