Baran Yildiz
Baran Yildiz

Reputation: 33

How to define a secondary y-axis when plotting with Kusto Query Language (KQL)

I was wondering if there is a way to create a secondary y-axis when plotting query results by Kusto Query Language. In particular via using the Kusto Explorer or Azure Web UI.

My data table has time-series variables whose magnitudes are significantly different. I would like to see all these variables in the same line-plot or time-chart therefore,require a secondary y-axis.

I have gone through the instructions given in the 'render' documentation (see the link below), however was unable to create a secondary y-axis (the argument such as ysplit didn't produce what I am looking for).

https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/renderoperator?pivots=azuredataexplorer

Would be great if someone can let me know whether this is possible, or do I have to use another tool such as PowerBI or Python to achieve this.

Thank you

Upvotes: 3

Views: 4590

Answers (1)

Nikolai Kummer
Nikolai Kummer

Reputation: 167

The following code can get you some of the way there, which may be enough, but the splitting of axes is a bit limited in the UI and the code generation. This answer is based on the sample code you posted in your comment:

All Signal Types on Separate Axes

Here we create separate columns for each measurement depending on signal type. The rendering will occur in the order in which the columns appear so you will get power as main axis (left) and power_reactive, freq_1, freq_2 as their own separate axes on the right.

datatable (timestamp: datetime, signal_type: string, measurement: real)[
'2020-01-01', 'power', 1200 ,
'2020-01-01', 'power_reactive', 500,
'2020-01-01', 'freq_1', 50.1, 
'2020-01-01', 'freq_2', 50.2,
'2020-01-02', 'power', 1300 ,
'2020-01-02', 'power_reactive', 330,
'2020-01-02', 'freq_1', 50.4, 
'2020-01-02', 'freq_2', 50.3,
'2020-01-03', 'power', 1500 ,
'2020-01-03', 'power_reactive', 250,
'2020-01-03', 'freq_1', 50.05, 
'2020-01-03', 'freq_2', 50.1,
'2020-01-04', 'power', 1500 ,
'2020-01-04', 'power_reactive', 700,
'2020-01-04', 'freq_1', 50.15, 
'2020-01-04', 'freq_2', 50.25,
]
| project timestamp,
          power_measurement = iif(signal_type == "power", measurement, real(null)),
          power_reactive_measurement = iif(signal_type == "power_reactive", measurement, real(null)),
          freq_1_measurement = iif(signal_type == "freq_1", measurement, real(null)),
          freq_2_measurement = iif(signal_type == "freq_2", measurement, real(null))
|render timechart with (ysplit =axes, ytitle="power")

Chart with each column on a separate y-axis

Combine multiple signals into the main y-axis

Using the web-ui you can render the above code and then delete the reactive-power y-axis, which will combine it back into the main y-axis and will display that signal on the same scale:

Location of deletion button for reactive power axis

This will result in the following plot with 3 axes:

  1. the main y-axis on the left containing power and power reactive and
  2. an axis on the right showing freq_1
  3. an axis on the right showing freq_2

Image showing the power and reactive power on the same scale

Upvotes: 2

Related Questions