JSXGraph更改轴刻度到日期

时间:2019-11-17 07:42:32

标签: jsxgraph

如何更改给定示例的xaxis标签或刻度以显示日期?

http://jsxgraph.uni-bayreuth.de/wiki/index.php/Time_series_II

1 个答案:

答案 0 :(得分:0)

您可以“手动”插入刻度线并将其标签设置为任意字符串。这是一个示例,请参见https://jsfiddle.net/8f65cgdq/7/

// Initialize the board without axes
const board = JXG.JSXGraph.initBoard('jxgbox', { 
    boundingbox: [-1, 100, 10, -8], axis:false
});

// Add a vertical axis
board.create('axis',[[0, 0], [0, 10]]);
// Add a horizontal axis
var xaxis = board.create('axis',[[0,0], [1,0]]);
// Remove the default ticks
xaxis.removeTicks(xaxis.defaultTicks);

// Create your own ticks with non-standard labels
var ticks = board.create('ticks', [xaxis, 
    [2, 4, 6, 8]], {
    labels: ['1.8.2019', '15.8.2019', '30.8.2019', '15.9.2019'],
    strokeColor: '#00ff00', 
    majorHeight: -1, 
    drawLabels: true, 
    label: {offset: [0,-5], anchorX: 'middle', anchorY: 'top'}
  });