Reputation: 5813
What would be the best approach to creating the graph just like the one below using JSXGraph? For example, how would I make axis go beyond the grid, etc.?
Have looked at the official documentation and external guides. Could not find information on how to adjust the ticks, grid, and axis so that I can generate the included graph.
Upvotes: 0
Views: 246
Reputation: 2323
Indeed, axis configuration is sort of complicated in JSXGraph. First, I would not recommend to use the deprecated grid, since it does not have tick labels. For configuration of default axes, JSXGraph has the attribute defaultAxes
.
The horizontal axis can be accessed by the sub-attribute x
, the vertical axis by y
.
Now, we do the following to imitate the above image:
insertTicks: false
minorTicks: 1
minorTicks: 0
ticksDistance: 2
zoom: {min: 0.5, max: 2}
label: {fontSize: 16, display: 'html', cssClass: 'tickLabels'}
Here is the complete example:
const board = JXG.JSXGraph.initBoard('jxgbox', {
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: 16, 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: 16, display: 'html', cssClass: 'tickLabels'}
}
}
},
zoom: {
min: 0.5,
max: 2
}
});
.tickLabels {
background-color: white;
padding: 1px
}
See it live at https://jsfiddle.net/b684vfaL/2/.
Upvotes: 0