您好,登錄后才能下訂單哦!
使用Power BI 實現實時數據的可視化是大家比較關心的一個話題,在儀表盤上實現推送數據的展示,可以在諸如指揮大屏等場景下使用。
本視頻實戰內容如下:https://v.qq.com/x/page/y3030euh7do.html
先看下效果,下圖中的曲線會自動刷新:
步驟如下:
創建流數據集,選擇API 方式
其中Azure 流分析,截至到2019年12月,中國區Azure流分析暫時不支持將輸出直接寫入到Power BI 中。
填寫數據集名稱和值及值類型并打開歷史數據分析:
其中歷史數據分析是用來暫存數據的,暫存的數據可以呈現一條曲線。
創建一個儀表盤并向儀表盤添加一個實時數據磁貼
4. 選擇已經創建好的流數據集
5.?在儀表板頁面添加一個自定義的流數據磁貼
可視化效果選擇折線圖
“軸”選擇時間
溫度濕度添加為“值”
6. 通過如下圖示的信息調用Post請求即可將數據推送到數據集
Postman發送的結果為200表示執行成功。
7. 在數據集上創建報表,可以查閱使用POST請求推送到流數據集的結果
8.調用示例代碼如下:
using?Newtonsoft.Json;using?System;using?System.IO;using?System.Net;using?System.Text;using?System.Threading.Tasks;namespace?pushdatatopowerbidataset{????class?Program????{????????private?static?int?s_telemetryInterval?=?1;?//?Seconds????????private?static?string?PowerBIPushDataUrl?=?"https://api.powerbi.cn/beta/729c6bf9-debe-4b7f-b56a-5fb0c70c9a80/datasets/fc445a3c-9a25-4298-8188-89112874e5c3/rows?key=seAORXugMKybekrdRAxfSWM5o1MS%2F9d4pcPF9zAgblivdNXz9pRivqyVwAS%2FXMoo8wA01vuAu%2B2hBHI8gdAWMg%3D%3D";???????private?static?void?Main(string[]?args)????????{????????????Console.WriteLine("Send?realtime?data?to?power?bi?dataset?by?api.?Ctrl-C?to?exit.\n");????????????SendMessageToPbiDataSetAsync();????????????Console.ReadLine();????????}????????private?static?async?void?SendMessageToPbiDataSetAsync()????????{?????????????while?(true)????????????{????????????????//?Initial?telemetry?values????????????????double?minTemperature?=?20;????????????????double?minHumidity?=?60;????????????????Random?rand?=?new?Random();????????????????double?currentTemperature?=?minTemperature?+?rand.NextDouble()?*?15;????????????????double?currentHumidity?=?minHumidity?+?rand.NextDouble()?*?20;????????????????//?Create?JSON?message????????????????var?telemetryDataPoint?=?new????????????????{????????????????????temperature?=?currentTemperature,????????????????????humidity?=?currentHumidity,????????????????????time=DateTime.Now????????????????};????????????????var?messageString?=?JsonConvert.SerializeObject(telemetryDataPoint);????????????????PostUrlAsync(PowerBIPushDataUrl,?messageString);????????????????await?Task.Delay(s_telemetryInterval?*?1000);????????????}????????}????????public?static?string?PostUrlAsync(string?url,?string?postData)????????{????????????string?result?=?"";????????????HttpWebRequest?req?=?(HttpWebRequest)WebRequest.Create(url);????????????req.Method?=?"POST";????????????req.Timeout?=?8000;//設置請求超時時間,單位為毫秒????????????req.ContentType?=?"application/json";????????????byte[]?data?=?Encoding.UTF8.GetBytes("["+?postData+"]");????????????req.ContentLength?=?data.Length;????????????using?(Stream?reqStream?=?req.GetRequestStream())????????????{????????????????reqStream.Write(data,?0,?data.Length);????????????????reqStream.Close();????????????}????????????HttpWebResponse?resp?=?(HttpWebResponse)req.GetResponse();????????????Stream?stream?=?resp.GetResponseStream();????????????//獲取響應內容?????????????if(resp.StatusCode==HttpStatusCode.OK)????????????{????????????????Console.WriteLine("OK"+"????"+postData);????????????}????????????return?result;????????}????}?}
至此,可以在儀表板上看到實時刷新的可視化效果:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。