python-3.x 如何在Azure Data Explorer中使用- Plotly Graph Objects库绘制 Jmeter 图

tzcvj98z  于 2023-10-21  发布在  Python
关注(0)|答案(1)|浏览(130)

如何使用Plotly Graph Objects Python库在Azure Data Explorer Jmeter 板中绘制Gauge图表
Kusto(带有Python插件)可以在Azure Data Explorer Jmeter 板中使用,以绘制Python Plotly图表(例如,条形图或散点图)。
但是,Plotly Express不能绘制 Jmeter 图。因此,需要使用Graph Objects库。
这个ADX代码可以工作(值硬设置为250):

['table']
| where abs(Prsr1IoTVal) >= 1 
| top 1 by IoTEventDateTime
| project  Pressure1Value=round(Prsr1IoTVal)
| evaluate python(typeof(plotly:string),
```if 1:
    import plotly.graph_objects as go
    fig = go.Figure(go.Indicator(
        mode = "gauge+number",
        value = 250,
        domain = {'x': [0, 1], 'y': [0, 1]},
        title = {'text': "Speed"}))
    plotly_obj = fig.to_json()
    result = pd.DataFrame(data = [plotly_obj], columns = ["plotly"])
```)

然而,我们尝试将该值设置为从Kusto表传入的值-没有返回行(即使我们知道Kusto查询确实返回值):

['glualwndpwriotevents-target-tbl']
| where abs(Prsr1IoTVal) >= 1 
| top 1 by IoTEventDateTime
| project  Pressure1Value=round(Prsr1IoTVal)*100
| evaluate python(typeof(plotly:string),
```if 1:
    import plotly.graph_objects as go
    fig = go.Figure(
                    data=[go.Indicator(
                                mode = "gauge+number",
                                value = df['Pressure1Value']
                                domain = {'x': [0, 1], 'y': [0, 1]},
                                title = {'text': "Speed"}
                                )
                        ]
                    )
    plotly_obj = fig.to_json()
    result = pd.DataFrame(data = [plotly_obj], columns = ["plotly"])
```)

有什么建议吗?
谢谢.

nhhxz33t

nhhxz33t1#

我在我的环境中复制,下面是我的预期结果:
我从你的查询或Python代码中观察到的是,你正在传递 Dataframe 对象,值期望它是标量值。
下面是为我工作的**KQL query**(修改了你的查询):

rithtable
|project Name,Age
| evaluate python(typeof(plotly:string),
```if 1:
    import plotly.graph_objects as go
    value = df['Age'].iloc[0]
    fig = go.Figure(
                    data=[go.Indicator(
                                mode = "gauge+number",
                                value = value,
                                domain = {'x': [0, 1], 'y': [0, 1]},
                                title = {'text': "Speed"}
                                )
                        ]
                    )
    plotly_obj = fig.to_json()
    result = pd.DataFrame(data = [plotly_obj], columns = ["plotly"])
```)

Output:

Output of Json is :

相关问题