Dashboards & Visualizations

How to round the decimal percentage in a piechart with XML?

pavanae
Builder

I had a pie-chart and I have added the following line on the source to display the percentage on the piechart But the percentage is displaying as xx.xyz. Now, how can I round it to single digit likle xx.y

option name="charting.chart.showPercent" as true

Is there any way to round the percentage from the xml?

1 Solution

mayurr98
Super Champion

As of now, there is no property to add precision in XML for a pie chart.
you can look for doc here https://docs.splunk.com/Documentation/Splunk/7.0.0/Viz/ChartConfigurationReference#Pie_charts
One way to do this using query.

index=your_index | stats query | eventstats sum(count) as total_Count | eval total_Count=round((count/total_Count)*100,2) | eval field=field + " , " + total_Count + "%"

here the name of the field will be the name which is given after by clause in stats command.

Let me know if it works.

View solution in original post

mayurr98
Super Champion

As of now, there is no property to add precision in XML for a pie chart.
you can look for doc here https://docs.splunk.com/Documentation/Splunk/7.0.0/Viz/ChartConfigurationReference#Pie_charts
One way to do this using query.

index=your_index | stats query | eventstats sum(count) as total_Count | eval total_Count=round((count/total_Count)*100,2) | eval field=field + " , " + total_Count + "%"

here the name of the field will be the name which is given after by clause in stats command.

Let me know if it works.

pavanae
Builder

Thanks for the response @mayurr98. It worked great.

0 Karma

cmerriman
Super Champion

try the number formatting options:
https://docs.splunk.com/Documentation/SplunkCloud/6.6.3/Viz/TableFormatsXML#Number_format_rules

<format type="number" field="count">
        <option name="precision">1</option>
</format>   
0 Karma

pavanae
Builder

Thanks for the response @cmerriman.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...