• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Contributor ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

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!

 

Screen Shot 2021-11-16 at 12.58.04 PM.png

TOPICS
Scripting , Type

Views

472

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 30, 2021 Nov 30, 2021

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

Votes

Translate

Translate
Adobe
Guide ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 16, 2021 Nov 16, 2021

Copy link to clipboard

Copied

Some of my labels are in text boxes. My stacked bar charts have text boxes but my slider chart has free text not bound in a box so that when the number automatically pulls in from the data it wont get cut off. the text though is attached to the chart, the text is not separate from my chart

Screen Shot 2021-11-16 at 2.16.44 PM.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 29, 2021 Nov 29, 2021

Copy link to clipboard

Copied

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 += "%";}}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 30, 2021 Nov 30, 2021

Copy link to clipboard

Copied

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 += "%";
    }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2021 Nov 30, 2021

Copy link to clipboard

Copied

LATEST

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...

-Manan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines