Legend Positioning and Entriy styling

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
patronas
Newbie
Newbie
Posts: 26
Joined: Fri Mar 01, 2019 12:00 am

Legend Positioning and Entriy styling

Post by patronas » Wed Mar 06, 2019 8:52 am

Hi,

I have a few questions concerning Legends:
1.) How can i vertically center legends with RIGHT alignment.
2.) How can I display only the n largest entries from a pie chart in the legend
3.) How can I truncate the displayed string in the legend if the number of characters exceed a certain umber?


Thanks for the supprt.

patronas
Newbie
Newbie
Posts: 26
Joined: Fri Mar 01, 2019 12:00 am

Re: Legend Positioning and Entriy styling

Post by patronas » Fri Mar 08, 2019 11:59 am

To get the limited legend, I have impolemented the following (Psudocode)

Code: Select all

Pie series = new Pie()
Pie legendSeries = new Pie();
chart.addSeries(series)
chart.addSeries(legendSeries)

legendSeries.setVisible(false)


for key,value in list:
	series.add(value, key, color)
	if index<5:
		legendSeries.add(value, key.substring(0,10), color)

chart.getLegend().setVisible(false);

extralegend = new ExtraLegend(chart.getChart());
extralegend.setSeries(legendSeries);
extralegend.getLegend().setVisible(false);

The problem is now that i ge a NPE:
java.lang.NullPointerException
at com.steema.teechart.drawing.Graphics3D.pointInEllipse(Graphics3D.java:783)
at com.steema.teechart.styles.Circular.clicked(Circular.java:247)
at com.steema.teechart.styles.Pie.clicked(Pie.java:1816)
at com.steema.teechart.styles.Series.clicked(Series.java:3339)
at com.steema.teechart.tools.MarksTip.findClickedSeries(MarksTip.java:198)
at com.steema.teechart.tools.MarksTip.mouseEvent(MarksTip.java:228)
at com.steema.teechart.Chart.broadcastMouseEvent(Chart.java:1016)
at com.steema.teechart.Chart.broadcastMouseEvent(Chart.java:1005)
at com.steema.teechart.Chart.mouseMoved(Chart.java:1406)
at com.steema.teechart.TChart.processMouseMotionEvent(TChart.java:1265)
at com.steema.teechart.TChart$3.handleEvent(TChart.java:378)
...
Am i doing something conceptually wrong?

Btw. I was inspired by this thread: viewtopic.php?f=10&t=14982&p=66405&hilit=legend#p66405

EDIT
I was further able detect that the exception does not occur if i do not set

Code: Select all

 new MarksTip(series.getChart());
So somehow it wants to react to the hidden series?


EDIT 2
Fixed psudo code to set correct visibility of second series

patronas
Newbie
Newbie
Posts: 26
Joined: Fri Mar 01, 2019 12:00 am

Re: Legend Positioning and Entriy styling

Post by patronas » Fri Mar 08, 2019 2:26 pm

Ok I have been able to more or less resolve this by doing something like:

Code: Select all


ie series = new Pie()
Pie legendSeries = new Pie();
chart.addSeries(series)
chart.addSeries(legendSeries)

legendSeries.setVisible(false)


for key,value in list:
	series.add(value, key, color)
	if index<5:
		legendSeries.add(value, key.substring(0,10), color)

chart.getLegend().setVisible(true);
chart.getLegend().setSeries(legendSeries)
However when activating tooltips with

Code: Select all

new MarksTip(series.getChart());
I get above NPE.
Could this be an actual bug?

patronas
Newbie
Newbie
Posts: 26
Joined: Fri Mar 01, 2019 12:00 am

Re: Legend Positioning and Entriy styling

Post by patronas » Fri Mar 08, 2019 3:11 pm

I was now able to resolve the issue by replacing

Code: Select all

new MarksTip(series.getChart());
by

Code: Select all

   final MarksTip toolTips = new MarksTip();
      toolTips.setSeries(series);
      toolTips.setChart(chart.getChart());

Post Reply