score:2

Accepted answer

It is kinda possible. This code here produces:

enter image description here

It is not pretty code though.

score:0

Have you tried putting a comma-separated list of values under xAxis:{ categories:[{'5/29/2007', '9/4/2007', '9/23/2008'}] }

and for the chart: { series: [{null}, {300}, {400}] }

I believe you can also use a delegate for the xAxis labels or series labels so that you can test the values against a threshold and drop them out.

score:3

You can do it easily with .isLast and .isFirst, like this:

     xAxis: {
                type: 'datetime',
                labels: {
                    formatter: function() {
                        if(this.isLast || this.isFirst)
                            return [whatever label calculation you need];
                        else return null;
                    },
                },
                title: {
                    text: 'Date'
                }
            }

score:3

Old question, but there's now a cleaner way to do this with tickPositions.

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container'
    },
  xAxis: {
     type: 'datetime',
     labels: {
         // When using tickPositions, you'll also need to specify a label format.
         format: '{value:%e. %b}',
     },         
     tickPositions: [Date.UTC(2007,05,29), Date.UTC(2007,09,04)]
  },
  credits: {
     enabled: false
  },
  series: [{
     data: [
        [Date.UTC(2007,05,29), 300], // This x-axis value should be labeled.
        [Date.UTC(2007,09,03), 300], // NO LABEL for this value
        [Date.UTC(2007,09,04), 200]  // This x-axis value should be labeled.
     ]         
  }]
});

JSFiddle demo

Resulting Chart enter image description here

score:4

Regarding the (1) question, I believe you can't do that in datetime xAxis in HighCharts. When setting that type of axis, the framework calculates the ticks shown in the correspondent axis depending on the data you have.

In answer to the (2) question, I believe that so far you can't skip times in the datetime axis. However, and even though I haven't tried, you might want to look at some workaround using categories so you can use a formatter and replace the ticks that you don't want.

Despite all of the above, I did a workaround that you might want to use and that it just needs a little bit of formatting to be more or less what you were asking. Here it is:

var chart = new Highcharts.Chart({
chart: {
    renderTo: 'container'
},
xAxis: {
    type: 'datetime',
    labels: {
        enabled: false
    }

},

series: [{
    dataLabels: {
        enabled:true,
        formatter: function(){
            if(this.point === this.series.data[this.series.data.length - 1])
            {
                return this.x
            }
            if(this.point === this.series.data[0])
            {
                return this.x
            }
        } 
    },
    data: [
        [Date.UTC(2007,05,29), 300], 
        [Date.UTC(2007,09,23), 300], 
        [Date.UTC(2007,09,04), 400]
    ]
}]

});

Basically what I do is getting rid of the xAxis labels and just show the date in the point itself for the values that I want (first and last). Notice that you might want to format how that date is shown because right now is showing the timestamp in ms.

You can see this live in jsFiddle: xAxis labels deleted


Related Query

More Query from same tag