Changing stats unit

I have a stats column on my Grafana dashboard that contains some number, I want to use the Indian numbering system for displaying this value. For example, 2570000 should be displayed as 25.70 Lakhs and 225700000 as 2.25 Crores.

How can I do this?

I would do a binary transformation to divide by 1,000,000 (or whatever you need to divide by)…

…and then create a custom unit (see here).

But this will limit to just one type. I want it to be dynamic i.e. use either lakh or crore according to the value.

what is your data source?

I am parsing json data using Infinity plugin.

please provide sample json data (obfuscated if needed)

2 Likes

this can be solved in jsonata but since you are not providing the data that was asked of you () => { console.log('Happy Journey')}

I don’t know what data did I miss to provide, I clearly mentioned some sample values that I have in the question statement itself, and for the format of the json that I am receiving I have provided the link with the format of my json data.

Also, if I format the data via jsonata, I will receive a string on grafana for example: “1.20 Lakh” or “3.40 Crore” etc then how will I be able to sort it like numbers on grafana?

provide real usable data. the following is not

{
	"jsonrpc": "2.0",
	"result": [
		{
			"itemid": "59832",
			"value": "col1 | col2 | col3 | col4\n entry1 | entry2 | entry 3 | entry4"
		}
	]
}

real column names and real entry value. Otherwise cant help you

Okay, here is the real usable data:

{
	"jsonrpc": "2.0",
	"result": [
		{
			"itemid": "59832",
			"value": "Server | Used | Given\n server1 | 1250000 | 50000000"
		}
	]
}
2 Likes

This is the json data samle that I receive from my datasource. I make an API call via the Infinity plugin to get this data then I visualize it using the table panel on Grafana.

[
  {
    "Server": "server1",
    "UserId": "user1",
    "Login": "not logged in ",
    "LastUpdate": " no update ",
    "Used.": "1457000",
    "Given.": "18000000"
  },
  {
    "Server": "server1",
    "UserId": "user2",
    "Login": "not logged in ",
    "LastUpdate": " no update ",
    "Used": "2960000",
    "Given": "15000000"
  }
]

I hope this would help.

and now this new data is totally different than the last data you posted :no_mouth:

{
	"jsonrpc": "2.0",
	"result": [
		{
			"itemid": "59832",
			"value": "Server | Used | Given\n server1 | 1250000 | 50000000"
		}
	]
}
[
  {
    "Server": "server1",
    "UserId": "user1",
    "Login": "not logged in ",
    "LastUpdate": " no update ",
    "Used.": "1457000",
    "Given.": "18000000"
  },
  {
    "Server": "server1",
    "UserId": "user2",
    "Login": "not logged in ",
    "LastUpdate": " no update ",
    "Used": "2960000",
    "Given": "15000000"
  }
]

I cannot think of an easy way to do this directly with Grafana.

The closest would be the “Locale format” which will format the value according to your browser’s locale preference, but it doesn’t look like it will format according to this system.

I cannot understand what exactly is required. I provided all the data that I am working on.

Yes, using the locale format is not helping.

accurate data, you have all kinds of data you are providing hard to help you or provide a solution
Again jsonata can help you in this case

https://try.jsonata.org/Hog_-HFfk

Check the documentation on functional programming on how to achieve what you want

Run with it and when you are stuck please post back.

(
    $.{
        "Server": Server,
        "UserId": UserId,
        "Login": Login,
        "LastUpdate": LastUpdate,
        "Used":  $number(Used) > 100000 ? $string(Used) & " Lakhs" : "Basic",
        "Given": Given

    }
)

You can even use functions

(
    $धन := function($x) {(
        $number($x) > 0 and  $number($x) <= 100000 ? $string(Used) & " Lakhs" : "Basic"
    )};

    $.{
        "Server": Server,
        "UserId": UserId,
        "Login": Login,
        "LastUpdate": LastUpdate,
        "Used":  $धन(Used),
        "Given": Given

    }
)

The issue with using jsonata in this case is that it will convert the numbers into strings with Lakhs/Crores suffix and then sorting based on these numbers on Grafana wouldn’t work.

1 Like

use jsonata for sorting on the real numeric value not grafana sort feature.