cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to get UI5 Chart selected data set index

Former Member
0 Likes
406

Hi experts,

I am facing problem with ui5 bar chart. i am not able to get the selected data set index of selected bar on the chart.

I am using below method, but not getting any result from this method.

ObjectName.getChartObject().getSelectedDataSetIndices()

please suggest any methods are avaliable to get selected index?

Thanks & Regards

Venkat

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Likes

Hello Everyone,

I have now updated my SAP MII patch to  SAP UI5 version 1.20.4. Now I am getting my chart as shown in figure below.

Now I want to get the selected point x axis value, yaxis value and corresponding legend name of selected point. I am getting x axis value but not yaxis value and corresponding legend name.

Regards,

Venkat.

RiaNinan
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Venkat,

You can get the legend index and y-value by using the below code in the event handler that you have registered for ChartSelectionEvent:

     var meaureIndex = event.srcElement.__data__.ctx.path.mi + 1;

     alert(meaureIndex); //hack for getting legend index

     var selPoint = c.getChartObject().getSelectedPoint();

     alert(selPoint); //selected bar index

     var yValue = c.getChartObject().getYDataValueAt(meaureIndex,selPoint);

     alert(yValue);

Using the legend index you should be able to get the legend name.

Please note that parts of the above code for getting legend index is a hack (not in i5Chart documentation/reference)

Hope this helps!

Regards,

Ria

RiaNinan
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Venkat,

If what you need is the index of the selected bar, then try this:

     ObjectName.getChartObject().getSelectedPoint()


getSelectedDataSetIndices() - returns the dataset(legend) item index for the selected bar and for using this method you would have to register for chartSelectionEventHandler.

Regards,

Ria

Former Member
0 Likes

Hi Ria,

I tried with  ObjectName.getChartObject().getSelectedPoint() method, getting index of data set point but I need the dataset(legend) item index and  i registered chartSelectionEventHandler event and calling getSelectedDataSetIndices() method even though i am not getting any result from this method.

I am using following code to register event and calling Method.

chartobj.registerChartSelectionEventHandler(fnOnSelectChart);

function fnOnSelectChart()

{

alert(chartobj.getChartObject().getSelectedDataSetIndices());

alert(chartobj.getChartObject().getSelectedDataSetNames());

}

Regards

venkat

RiaNinan
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi Venkat,

Is it that the function fnOnSelectChart is getting called and the alerts do not return anything?

I tried the same, I get empty alerts- those methods returns the indices and names respectively of the legend items on selection of legend items. Sorry for the incorrect information in the earlier post.

If possible, can you please post a screenshot of the bar chart that is rendered and the expected value on selection of a bar - just to better understand your scenario.

Regards,

Ria

Former Member
0 Likes

Hi Ria,

Sorry for late replay,

Bellow is my bar chat, on selection of a bar, i need respective legend item name.

please suggest how can we achive this.

Regards

venkat