日期时间值和在数据点之间打印样条图的问题



谁能帮助解决以下问题:

尝试绘制一个包含四个数据序列的图表,其中两个是散点,一个是样条。样条的目的只是在图表上的特定点之间画一条线,而不是将它们连接在一起。下面是我到目前为止的代码:

$(function () {
    var chart;
    $(document).ready(function() {
        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'scatter',
                zoomType: 'xy'
            },
            title: {
                text: ''
            },
            xAxis: {
              type: 'datetime',
              ordinal: false,
              labels: {
                formatter: function() {
                   return Highcharts.dateFormat('%H', this.value);
                }
              }
            },
            yAxis: {
              categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
              gridLineWidth: 0,
              step: 1,
              title: '',
              labels: {
                style: {
                  color: '#6D869F',
                  fontSize: '9px',
                }
              },
            },
            tooltip: {
                formatter: function() {
                        return ''+
                        this.x +' cm, '+ this.y +' kg';
                }
            },
            legend: {
                layout: 'vertical',
                align: 'left',
                verticalAlign: 'top',
                x: 100,
                y: 70,
                floating: true,
                backgroundColor: '#FFFFFF',
                borderWidth: 1
            },
            plotOptions: {
                scatter: {
                    marker: {
                        radius: 5,
                        states: {
                            hover: {
                                enabled: true,
                                lineColor: 'rgb(100,100,100)'
                            }
                        }
                    },
                    states: {
                        hover: {
                            marker: {
                                enabled: false
                            }
                        }
                    }
                }
            },
            series: [{
                name: 'sleep time',
                marker: {
                  symbol: 'circle',
                },
                color: '#81c65b',
                data: [[Date.UTC(2012, 1, 1, 22, 15), 0], 
                       [Date.UTC(2012, 1, 1, 20, 30), 3],
                       [Date.UTC(2012, 1, 1, 21, 45), 5],
                       [Date.UTC(2012, 1, 1, 22, 00), 6]]
            }, 
            {
              name: 'wakeup time',
              marker: {
                symbol: 'circle',
                fillColor: '#76a4fb',
              },
              data: [[Date.UTC(2012, 1, 2, 08, 15), 0], 
                     [Date.UTC(2012, 1, 2, 07, 10), 1],
                     [Date.UTC(2012, 1, 2, 09, 20), 2],
                     [Date.UTC(2012, 1, 2, 07, 40), 3],
                     [Date.UTC(2012, 1, 2, 07, 30), 4],
                     [Date.UTC(2012, 1, 2, 08, 20), 5],
                     [Date.UTC(2012, 1, 2, 09, 30), 6]],
           },
           {
              name: 'sleep time over average',
              color: 'rgba(119, 152, 191, .5)',
              marker: {
                symbol: 'square',
                  fillColor: '#000',
              },
              data: [[Date.UTC(2012, 1, 1, 20, 15), 1],
                     [Date.UTC(2012, 1, 1, 23, 40), 2], 
                     [Date.UTC(2012, 1, 1, 21, 20), 4]]
           },
           {
              name: '',
              legend: {
                enabled: false,
              },
              color: '#d62a9c',
              type: 'spline',
              marker: {
                enabled: false,
              },
              data: [[Date.UTC(2012, 1, 1, 22, 15), 0], 
                     [Date.UTC(2012, 1, 2, 08, 15), 0],
                     [Date.UTC(2012, 1, 1, 20, 15), 1], 
                     [Date.UTC(2012, 1, 2, 07, 10), 1],
                     [Date.UTC(2012, 1, 1, 23, 40), 2], 
                     [Date.UTC(2012, 1, 2, 09, 20), 2],
                     [Date.UTC(2012, 1, 1, 20, 30), 3], 
                     [Date.UTC(2012, 1, 2, 07, 40), 3],
                     [Date.UTC(2012, 1, 1, 21, 20), 4], 
                     [Date.UTC(2012, 1, 2, 07, 30), 4],
                     [Date.UTC(2012, 1, 1, 21, 45), 5], 
                     [Date.UTC(2012, 1, 2, 08, 20), 5],
                     [Date.UTC(2012, 1, 1, 22, 00), 6], 
                     [Date.UTC(2012, 1, 2, 09, 30), 6]]
           }]
        });
    });
});

我现在的问题是,在样条序列中,如果我在元素之间添加一个null来阻止两点之间的直线,整个绘图就会混乱。这个想法是只画直线,以便垂直在同一直线上的点连接在一起。在这里是"睡眠时间"one_answers"起床时间"。例如,

data: [
  [Date.UTC(2012, 1, 1, 22, 15), 0], 
  [Date.UTC(2012, 1, 2, 08, 15), 0], null,
  [Date.UTC(2012, 1, 1, 20, 15), 1], 
  [Date.UTC(2012, 1, 2, 07, 10), 1], null,
  [Date.UTC(2012, 1, 1, 23, 40), 2], 
  ...

尝试以下操作。

data: [
    [Date.UTC(2012, 1, 1, 22, 15), 0], 
    [Date.UTC(2012, 1, 2, 08, 15), 0],
    [Date.UTC(2012, 1, 2, 08, 15), null],
    [Date.UTC(2012, 1, 1, 20, 15), 1], 
    [Date.UTC(2012, 1, 2, 07, 10), 1],
    [Date.UTC(2012, 1, 2, 08, 15), null],
    [Date.UTC(2012, 1, 1, 23, 40), 2], 
    [Date.UTC(2012, 1, 2, 09, 20), 2],
    [Date.UTC(2012, 1, 2, 08, 15), null],
    ...
]

正如你所看到的,你必须传递一个数组,它的第一个值必须是任意日期。

相关内容

  • 没有找到相关文章

最新更新