Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7863725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:34:26+00:00 2026-06-02T23:34:26+00:00

I would like to know how to format the data labels on a Pie

  • 0

I would like to know how to format the data labels on a Pie Chart so it shows max 2 decimal characters, and never shows trailing zeros, for example:

2 -> 2
2.0 -> 2
2.566 -> 2.57

In other words, I am asking how to set dataLabelFormatString parameter?
I know it is using sprintf, thus I tried ‘%.2f’ and ‘%g’. They do not solved my problem though. Since the first makes each number to show to decimal characters, the other just removes trailing zeros but doesn’t work with precision as in this case the digits you place in front of it ,e.g. ‘%.2g’ refer to the total length of the character.

I do not know how to, effectively, combine these two (is it even possible?). How to set the parameter, for example, to first format using ‘%.2f’ then using ‘%g’ and it should do the trick, but how to do it?

Can I maybe ‘inject’ an if/else into the format, if so then how?

Otherwise the only way I can think of would be to, once the plot is drawn, run a jquery script getting the labels and applying parseFloat(label.toFixed(2)) on each.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:34:28+00:00Added an answer on June 2, 2026 at 11:34 pm

    To close this topic I am posting my answer here. I managed to solved this issue, thanks to jQuery. Once again it appears to be a real life saver when it comes to doing the client side. 🙂

    I have approached it similarly to my thought mentioned in my question, i.e. using parseFloat(label.toFixed(2)). Though I did it in a slightly inverted way. I decided to set the chart to use label for dataLabels parameter. I use the $.jqplot.postDrawHooks.push(...) to bind my function for execution once the chart is finished painting. My function modifies the legend labels to display names instead of percentage values which I calculate before I set them to data array.

    This approach works perfectly as I would want it. To those interested, please find my jsfiddle showing the solution here.

    If someone has a better solution I am very keen to move the accept from my answer at any time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know the on disk format of an RMAN backup file.
I would like to know how can I pass data from controller to view
I would like to know how to run Pig queries stored in Hive format.
I would like to have an JSON like data format with the following features:
i would like know some reference. I know i can googling it. but prefer
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static
Would like to know how to integarate cruise control with maven? Cruise Control comes
Would like to know how to hide an div after a set of css3
I would like to know how to evaluate a string representation of an equation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.