最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Highcharts - Skip date in series - Stack Overflow

programmeradmin0浏览0评论

So I'm pulling some data from a database and getting a UNIX Timestamp and a number. So lets say N (number) was sold on D (date).

There are days missing, like the weekend. I need it to still display the day, but not require any data. It's a line chart.

April 1 2010, 50 sold
April 2 2010, 53 sold
April 7 2010, 10 sold
(I have over a 1,000 records spanning a several years - so I will add a zoom as well)

So the chart should still show April 1-7 but have no data for 3-6. (the line would just go from 2-7).

Any ideas on how to do this?

Thanks, Josh

So I'm pulling some data from a database and getting a UNIX Timestamp and a number. So lets say N (number) was sold on D (date).

There are days missing, like the weekend. I need it to still display the day, but not require any data. It's a line chart.

April 1 2010, 50 sold
April 2 2010, 53 sold
April 7 2010, 10 sold
(I have over a 1,000 records spanning a several years - so I will add a zoom as well)

So the chart should still show April 1-7 but have no data for 3-6. (the line would just go from 2-7).

Any ideas on how to do this?

Thanks, Josh

Share Improve this question asked Nov 24, 2010 at 20:58 JoshJosh 8191 gold badge14 silver badges30 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

take a look here: http://highcharts./ref/#series second example of 'data' property.

You just have to convert mysql date, convert it to UNIX timestamp (UNIX_TIMESTAMP()), and then multiply it by 1000 (JS needs time in microseconds)...

Scale the x axis of your data when you're creating the chart to only count the days when you have at least one sale, and just ensure your axis is labelled sensibly.

This would mean stepping through your entire data set and ensuring it has sequential numbers. So might not be terribly efficient and could certainly benefit for pre-processing (another key in your database for "sale day" or something).

You can plot your data as normal Y data and use a formatter on the x-axis

dates = ['April 1 2010', 'April 2 2010', 'April 7 2010'];
numSold = [50, 53, 10];

chart = new Highcharts.Chart({
    series: [{
        type: 'line',
        data: numSold
    }],
    xAxis: {
        labels: {
            formatter: function() {
                var dateStr = dates[this.value];
                return dateStr;
            }
        }
    }
});
发布评论

评论列表(0)

  1. 暂无评论