Power BI API used to push real time data stream data set and visualization of the instrument panel

640?wx_fmt=png

Use Power BI real-time data visualization is a topic we are more concerned about pushing data show realized on the dashboard, it can be used in command of such a large screen, and other scenes.


This video combat follows: https://v.qq.com/x/page/y3030euh6do.html




Look under the effect of the figure the curve will automatically refresh:

640?wx_fmt=png


Proceed as follows:

  1. Create a stream of data sets, select the mode API

    Azure flow analysis which, as of December 2019, China, Azure flow analysis does not support the write output directly to the Power BI.

    640?wx_fmt=png


  2. Fill in the data set name and values ​​and value types and open historical data analysis:

    Historical data analysis which is used to temporarily hold data temporarily stored data can be presented a curve.


    640?wx_fmt=png

  3. Creating a dashboard and instrument panel add a real-time data tile


    640?wx_fmt=png


4. Select the stream data sets already created


640?wx_fmt=png

5. In the dashboard page to add a custom data stream tile

Select line graph visualization

"Axis" selection time

Temperature and humidity add "value"

640?wx_fmt=png

6. Post call request illustrated by the following information data can be pushed to the data set

640?wx_fmt=png


Postman sent the results of 200 indicates successful execution.

640?wx_fmt=png

7. Create a report on the data set, can be used to view the results pushed POST request stream data set

640?wx_fmt=png



8. call the following sample code:

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;        }    } }

At this point, you can see real-time visualization refresh the dashboard:

640?wx_fmt=png




640?wx_fmt=gif



Guess you like

Origin blog.51cto.com/10117438/2456854