3

I have numbers in the millions and would like to know what string to enter in the Legend Format box to have thousands separated by commas ex: 2,000,000

QGIS example

1
  • 1
    Any news on this one? – Michael Oct 17 '17 at 0:15
3

I don't think it's possible (yet) for the Legend Format to include expressions such as those from the Field Calculator.

A workaround is to manually insert the commas into the correct places in the Legend (this can be laborious if you have a lot of items) and then click Apply.

DO NOT CLICK "CLASSIFY" AS THIS WILL RESET YOUR LEGEND.

Graduated with commas

2
  • Yeah, beyond doing things manually as you say doesn't look too promising. Even the percentage question had a similar solution – raphael May 5 '15 at 16:09
  • @raphael - Yes, you could always open a feature request and hope they implement a viable solution in the next QGIS version :) – Joseph May 7 '15 at 9:30
0

For QGIS3.X I still don't know of a method to do this using the Legend Format but here's a PyQGIS script (can be run from the Python Console) to apply a thousands seperator to a given layer assuming it's using a graduated symbology:

    for lyr in iface.mapCanvas().layers():
        if lyr.name() == 'sales': #replace with your layer name
            renderer = lyr.renderer()
            if renderer.type() == 'graduatedSymbol':
                myRenderer = renderer.clone()
                idx = 0 
                for r in myRenderer.ranges():
                    lv = f'{int(r.lowerValue()):,}'
                    uv = f'{int(r.upperValue()):,}'
                    myRenderer.updateRangeLabel(idx,lv + " - " + uv)
                    idx+=1
                lyr.setRenderer(myRenderer)
                lyr.triggerRepaint()

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.