swathy

Legends In Pie Charts

Recommended Posts

Hi

I am working with Fusion charts 3.2.1. i am using single series pie charts 2D/3D and i want to display legends at the right side of my jsp page.

 

I have given showLegend ="1",legendPosition ="RIGHT" and styles also included. but still i am not getting legends on my page.

 

Is there anything more i have to include. please suggest.

 

Thanks in advance!

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Welcome to FusionCharts Forum!smile.gif

 

First of all, we would like to thank you for showing interest in FusionCharts.

 

Could you please confirm whether you are using JavaScript fallback?

 

Awaiting for your response.

Share this post


Link to post
Share on other sites

Hi

Thanks for ur Reply.

 

No i am not using any javascript fallback. i am preparing my xml data from a seperate java file

 

and convert it as a string in jsp then pass it to the object.

 

Hi,

 

Welcome to FusionCharts Forum!smile.gif

 

First of all, we would like to thank you for showing interest in FusionCharts.

 

Could you please confirm whether you are using JavaScript fallback?

 

Awaiting for your response.

Share this post


Link to post
Share on other sites

Hi

Thanks for ur Reply.

 

No i am not using any javascript fallback. i am preparing my xml data from a seperate java file

 

and convert it as a string in jsp then pass it to the object.

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Thanks for your response.

 

Could you please send us the generated XML code to test it from our end?

 

Awaiting for your reply.

Share this post


Link to post
Share on other sites

sure i will send it

 

first i am sending jsp side code for xml data

 

 

HashMap mapChartAttributes = new HashMap();//map for chart attributes

mapChartAttributes.put("bgcolor","FFFFFF");

mapChartAttributes.put("enablesmartLabels","0");

mapChartAttributes.put("showToolTip","0");

mapChartAttributes.put("showPercentValues","0");

mapChartAttributes.put("palette","2");

mapChartAttributes.put("pieRadius","90");

mapChartAttributes.put("showLegend","1");

mapChartAttributes.put("legendPosition","RIGHT");

 

HashMap mapChartData = new HashMap();//map for chart data

mapChartData.put("pieLabels",countName);

mapChartData.put("pieValues",countValue);

mapChartData.put("pieColors",colorValue);

 

HashMap mapProperties = new HashMap();//map for misc properties

mapProperties.put("showLabels","false");

mapProperties.put("showColors","true");

mapProperties.put("enableLinks","false");

 

EcFusionChartBean chartbean = new EcFusionChartBean();

String xmlString = chartbean.getXMLDataForPieChart(mapChartAttributes,mapChartData,mapProperties);

 

i am passing this xmlstring into my code

 

and java code is

 

public String getXMLDataForPieChart(Map chartAttributes,Map chartData,Map miscProperties) throws UnsupportedEncodingException

{

ArrayList aListColors = new ArrayList();

ArrayList aListLinks = new ArrayList();

int colCount = 0;

 

String pieLabels = (String)chartData.get("pieLabels");

String pieValues = (String)chartData.get("pieValues");

String pieColors = (String)chartData.get("pieColors");

String pieLinks = (String)chartData.get("pieLinks");

 

Iterator itrchart = chartAttributes.keySet().iterator();

String xmlData = "<Chart ";

while (itrchart.hasNext())

{

String chartAttribute = (String)itrchart.next();

String chartAttributeValue = (String)chartAttributes.get(chartAttribute);

xmlData += chartAttribute + "=" + "'" + chartAttributeValue + "' ";

}

xmlData += ">";

 

if (pieColors!= null)

{

StringTokenizer strColors = new StringTokenizer(pieColors,",");

while (strColors.hasMoreTokens())

{

String chartColor = strColors.nextToken();

chartColor = chartColor.substring(chartColor.indexOf("#")+1);

aListColors.add(chartColor);

}

}

 

if (pieLinks != null)

{

StringTokenizer strLinks = new StringTokenizer(pieLinks,",");

while (strLinks.hasMoreTokens())

{

String chartLink = strLinks.nextToken();

aListLinks.add(chartLink);

}

}

 

String showLabels = null;

String showColors = null;

String enableLinks = null;

if (miscProperties != null && !miscProperties.isEmpty())

{

showLabels = (String)miscProperties.get("showLabels");

showColors = (String)miscProperties.get("showColors");

enableLinks = (String)miscProperties.get("enableLinks");

}

 

StringTokenizer strValues = new StringTokenizer(pieValues,",");

StringTokenizer strLabels = new StringTokenizer(pieLabels,",");

while (strValues.hasMoreTokens())

{

String chartValue = strValues.nextToken();

String chartLabel = strLabels.nextToken();

 

xmlData += "<set value='" + chartValue + "' ";

 

if (showLabels != null && showLabels.equalsIgnoreCase("true"))

{

xmlData += " label='" + chartLabel + "'";

}

 

if (showColors != null && showColors.equalsIgnoreCase("true"))

{

xmlData += " color='" + aListColors.get(colCount) + "'";

}

 

if (enableLinks != null && enableLinks.equalsIgnoreCase("true"))

{

xmlData += " link='" + EgURLEncoder.encode((String)aListLinks.get(colCount),"UTF-8") + "'";

}

 

xmlData += " />";

 

colCount++;

}

 

xmlData +="<styles>"+"<definition>"+"<style name='myLegendFont' type='font' size='11' color ='FFFFFF' bold='1'/>"+"</definition>"+"<application>"+"<apply toObject='Legend' styles='myLegendFont' />"+"</application>"+"</styles>";

xmlData += "</Chart>";

 

return xmlData;

}

 

waiting for ur reply!

Share this post


Link to post
Share on other sites

Hi srividya

 

 

Thanks for ur reply! I am sending the output of the xmlstring for ur kind notice. please view it.

 

xmlString ==> <Chart showLegend='1' showPercentValues='0' enablesmartLabels='0' bgcolor='FFFFFF' showBorder='0' showToolTip='0' pieRadius='90' legendPosition='RIGHT' ><set value='1' color='ABDDA4' /><set value='1' color='386CB0' /><styles><definition><style type='font' name='myLegendFont' type='font' size='11' color ='FFFFFF' bold='1'/></definition><application><apply toObject='Legend' styles='myLegendFont' /></application></styles></Chart>

 

Awaiting for your reply.

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Thanks for your response.

In Pie / doughnut charts, the data label of each slice shows up in the legend of the chart.

 

It seems from your XML code that you have not specified any data labels to show as the legend.

 

Please try the same by setting <label> attribute inside the <set> element.

Please find the modified XML code below:

 

<chart showLegend='1' showLabels='1' showPercentValues='0' enableSmartLabels='1' bgcolor='FFFFFF' showBorder='0' showToolTip='0' pieRadius='90' legendPosition='RIGHT'>
<set value='1' color='ABDDA4' label='Legend 1' />
<set value='1' color='386CB0' Label='Legend 2' />
</chart>

Hope this works.smile.gif

Share this post


Link to post
Share on other sites

Hi Angshu

 

Thanks for ur reply!

 

I copied ur code and pasted it doesnt work.

 

it is just showing legend 1 and legend 2 as a smartlabel for chart alone.

 

legend is still not coming. I wantedly not shown the labels.

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Could you please enable the debug mode and send us the screenshot?

 

The code is working fine from our end and legend is showing properly.

 

Please find the screenshot attached for your reference.

 

Awaiting for your response.

post-10517-0-32484400-1310650927_thumb.png

Share this post


Link to post
Share on other sites

Hi Angshu

 

Thank u very much :).

 

The code is working fine. I am getting chart and legend now.

 

And one more doubt is it possible to give links above the legend?

 

That is, is it possible to drilldown on the link which takes me to some other page.

 

Please suggest!

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

You are always welcome.smile.gif

 

I am afraid, FusionCharts does not support drill down feature on legend, at this time.

 

Thank you very much for your continued patience and patronage.

 

Hope you have a great day!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now