Skip to main content
LynxKx
Inspiring
November 16, 2021
Answered

Quick solution to add decimal to whole number in chart label?

  • November 16, 2021
  • 1 reply
  • 1021 views

I created this slider chart in Illustrator. Used column designs to get the desired style and add the label automatically. Is there an easy find/replace or a script that will allow me to change all whole numbers to be decimals. I want 64 to be consistent with the others and read as 64.0

I have tons of these charts and takes a long time to manually make the adjustment and then have to do it again when/if the data changes and resets.

thanks!

 

This topic has been closed for replies.
Correct answer Manan Joshi

I can't check at present, but I don't think a paragraphStyle will work the way you intend.  

 

Off the top of my head, you could try adding % specifically to numbers with decimal points.  

    if (!isNaN(text) && text.search(/\./) != -1) {
        frames[i].contents += "%";
    }

 


I added a code snippet for this in another thread by OP, hopefully that will work

https://community.adobe.com/t5/illustrator-discussions/script-to-add-a-percent-symbol-to-all-numbers/m-p/12559537#M300593

-Manan

1 reply

femkeblanco
Legend
November 16, 2021

Edit:  Sorry.  I didn't read that this was for a graph.  What I wrote won't work. 

LynxKx
LynxKxAuthor
Inspiring
November 30, 2021

I was able to use your script after all. I just saved a copy of my working file, ungrouped all of the charts and ran the script! Works great and I was able to adjust it to add a percentage symbol to all of the data labels.  Thank you for you help! 

var myDoc = app.activeDocument;
var frames = myDoc.textFrames;

for (var i = 0; i < frames.length; i++) {
    var text = frames[i].contents;
    if (!isNaN(text) && text.search(/\./) == -1) {
        frames[i].contents += ".0";
    }
    if (!isNaN(text)) {
        frames[i].contents += "%";
    }
}

 I tried adding a condition for the text to be a specific paragraph style but it wasn't working. If you have thoughts on how to adjust to get the number to be conditional on a paragraph style... this is what i was using.

var myStyle = myDoc.paragraphStyles.getByName("data_bars_right");
for (var i = 0; i < frames.length; i++) {
    var text = frames[i].contents;
    if (!isNaN(text) && myStyle){ frames[i].contents += "%";}}
femkeblanco
Legend
November 30, 2021

I can't check at present, but I don't think a paragraphStyle will work the way you intend.  

 

Off the top of my head, you could try adding % specifically to numbers with decimal points.  

    if (!isNaN(text) && text.search(/\./) != -1) {
        frames[i].contents += "%";
    }