javascript - 将轴标签与刻度下的类型类别对齐

标签 javascript highcharts

我有一个类似于以下示例的图表(从 Highcharts 示例复制并针对我的问题的使用进行了修改):

enter image description here

http://jsfiddle.net/zryrgh3f/

Highcharts.chart('container', {
    title: {
        text: 'Chart reflow is set to true'
    },

    subtitle: {
        text: 'When resizing the window or the frame, the chart should resize'
    },


    xAxis: {
        categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
        labels: {
        }
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>

对于相同的数据集,我真正需要的是:

enter image description here

标签应向左移动到刻度线下方,并且应在最后一个刻度线下方添加下一个数字的附加标签(计算标签的值,以便预先知道要添加的值)(上面用红色写出) )。请注意,数据点相对于刻度的位置不会改变。

我猜我需要人为地添加额外的刻度,但我该如何做到这一点,以及如何首先正确定位所有标签?在我的第二个图表中,我硬编码了要偏移的像素数,但我正在寻找更好、更动态的解决方案,因为我的实际图表大小可能会随着调整大小而变化。

最佳答案

对于您的图表,您应该能够将 xAxis.tickmarkPlacement 与系列的 pointPlacement 选项一起使用。此选项允许您在刻度上以及刻度之间的数据点上添加标签。

http://api.highcharts.com/highcharts/xAxis.tickmarkPlacement http://api.highcharts.com/highcharts/plotOptions.series.pointPlacement

Highcharts.chart('container', {
  title: {
    text: 'Chart reflow is set to true'
  },
  subtitle: {
    text: 'When resizing the window or the frame, the chart should resize'
  },
  xAxis: {
    categories: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'],
    min: 0,
    max: 12,
    tickmarkPlacement: 'on',
    labels: {}
  },
  series: [{
  pointPlacement: 'between',
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
  }]
});

http://jsfiddle.net/zryrgh3f/3/

关于javascript - 将轴标签与刻度下的类型类别对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44672078/

相关文章:

javascript - 如何不断检查 JavaScript 函数是否可用,然后在可用时调用

javascript - 如何在移动浏览器的后台支持音频自动播放?

javascript - 在该对象的函数中迭代该对象的所有成员

javascript - Highcharts 返回错误 #15

javascript - 在 react 中动态更新 Highcharts 图表

javascript - 使用 Jquery 在组合框中动态添加选项

javascript - 如何更新 map Canvas 的谷歌地图改变了它的尺寸?

javascript - 从 CSV 将 highcharts 添加到 mapbox 弹出窗口?

HighCharts - 动态更改轴标题颜色

javascript - 在高 map 中的纬度/经度 map 点上单击事件