How to get Highcharts X-Axis Categories starting at the left most point

前端 未结 6 1823
慢半拍i
慢半拍i 2020-12-29 09:55

I have a Highcharts area chart, with string categories on the X-Axis. I want the chart to start at the left most edge of the x-axis and end at the rightmost edge, without an

相关标签:
6条回答
  • 2020-12-29 10:08

    A cleaner solution is to use the pointPlacement reference provided in the Highchart API.

    Add pointPlacement: 'on' and you should be in business. (For reference, here is their example JSFiddle)

    0 讨论(0)
  • 2020-12-29 10:10

    You can use spacingLeft and spacingRight to set the spacing:

    chart: {
             renderTo: 'chart1',
             type: 'area',
             spacingLeft: -21,      
             spacingRight: -21,      
             spacingBottom: 1
    },
    
    0 讨论(0)
  • 2020-12-29 10:14

    You can achieve the desired result by redefining labels.formatter on axis. jsFiddle is here.

    But if you want to keep it simple and pass axis.categories in traditional way (I think that this is a way more better), I suggest you to use a tiny hack and redefine an Axis.init function. Try it on jsFiddle.

    UPD: I've updated my previous fiddle a little. Check it out. I think that you can combine all my solution to get a nicer one.

    0 讨论(0)
  • 2020-12-29 10:14

    You need the following settings.

    xAxis: {           
      plotLines: [{
        value: 0, 
        color: '#color'
      }],
      tickmarkPlacement: 'on'
    },
    yAxis: {           
      lineWidth: 0,
    }
    
    0 讨论(0)
  • 2020-12-29 10:22
    xAxis: {
    categories: ['cat1', 'cat2', 'cat3', 'cat4', 'cat5']
    },
    series: [
        {
          name: 'name of series',
          data: [0, 2, 0, 2, 0],
          pointPlacement: 'on',
        }
    ]
    

    This solution worked for me, maybe it helps. I can't confirm whether or not this applies to other ways of inputting data.

    0 讨论(0)
  • 2020-12-29 10:27

    Just add:

    ...
    xAxis: {
      startOnTick: true,
      ...
    },
    ...
    
    0 讨论(0)
提交回复
热议问题