azure-data-explorer-datasource icon indicating copy to clipboard operation
azure-data-explorer-datasource copied to clipboard

Multiple series can't be distinguished in legend

Open cdeil opened this issue 2 years ago • 3 comments

When I use the query builder and add two queries and time series they are both shown as avg_Value in the legend and it's not clear which is which.

Other Plugins like Graphite have a nice way to alias time series names.

Could you please offer something like this for ADX as well?

PS: this was already mentioned in #14 and probably I should have filed it as a feature request, but I thought maybe bug reports get more attention. :-)

Screenshot 2022-11-16 at 20 40 10 Screenshot 2022-11-16 at 20 37 25

cdeil avatar Nov 16 '22 19:11 cdeil

hi @cdeil, this is due to the fact that that's the column name of the returned values.

In fact, we could add an Alias field so we can rename it but that would be a new feature request. In the meantime, you can manually rename the column if you edit the KQL code, using the project-rename function:

| summarize avg(Value) by bin(DateTime, $__timeInterval)
| project-rename W1_KAL_SCIN=avg_Value

andresmgot avatar Nov 24 '22 10:11 andresmgot

Hello @cdeil,

Have you considered using a query where you add the SensorTag column in the summarize / group by?

Plant_Metric_0762
| where $__timeFilter(DateTime)
| where SensorTag in ('W1_Kal_OSADY', 'W1_KAL_SCIN')
| summarize average(Value) by bin(Datetime, $__timeinterval), SensorTag
| order by Datetime asc;

This will give you an output like:

DateTime     SensorTag,        avg_value
2022-01-01   W1_Kal_OSADY      10
2022-01-01   W1_KAL_SCIN       16
etc.

The graph would then look like this: image

However, this does not solve the Alias field, but in my opinion, one should not define 'friendly names' hardcoded in queries, but add a friendly name column in Plant_Metric_0762 table. An alternative is creating a fact table and use a join to get the friendly name. However, this is not always possible depending on the situation.

In such situation where you need to hardcode this, you can use the let statement to define a key/value list with the SensorTag as the key and the friendly name as the value. Then use strcat() to format the label. For example:

let FriendlyNames=dynamic({'W1_Kal_OSADY': 'Friendly name 1', 'W1_KAL_SCIN': 'Friendly name 2'});
Plant_Metric_0762
| where $__timeFilter(DateTime)
| where SensorTag in ('W1_Kal_OSADY', 'W1_KAL_SCIN')
| summarize average(Value) 
         by bin(Datetime, $__timeinterval), 
            SensorName=strcat(SensorTag, ' = ', Friendlynames[SensorTag])
| order by Datetime asc;

Which will result in something like this: image Still not the label names we expect in the legend. We can use the Grafana "labels to fields" transformation to apply the values of the SensorName column to the labels: image Now the sensor tags have both the sensor tag and the 'Alias'.

Grrrolf avatar Nov 25 '22 11:11 Grrrolf

In the meantime, you can manually rename the column if you edit the KQL code, using the project-rename function:

| summarize avg(Value) by bin(DateTime, $__timeInterval)
| project-rename W1_KAL_SCIN=avg_Value

| project-rename ['W1_KAL_SCIN = RDF calciner']=avg_Value also works to have the friendly name included too.

Grrrolf avatar Nov 25 '22 11:11 Grrrolf