简体   繁体   English

多数据选择SAPUI5 viz

[英]Multi data select SAPUI5 viz

The following code gives me a nice line chart as shown below: 以下代码为我提供了一个不错的折线图,如下所示:

//Code snippet to create dataset  
var oDataset1 = new sap.viz.ui5.data.FlattenedDataset({  
  dimensions : [{axis : 1,name :'BUSINESS_DATE', value :"BUSINESS_DATE"}]  
  measures : [{name : 'Profit', value : '{Profit}'}], //Define the Y-axis parameter  
  data : {path : "/GRAPHDATA",filters: [oFilter1,oFilter2,oFilter3],parameters: {select: 'BUSINESS_DATE,PROFIT'}} //set the data and filter  
});

Define line chart: 定义折线图:

var oLineChart = new sap.viz.ui5.Line({
  width : "100%",
  height : "300px",  
  //plotArea : {'colorPalette' :['#748CB2','#FFC200']},  
  title : {visible : true,text : 'BusinessDate Vs Profit'},  
  dataset : oDataset1,  
  selectData : function(oEvent) {  
    alert("Need to extend code");                     
  },  
});  

在此处输入图片说明

Now, when I click on a single data point I need to get the values of X-axis and Y-axis of that data point selected. 现在,当我单击单个数据点时,我需要获取所选数据点的X轴和Y轴的值。 Could anyone suggest how this could be done? 有人可以建议如何做到这一点吗? Any example solutions. 任何示例解决方案。 Thanks 谢谢

在查看API文档时,您可能需要attachSelectData函数来侦听数据选择。

Get your Line Chart via Id 通过ID获取折线图

var line = sap.ui.getCore().byId("LineChart");

Get the model from the line chart 从折线图获取模型

var json = line.getModel().getProperty("/GRAPHDATA");

now you can access the element clicked via row and column ID in the json and you got your X-Axis value... 现在您可以访问通过json中的行和列ID单击的元素,并且得到了X轴值...

Please try with the following code: 请尝试以下代码:

var oSelectData = oEvent.getParameter("GRAPHDATA");
var oContext = this.getDataset().findContext(oSelectData[0].data[0].ctx.path);

oContext will get the datapath followed by the data index. oContext将获取数据路径,后跟数据索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM