I have the following code (simplified example):
$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
xAxis: {
type: 'datetime'
},
series: [{
data: [
[Date.UTC(2016, 0, 1), 29.9],
[Date.UTC(2016, 0, 2), 106.4],
[Date.UTC(2016, 0, 3), 75],
[Date.UTC(2016, 0, 4), 129.2],
[Date.UTC(2016, 1, 10), 176.0],
[Date.UTC(2016, 1, 11), 176.0]
]
}],
});
});
Which gives me the following graph:
As you will see, there is a time gap in which there is no data, obtaining an unattractive result, especially when there are many points at both ends. What I hope to achieve is something like this:
This means that the plotted points only show the dates that exist.
Note: I am using Highcharts-4.2.6
Add a data point with a value of
undefined
, within the span you want not to display. For example:See a full example here .
The important part is obviously:
[Date.UTC(2016, 0, 5), undefined],
.If you are making a graph that shows a data value at given intervals of time (e.g. one value per day), then it is a good idea to generate a point for each day, even those points for which you do not have data , and explicitly make the value of those points
undefined
.In my opinion, it is important that the scale of the X axis is maintained . If you want to make your graph more aesthetic, you will have to ask yourself how you want to distort the data axes.
This is possible with highcharts, but you will have to manually calculate the values for the X axis, and provide a function that, given one of those values, returns the corresponding label.
I got it and it was easier than it seemed: