【问题标题】:Set distance between labels and chart in Highcharts在 Highcharts 中设置标签和图表之间的距离
【发布时间】:2020-12-03 20:04:21
【问题描述】:

我有以下图表,我想增加 y 轴标签和图表之间的距离(浅蓝色线) - 检查图像,10k 和蓝色线之间的距离更大

在y轴我尝试结合yAxis偏移、yAxis标签填充和yAxis标题边距的设置,但没有成功

我如何做到这一点?

这些是图表的设置

       options: {              
          chart: { 
            updateArgs: [false, false, true],
            borderWidth: 1,
            marginLeft: 40,
            marginRight: 2,
            type:'line',
            zoomType: 'x',
            animation: false,
            height:250,
            title: {
                text: ''
            }, 
            panning:true 
          },
          title: {
            text: ''
          },
          time:{
            useUTC:true
          },  
          credits:{
            enabled:false
          },
          tooltip: {
            shared: true,
            formatter: this.tooltipFormatter
          },
          title:{
            text:null
          },
          lang: {
            noData: 'loading...'
          },
          rangeSelector: {
            inputEnabled: false
          },
          xAxis:{
            type:'datetime',
            max:this.maxdate,
            min:this.mindate,
            title:
            {
              align:'high'
            }, 
            labels: {
              padding: 50,
              format: '{value:%H:%M}',
              style: {
                fontSize: '10px'
              }
            },
            crosshair: {
                enabled: true,
                width: 1,
                color: '#000'
            },
            events : {
                afterSetExtremes : this.afterSetExtremes
            }
          },   
          yAxis: {
            title: {
              text: this.streamChart.title + '  [' + this.streamChart.unit+']',
              margin:20,
              fontSize:"15px"
            },
            labels: {
              step: 2,
              staggerLines: 2,
              enabled:true,
              align: 'left',
              padding:0
            },
            alignTicks:'left', 
            textAlign:'left',
            align:'middle', 
            opposite:false, 
            offset:0
          },    
          plotOptions: {
            series: {
              animation: false,
              boostThreshold: 1,
              pointInterval: 3600 * 1000
            }
          },
          legend: {
            enabled: false
          },
          responsive: {
            rules: [{
                condition: {
                    maxWidth: '100%',
                    minHeight: 300
                },
                chartOptions: {
                    subtitle: {
                        text: null
                    },
                    navigator: {
                        enabled: false
                    },
                    legend: {
                      enabled: false
                    },
                    yAxis: {
                      title: {
                        enabled: false
                      }
                    }
                }
            }]
          }   
          ,series: [{ 
            name:this.streamChart.title,
            id:this.streamChart.id,
            data:[]
          }],

      }, 

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    增加chart.marginLeft 并启用reserveSpace 或通过x 属性对齐标签:

    labels: {
      ...,
      reserveSpace: true
    }
    

    现场演示: http://jsfiddle.net/BlackLabel/71gxj4sd/

    API 参考:

    https://api.highcharts.com/highcharts/yAxis.labels.reserveSpace

    https://api.highcharts.com/highcharts/yAxis.labels.x

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-25
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多