ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Get Percentage Values From Bar Chart
Posted by John Nelson on Dec-21-2017 01:05
Here is my delima

I have a stacked chart that will display percentages.

layer = (BarLayer)c.addBarLayer2(Chart.Percentage);

I add three data sets

layer.addDataSet(red, project.getHighLevelColor(), "High");
layer.addDataSet(yellow, project.getMidLevelColor(), "Medium");
layer.addDataSet(green, project.getLowLevelColor(), "Low");

I am trying to use the javascript clickable chart example from your demo war file


String showText = "onmouseover='showInfo("{xLabel}", "{field0|2}", "{field1|2}", "{field2|2}", "{field3|2}", "{field4|2}");' ";

String hideText = "onmouseout='showInfo(null);' ";

String toolTip = "title='{xLabel}: {dataSetName} Percent = {percent|2}%'";

when I call

setHtmlImageMap(c.getHTMLImageMap("", "", showText + hideText + toolTip));


The values in the field0, field1, etc are not correct.

I tried usng the 'dsField0', 'dsField1', etc as the paraneter in the showText String.  but that didn't seem to work.

So - is there any way to get that precentage value that chart director creates for us in the bar chart?

BTW - I tried adding

layer.addExtraField2(red);
layer.addExtraField2(yellow);
layer.addExtraField2(green);

but then that just displays the values of red, yellow, green and not the percentages

  Re: Get Percentage Values From Bar Chart
Posted by Peter Kwan on Dec-22-2017 02:44
Hi John,

The onmouseover method only shows information of the data object under the mouse. For your case, it is the bar segment. The value of the bar segment is {value}, while the percentage of the bar segment is {percent}.

String showText = "onmouseover='showInfo(\"{xLabel}\", {value}, {percent});' ";

You can ask ChartDirector to format the value and percentage (eg. to two decimal place). You can also format the value and percentage in the Javascript code inside onmouseover.

If you want to display all data objects at a certain x-position, you may use programmable track cursor, such as:

http://www.advsofteng.com/doc/cdjava.htm#trackboxweb.htm

In the example above, it is using a bar chart with "Side" layout. You can also use a bar chart with Percentage layout.

The ChartDirector Javascript Chart Model provides two APIs to get the value of a segment - JsDataSet.getValue and JsDataSet.getPosition. See:

http://www.advsofteng.com/doc/cdjava.htm#jschartmodel.htm
http://www.advsofteng.com/doc/cdjava.htm#JsDataSet.htm

The JsDataSet.getValue gets the original data value of a data object. The JsDataSet.getPosition gets the value used to position the data object. For a percentage bar chart, the value used to position the data point is the accumulated percentage (or "stacked" percentage). So the percentage of a data object is its accumulated percentage minus the accumulated percentage of the data object under it (or 0 if there is no data object under it).

If you prefer to use the getHTMLImageMap method, you can use the addExtraField method to add the data for all segments to every single segment. In this case, you would need to compute the percentage with your own code in Javascript (which should be quite simple).

Regards
Peter Kwan