Commas on axis tick marks

18 views
Skip to first unread message

Jesus

unread,
Feb 22, 2025, 3:27:26 PMFeb 22
to JSXGraph
Is there a setting to add commas to major tick labels on axis? I enabled mathjax and display html. The labels display as mathjax but with no commas, 10000 instead of 10,000.

Thanks,


Murray

unread,
Feb 23, 2025, 7:55:09 PMFeb 23
to JSXGraph
Hello Jesus

You usually need to disable JSXGraph's default axes when you want to do something like this, then create new ones, OR re-define the default axes.

In this fiddle, I modified one of the graphs on this page https://jsxgraph.uni-bayreuth.de/docs/symbols/Ticks.html which re-defines the default axes.

I'm adding the commas on the y-axis by .toLocaleString("en-US") In a similar way, you could format them for other locations (like lakhs in India, or period in Europe.)

Here it is:


Hope it helps
Regards
Murray

Alfred Wassermann

unread,
Feb 24, 2025, 9:59:57 AMFeb 24
to JSXGraph
Murray's solution can be simplified a little bit: it is sufficient to add the attribute `intl` to the axis ticks. Here is the same example:

const board = JXG.JSXGraph.initBoard('jxgbox', { boundingBox: [-10, 30000, 10, -5000],
    axis: true,
    defaultAxes: {
        x: {
                margin: -4,
                ticks: {
                    minTicksDistance: 0,
                    minorTicks:4,
                    ticksDistance: 3,
                    scale: Math.PI,
                    scaleSymbol: 'π',
                    insertTicks: true
                }
             },
        y: {
          ticks: {
            intl: {
              enabled: true,
          locale: 'en-US'
            }
          }
        }
    }
});

board.create('functiongraph',  [function(x){ return 1000*Math.tan(x);} ])


Best wishes, Alfred

Reply all
Reply to author
Forward
0 new messages