![](/img/trans.png)
[英]How to get value of selected parameter on parameter change event in tableau Javascript API
[英]Tableau JavaScript API - get Selected value
我目前正在研究通過JavaScript API從Tableau報告中獲取數據的可能性,但是在過濾后,我可以從圖形中獲取值的壁櫥是通過selectSingleValue()方法選擇值。
例如: JavaScript API教程
在API教程標簽中,稱為“選擇”。 示例之一選擇了“中國的馬可騷”行。 是否可以提取$ 52,000k的數值?
我嘗試查看返回的對象(通過FireBug),但似乎找不到正確的對象。 我最近的位置在getActiveSheets()中。
任何幫助,將不勝感激。
在JavaScript API教程標簽“事件”中,它顯示了如何添加事件偵聽器以返回所選標記。 然后,您可以遍歷標記以獲取所需的值。
將以下代碼塊復制到文件中,另存為html,然后在您喜歡的Web瀏覽器中打開(在ie11上測試)。
<html>
<head>
<meta charset="utf-8">
<title>Tableau 8 Javascrip API</title>
<script type="text/javascript" src="http://public.tableausoftware.com/javascripts/api/tableau_v8.js"></script>
<script type="text/javascript">
/////////////////////
// Global variables
var viz, workbook, activeSheet
// function called by viz on marks being selected in the workbook
function onMarksSelection(marksEvent) {
return marksEvent.getMarksAsync().then(reportSelectedMarks);
}
function reportSelectedMarks(marks) {
for (var markIndex = 0; markIndex < marks.length; markIndex++) {
var pairs = marks[markIndex].getPairs();
for (var pairIndex = 0; pairIndex < pairs.length; pairIndex++) {
var pair = pairs[pairIndex];
if (pair.fieldName == "AVG(F: GDP per capita (curr $))") {
alert("You selected a country with an avg GPD per capita of " + pair.formattedValue);
}
}
}
}
// Initialise the viz to hold the workbook
function initializeViz(){
var placeholderDiv = document.getElementById("tableauViz");
var url = "http://public.tableausoftware.com/views/WorldIndicators/GDPpercapita?Region=";
var options = {
width: "800px", //width: placeholderDiv.offsetWidth,
height: "400px", //height: placeholderDiv.offsetHeight,
hideTabs: true,
hideToolbar: true,
onFirstInteractive: function () {
workbook = viz.getWorkbook();
activeSheet = workbook.getActiveSheet();
}
};
viz = new tableauSoftware.Viz(placeholderDiv, url, options);
// Add event listener
viz.addEventListener(tableauSoftware.TableauEventName.MARKS_SELECTION, onMarksSelection);
}
</script>
</head>
<body>
<!-- Tableau view goes here -->
<div id="tableauViz" style="height:1200px; width:1200px"\></div>
<script type='text/javascript'>
//Initialize the viz after the div is created
initializeViz();
</script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.