How can the Plotly Graph Objects Python library be used to plot a Gauge chart in an Azure Data Explorer dashboard.
Kusto (with Python plug-in) may be used in an Azure Data Explorer Dashboard to graph a Python Plotly chart (e.g. a bar chart or a scatter chart) using the Plotly Express library.
However, Plotly Express CANNOT draw a Gauge Chart. Hence, the Graph Objects library needs to be used.
This ADX code does work (with value hard set to 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"])
```)
However, we tried setting the value to be the value passed in from the Kusto table - no rows are returned (even though we know the Kusto query does return a value):
['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"])
```)
Any suggestions?
Thanks.
I have reproduced in my environment and below are my expected results:
I observed from your query or python code is that, you are passing data frame object, the value expects it to be scalar value.
Below is the KQL query
(modified your query a bit) which worked for me:
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 :