how to automatically add commas to numbers in adobe illustrator

Participant ,
Jun 23, 2018 Jun 23, 2018

Copy link to clipboard

Copied

As far as I can tell, Ai graphs don't let you include thousand/comma separators in the data from which graphs are created, so you need to add them after. I can't find any automatic way to do this after the graph has been created. Here's a screen shot example, in case that's helpful. I want thousand/comma separators on the Y axis and the bar value markers. Any help would be greatly appreciated. Thanks!

Screenshot 2018-06-23 11.57.42.png

Views

1.2K

Likes

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 Beginner ,
Oct 25, 2019 Oct 25, 2019

Copy link to clipboard

Copied

Yes, I've been wondering how to do this for years! I end up just manually adding them after I finish creating the chart. It's very time consuming.

Likes

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
Adobe Community Professional ,
Oct 26, 2019 Oct 26, 2019

Copy link to clipboard

Copied

To use the following scripted suggestion, you will need to ungroup the graph, therefore live/dynamic graph editing will be lost (so dupe and hide the original graph in a backup layer etc).

 

 

 

// graphicdesign.stackexchange.com/questions/50503/how-to-do-a-wildcard-grep-regex-find-replace-in-illustrator
// It does a regex find-replace on text in the selected items, or on all text if nothing is selected.
// Note: there seems to be a bug where sometimes it fails to find text within selected groups - if you encounter this, try running the script with nothing selected, or ungrouping.
// Here's a few examples I tested with it:
// Simple find/replace:
// Find: test
// Replace: hello
// Add a % to all numbers in selection:
// Find: (\d+\.?\d*)
// Replace: $1%
// Turn multiple spaces into one space:
// Find:+ (there's a space before that + which is getting chopped out)
// Replace:  (space)

// 2019: Hardcoded a thousand separator regex into the prefilled find/replace suggestion

var scope = app.activeDocument.selection.length ? app.activeDocument.selection : app.activeDocument.pageItems;

var find = prompt("Find: (Text or regex)","\\d{1,3}(?=(\\d{3})+(?!\\d))"); // Escape those digits!
if(find !== null){

    var replace = prompt("Replace: (Text or regex)","$&,");
    if(replace !== null){

        var changes = 0;

        for(var i=0;i<scope.length;i++){  

            var text = scope[i];

            var string = text.contents;  
            if(typeof string == "string"){
                var newstring = string.replace( new RegExp(find, 'g'), replace);
                if (newstring != string) {
                    changes++;
                    var paragraphsArray = newstring.split("\n");
                    text.paragraphs.removeAll(); 
                    for(var ii=0;ii<paragraphsArray.length;ii++){  
                         text.paragraphs.add(paragraphsArray[ii]);
                    }
                }
            }
        }
        alert( changes==1 ? "1 text object changed" : changes + " text objects changed");
    }
}

 

 

 

 

 

 

A modified version of the script could be created to remove the prompts and simply apply the regular expression find/replace directly, however, I believe that it is more useful to keep the prompts and change the prefilled text if needed. You will just need to press OK/return/enter three times, which is a small price to pay.

 

NOTE: If no objects are selected, then all matching digits will receive the comma separator, whether the text is locked or hidden or isolated on hidden layers etc. Otherwise, pre-select the objects first and only the selected text objects will change.

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Likes

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
Adobe Community Professional ,
Oct 26, 2019 Oct 26, 2019

Copy link to clipboard

Copied

Here is the modified version with hardcoded find/replace without using prompts, so no need to press OK:

 

 

 

 

#target illustrator

var scope = app.activeDocument.selection.length ? app.activeDocument.selection : app.activeDocument.pageItems;

var find = "\\d{1,3}(?=(\\d{3})+(?!\\d))"; // Escape those digits!
if(find !== null){

    var replace = "$&,";
    if(replace !== null){

        var changes = 0;

        for(var i=0;i<scope.length;i++){  

            var text = scope[i];

            var string = text.contents;  
            if(typeof string == "string"){
                var newstring = string.replace( new RegExp(find, 'g'), replace);
                if (newstring != string) {
                    changes++;
                    var paragraphsArray = newstring.split("\n");
                    text.paragraphs.removeAll(); 
                    for(var ii=0;ii<paragraphsArray.length;ii++){  
                         text.paragraphs.add(paragraphsArray[ii]);
                    }
                }
            }
        }
        alert( changes==1 ? "1 text object changed" : changes + " text objects changed");
    }
}

 

 

 

Likes

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
Participant ,
Sep 27, 2021 Sep 27, 2021

Copy link to clipboard

Copied

It is complete insanity that anyone would have to write a SCRIPT to add commas to numbers on a GRAPH.   Adobe, cmon, GET WITH IT.

Likes

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 ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

Here is a workaround... you can copy the axis numbers, then recolor the existing axis numbers (without the commas) to NONE. Then past on top what you copied, then add the commas. Keeps your chart live. Only issue is if the data range changes, you'd have to do this over again, but no biggie.

Likes

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 ,
Aug 03, 2022 Aug 03, 2022

Copy link to clipboard

Copied

LATEST

Here's another one... fake the axis data numbers... for instance if they are 100,000, 200,000, 300,000... divide all the data by 1000, then add ",000" as a "suffix"

Likes

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