JSXGraph logo
JSXGraph
JSXGraph share

Share

Axes configuration
QR code
<iframe 
    src="https://www.jsxgraph.org/share/iframe/axes-configuration" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Axes configuration" 
    allowfullscreen
></iframe>
This code has to
<style>
.tickLabels {
  background-color: white;
  padding: 0px
}
</style>

<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution ShareAlike 4.0 International License.
    https://creativecommons.org/licenses/by-sa/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    const board = JXG.JSXGraph.initBoard(BOARDID, {
        boundingbox: [-9, 17, 9, -17],
        axis: true,
        defaultAxes: {
            x: {
                ticks: {
                    insertTicks: false, // Turn off automatic tick placing
                    minorTicks: 1,        // One minor tick between two major ticks
                    minorHeight: -1,    // Minor ticks are finitely long, too
                    ticksDistance: 2,   // Major ticks are positioned at multiples of two
                    label: {
                        fontSize: 14,
                        display: 'html',
                        cssClass: 'tickLabels'
                    }
                }
            },
            y: {
                ticks: {
                    insertTicks: false,  // Turn off automatic tick placing
                    minorTicks: 0,        // No minor ticks between major ticks
                    ticksDistance: 2,   // Major ticks are positioned at multiples of two
                    label: {
                        fontSize: 14,
                        display: 'html',
                        cssClass: 'tickLabels'
                    }
                }
            }
        },
        zoom: {
            min: 0.5,
            max: 2
        }
    });
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-sa/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-9, 17, 9, -17],
    axis: true,
    defaultAxes: {
        x: {
            ticks: {
                insertTicks: false, // Turn off automatic tick placing
                minorTicks: 1,        // One minor tick between two major ticks
                minorHeight: -1,    // Minor ticks are finitely long, too
                ticksDistance: 2,   // Major ticks are positioned at multiples of two
                label: {
                    fontSize: 14,
                    display: 'html',
                    cssClass: 'tickLabels'
                }
            }
        },
        y: {
            ticks: {
                insertTicks: false,  // Turn off automatic tick placing
                minorTicks: 0,        // No minor ticks between major ticks
                ticksDistance: 2,   // Major ticks are positioned at multiples of two
                label: {
                    fontSize: 14,
                    display: 'html',
                    cssClass: 'tickLabels'
                }
            }
        }
    },
    zoom: {
        min: 0.5,
        max: 2
    }
});

Axes configuration

This is a specific example to style the default axes. - Turn off automatic tick positioning by `insertTicks: false` - The $x$-axis has labels at every other tick line: `minorTicks: 1` - The $y$-axis has labels at every tick line: `minorTicks: 0` - Both axes have labels for 2, -2, 4, -4, 6, ...: `ticksDistance: 2` - If the automatic tick positioning is turned off, there will appear performance problems if users zoom out. Therefore, it might be advisable to limit the zoom factor: `zoom: {min: 0.5, max: 2}` - The labels can be styled by supplying a CSS class: `label: {fontSize: 14, display: 'html', cssClass: 'tickLabels'}`
<style>
.tickLabels {
  background-color: white;
  padding: 0px
}
</style>
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-9, 17, 9, -17],
    axis: true,
    defaultAxes: {
        x: {
            ticks: {
                insertTicks: false, // Turn off automatic tick placing
                minorTicks: 1,        // One minor tick between two major ticks
                minorHeight: -1,    // Minor ticks are finitely long, too
                ticksDistance: 2,   // Major ticks are positioned at multiples of two
                label: {
                    fontSize: 14,
                    display: 'html',
                    cssClass: 'tickLabels'
                }
            }
        },
        y: {
            ticks: {
                insertTicks: false,  // Turn off automatic tick placing
                minorTicks: 0,        // No minor ticks between major ticks
                ticksDistance: 2,   // Major ticks are positioned at multiples of two
                label: {
                    fontSize: 14,
                    display: 'html',
                    cssClass: 'tickLabels'
                }
            }
        }
    },
    zoom: {
        min: 0.5,
        max: 2
    }
});

license

This example is licensed under a Creative Commons Attribution ShareAlike 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.