Google图表,如何将空数据添加到列中

Jim*_*988 4 javascript google-visualization

我有以下行,其中的列声明为null作为我没有数据时的值...但它没有正确绘制图形...如何为列添加空数据以便该行将通过通过最后一个条目和当前条目之间的平均值?:

        function DrawChart() {      
            // Create the data table.
            var data = new google.visualization.DataTable();

            data.addColumn('date', 'Date');   
            data.addColumn('number', 'a name');                 
            data.addColumn('number', 'a name 2');                 
            data.addColumn('number', 'a name 3');                 

            data.addRows( [
                [new Date( 2013,  7,  1 ),1.5,null,null],
                [new Date( 2013,  6,  28 ),-1.5,null,null],
                [new Date( 2013,  6,  21 ),null,-1,null],
                [new Date( 2013,  6,  15 ),null,0,2],
                [new Date( 2013,  6,  7 ),1.5,null,null],
                [new Date( 2013,  6,  5 ),-1,null,null],
               [new Date( 2013,  6,  1 ),0.5,2,null],
            ] );  

            // Set chart options
            var options = {
                'title': 'tracker',
                'width': 800,
                'height': 600,
                'backgroundColor': 'transparent',
                chartArea: 
                {
                    left: 'auto',
                    top: 'auto'
                },
                hAxis: 
                {
                    title: 'Date of bla',
                    titleTextStyle: 
                    {
                        italic: false
                    },
                    gridlines: 
                    {
                        color: "#E3E3E3"
                    }, 
                    showTextEvery: 1
                },
                vAxis: 
                { 
                    title: 'Positivity',  
                    titleTextStyle: 
                    {
                        italic: false
                    },
                    gridlines: 
                    {
                        color: "#E3E3E3"
                    } 
                }
            };

            // Instantiate and draw our chart, passing in some options.
            var chart = new google.visualization.LineChart( document.getElementById('chartDiv') );  

            google.visualization.events.addListener( chart, 'select', selectHandler );

            chart.draw(data, options);
        }   
     </script>
Run Code Online (Sandbox Code Playgroud)

https://developers.google.com/chart/interactive/docs/reference#DataTable

在此输入图像描述

输入0而不是null意味着数据将变为0 ..我不希望发生这种情况..如果我将平均值放在最旧和最新数据之间,它仍然是一个可选择的点,我也不会想?

dla*_*rte 11

您希望使用"interpolateNulls"选项(在https://developers.google.com/chart/interactive/docs/gallery/linechart上)描述为"是否猜测缺失点的值.如果为true,则会猜测基于相邻点的任何缺失数据的值.如果为false,它将在未知点处的线上留下中断."