<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Pie Chart Labels organisation in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738378#M91976</link>
    <description>Thanks &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;.&lt;BR /&gt;As my data are changing every month and all categories are not always present it is hard for me to code all of this, even the offset mais not be for every month.&lt;BR /&gt;As an alternative I can put the labels on sections of pie chart and alternate the distance to the center of the pie to ensure they are not overlapping. Do you know if the option existes or do I need to script that?&lt;BR /&gt;Thanks again</description>
    <pubDate>Sun, 24 Mar 2024 07:32:26 GMT</pubDate>
    <dc:creator>mgerusdurand</dc:creator>
    <dc:date>2024-03-24T07:32:26Z</dc:date>
    <item>
      <title>Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738108#M91938</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I try to dig in the community to find my answer but couldn't.&lt;BR /&gt;I have a script generating monthly report as a pie chart. I moved the labels on first one to make them readable and copy the position in my script. This is working when using the same data but the répartition of data is not the same over months so labels become overlapping again.&lt;BR /&gt;Is there a way to have connecting lines between the pie section and data so they can be spread over the pie while staying visible, without overlapping? I am using JMP 16 to 18.&lt;BR /&gt;Thanks for your help</description>
      <pubDate>Fri, 22 Mar 2024 21:44:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738108#M91938</guid>
      <dc:creator>mgerusdurand</dc:creator>
      <dc:date>2024-03-22T21:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738258#M91956</link>
      <description>&lt;P&gt;I don't know of a way of adding such lines to pie chart easily. You could calculate those lines and add them with a script or perform some calculations and set the offsets by script.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2024 16:15:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738258#M91956</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-23T16:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738378#M91976</link>
      <description>Thanks &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;.&lt;BR /&gt;As my data are changing every month and all categories are not always present it is hard for me to code all of this, even the offset mais not be for every month.&lt;BR /&gt;As an alternative I can put the labels on sections of pie chart and alternate the distance to the center of the pie to ensure they are not overlapping. Do you know if the option existes or do I need to script that?&lt;BR /&gt;Thanks again</description>
      <pubDate>Sun, 24 Mar 2024 07:32:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738378#M91976</guid>
      <dc:creator>mgerusdurand</dc:creator>
      <dc:date>2024-03-24T07:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738391#M91977</link>
      <description>&lt;P&gt;I would most likely use something else than Pie Chart (much easier than start scripting Pie segments, even the documentation in Scripting Index is wrong in most of the cases for that...), but this seems like a nice challenge so I'll try to write some sort of a script for this.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 08:08:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738391#M91977</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-24T08:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738405#M91979</link>
      <description>Thanks a lot. I can try too but I think you will be much faster than me.&lt;BR /&gt;I tried to make my supervisor change her mind for another graphic representation but she wants a pie chart unfortunately :pensive_face:&lt;/img&gt;, this is not my favourite.&lt;BR /&gt;I will write something on the wish list too because it is true that scripting index is not good for this.&lt;BR /&gt;&lt;BR /&gt;Thanks again</description>
      <pubDate>Sun, 24 Mar 2024 09:04:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738405#M91979</guid>
      <dc:creator>mgerusdurand</dc:creator>
      <dc:date>2024-03-24T09:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738409#M91980</link>
      <description>&lt;P&gt;Too bad you cannot get rid of the pie chart (most overused and usually bad way to visualize anything). Below is script which might give some idea what you could do, the calculations definitely aren't optimal but they might work (I don't really remember unit circle and trigonometry anymore)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

ADJUSTED_LOCATION = 0.8 ; // default is 1

dt = open("$SAMPLE_DATA/Big Class.jmp");

gb = dt &amp;lt;&amp;lt; Graph Builder(
	Variables(X(:age), Y(:height)),
	Elements(Pie(X, Y, Legend(2), Summary Statistic("Sum"), Label("Label by Value")))
);

fb = Report(gb)[FrameBox(1)];
pie = fb &amp;lt;&amp;lt; Find Seg("Pie Seg");
{x_origo, y_origo} = pie &amp;lt;&amp;lt; Get Origin;
radius = pie &amp;lt;&amp;lt; Get Radius;

Summarize(dt, groups = By(:age), sums = Sum(:height)); // we must know summary statistic used in pie chart
r_sections = Reverse((sums / Sum(sums)) * 2 * Pi());

angles = {};
For Each({section, idx}, r_sections,
	angle = (section + Pi()) / 2;
	If(idx &amp;gt; 1,
		angle = angle + Sum(r_sections[1::idx - 1]);
	);
	Insert Into(angles, angle);
);


label_locations = {};
For Each({angle, idx}, angles,
	i = N Items(angles) - idx;
	xcoord = x_origo + ADJUSTED_LOCATION * Cos(angle);
	ycoord = y_origo + ADJUSTED_LOCATION * Sin(angle);
	
	location = Eval List({i, xcoord, ycoord});
	Insert Into(label_locations, Eval List({location}));
);

For Each({location}, label_locations,
	Eval(EvalExpr(
		pie &amp;lt;&amp;lt; Set Label Offset(Expr(location));
	));
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;default&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_2-1711272611572.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/62572iCF937680C922C6F9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_2-1711272611572.png" alt="jthi_2-1711272611572.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;ADJUSTED_LOCATION = 0.8&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1711272568085.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/62570i02C357B0A3BFB102/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1711272568085.png" alt="jthi_0-1711272568085.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;ADJUSTED_LOCATION = 1.1&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_1-1711272587102.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/62571i81BDD0060A19DF95/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_1-1711272587102.png" alt="jthi_1-1711272587102.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This could be turned into a function which would be able to add lines to the labels.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 09:37:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738409#M91980</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-24T09:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738411#M91981</link>
      <description>&lt;P&gt;Example how lines could be added&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

ADJUSTED_LOCATION = 1 ; // default is 1

dt = open("$SAMPLE_DATA/Big Class.jmp");

gb = dt &amp;lt;&amp;lt; Graph Builder(
	Variables(X(:age), Y(:height)),
	Elements(Pie(X, Y, Legend(2), Summary Statistic("Sum"), Label("Label by Value")))
);

calculate_pie_graph_angles = Function({gb}, {Default Local},
	dt = gb &amp;lt;&amp;lt; Get Data Table;
	
	// Get X and Y columns (doesn't currently support Overlay)
	vars = gb &amp;lt;&amp;lt; Get Variables;
	xcol = Empty();
	ycol = Empty();
	For Each({var}, vars,
		role = var["Role"];
		If(role == "X",
			xcol = Arg(var, 1) &amp;lt;&amp;lt; get name; // I don't use references
		, role == "Y",
			ycol = Arg(var, 1) &amp;lt;&amp;lt; get name; // I don't use references
		);
	);

	// Get summary statistic
	elements = gb &amp;lt;&amp;lt; Get Elements(1, 1);
	summary_stat = Try(elements[1]["Summary Statistic"], "Mean"); // We assume Mean is the default one

	// Calculate groups and segments
	// I'm lazy and use Evil Parse here
	stat = Eval Insert("^summary_stat^(Eval(ycol))");
	Eval(EvalExpr(
		dt_summary = dt &amp;lt;&amp;lt; Summary(
			Group(Eval(xcol)),
			Expr(Parse(stat)),
			Freq("None"),
			Weight("None"),
			statistics column name format("column"),
			Link to original data table(0),
			invisible
		);
	));

	groups = dt_summary[0, 1]; // 2 is N Rows
	stats = dt_summary[0, 3];
	Close(dt_summary, no save);

	// calculate segments
	r_sections = Reverse((stats / Sum(stats)) * 2 * Pi());

	angles = {};
	For Each({section, idx}, r_sections,
		angle = (section + Pi()) / 2;
		If(idx &amp;gt; 1,
			angle = angle + Sum(r_sections[1::idx - 1]);
		);
		Insert Into(angles, angle);
	);
	
	Return(Reverse(angles));
);


get_segment_locations = Function({pie, angles, radius = 1}, {Default Local},
	{x_origo, y_origo} = pie &amp;lt;&amp;lt; Get Origin;
	pie_radius = pie &amp;lt;&amp;lt; Get Radius;

	label_locations = {};
	For Each({angle, idx}, angles,
		i = idx - 1;
		xcoord = x_origo + radius * Cos(angle);
		ycoord = y_origo + radius * Sin(angle);
		
		location = Eval List({i, xcoord, ycoord});
		Insert Into(label_locations, Eval List({location}));
	);
	
	return(label_locations);
);

fb = Report(gb)[FrameBox(1)];
pie = fb &amp;lt;&amp;lt; Find Seg("Pie Seg");

angles = calculate_pie_graph_angles(gb);
offsets1 = get_segment_locations(pie, angles, 1.05);

For Each({location}, offsets,
	Eval(EvalExpr(
		pie &amp;lt;&amp;lt; Set Label Offset(Expr(location));
	));
);

offsets2 = get_segment_locations(pie, angles, 0.9);
offsets3 = get_segment_locations(pie, angles, 1.02);
For Each({{start, end}}, Across(offsets2, offsets3),
	Eval(EvalExpr(
		x = start[2] || end[2];
		y = start[3] || end[3];
		fb &amp;lt;&amp;lt; Add Graphics Script(
			Line(
				Expr(x), Expr(y)
			);
		);
	));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1711274953677.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/62573i72C79CEA06D163D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1711274953677.png" alt="jthi_0-1711274953677.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 10:20:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738411#M91981</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-24T10:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738446#M91985</link>
      <description>&lt;P&gt;Echoing the other comments, don't use pie charts - I'm more emphatic than others on this point.&amp;nbsp; But here is a very good presentation illustrating why it is always better to use a bar chart (or similar alternatives) than a pie chart:&amp;nbsp; &lt;A href="https://speakerdeck.com/cherdarchuk/data-looks-better-naked-pie-chart-edition" target="_blank"&gt;https://speakerdeck.com/cherdarchuk/data-looks-better-naked-pie-chart-edition&lt;/A&gt;.&amp;nbsp; I'd view this a chance to educate your supervisor.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 15:08:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738446#M91985</guid>
      <dc:creator>dlehman1</dc:creator>
      <dc:date>2024-03-24T15:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738448#M91987</link>
      <description>Wow you were so fast!&lt;BR /&gt;Thanks a lot Jarmo this do the job perfectly</description>
      <pubDate>Sun, 24 Mar 2024 15:39:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738448#M91987</guid>
      <dc:creator>mgerusdurand</dc:creator>
      <dc:date>2024-03-24T15:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Pie Chart Labels organisation</title>
      <link>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738450#M91989</link>
      <description>Hello &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/53879"&gt;@dlehman1&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;Thanks for the link. I will try to educate them but they have pretty strong feelings for pie chart. I will make the parallel with other visualisation to try to convince them.&lt;BR /&gt;</description>
      <pubDate>Sun, 24 Mar 2024 15:41:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Pie-Chart-Labels-organisation/m-p/738450#M91989</guid>
      <dc:creator>mgerusdurand</dc:creator>
      <dc:date>2024-03-24T15:41:25Z</dc:date>
    </item>
  </channel>
</rss>

