简体   繁体   English

高图:不规则数据的规则间隔

[英]Highcharts: regular interval for irregular data

I have the stored procedure that returns the sensor data that have been stored in the database. 我具有存储过程,该过程返回已存储在数据库中的传感器数据。 To display the values I build graphs using the Highcharts library. 为了显示值,我使用Highcharts库构建了图形。

execute [sensors].[dbo].[usp_deddt] 50320001, 1, '20150801', '20150821';

Sometimes, for some time to, the data do not come - I get the gap, for example: 有时,一段时间以来,数据不会出现-我得到了差距,例如:

在此处输入图片说明

Then my histogram takes the form: 然后我的直方图采用以下形式:

在此处输入图片说明

I'd like to see on the X-axis continuous time series. 我想在X轴连续时间序列上看到。

For example, in my case it should be: 例如,就我而言,应为:

16.08.2015 15:00 16.08.2015 16:00 16.08.2015 17:00 16.08.2015 18:00

How to set regular interval for irregular data? 如何为不规则数据设置规则间隔?

If I understand from your example correctly it seems that you are using categories for the x axis. 如果我从您的示例中正确理解,似乎您正在使用x轴的类别。

You can solve this problem, without the complication of making fake database data, by simply eliminating categories and using instead a datetime x axis. 通过简单地消除类别并改用datetime x轴,您可以解决此问题,而不会增加制造假数据库数据的复杂性。

Your time stamp values would be used to plot the values along the x axis, which means they would, by default, without adding complication to your database, or unnecessary looping, accomplish a continuous x axis, with the data plotted where it actually occurs. 您的时间戳值将用于沿x轴绘制值,这意味着默认情况下,它们将在不实际增加数据库复杂性或不必要的循环的情况下完成连续的x轴,并绘制实际出现的数据。

Well as I know you cannot do that many things. 据我所知,您不能做那么多事情。 The Highcharts display the series, so if yours has a gap it won't automatically get filled. 高图表显示系列,因此如果您有缺口,则不会自动填充。

What you can do is manually generating the missing parts. 您可以做的是手动生成缺少的部分。 Eg you can generate it on the database level: 例如,您可以在数据库级别生成它:

/* create a table with all possible hours */
create table hours (hour varchar2);

insert into hours values ('01:00');
insert into hours values ('02:00');
insert into hours values ('03:00');
insert into hours values ('04:00');
/* ... */

/* the same for days */
/* ... */

Then just outer-join them with your table by the compound date value and you will get your series with all gaps filled. 然后,通过复合日期值将它们与表进行外部联接,就可以填补所有空白。

Also some databases allow you to generate the datasets instead of creating these tables which somebody would call trash and probably would be right, eg in Oracle you can use connect by level statements to achieve this without tables at all. 还有一些数据库允许您生成数据集,而不是创建这些表,有人称其为“垃圾箱”并且可能是正确的,例如,在Oracle中,您可以使用“按级别连接”语句来完全不用表来实现此目的。

Another approach would be to generate them on a JavaScript side. 另一种方法是在JavaScript端生成它们。 You take your array as an input and process it by passing inside the missing values. 您将数组作为输入并通过传递缺失值来对其进行处理。

Many thanks to all for the help... My small solution: 非常感谢大家的帮助...我的小解决方案:

Added the attribute gapSize from Highstock to mark the gap. Highstock添加了属性gapSize以标记间隙。

$scope.highchartsNG = {
        options: {
            chart: {
                zoomType: 'x, y'
            },

            plotOptions: {
                column: { stacking: 'normal', color: '#007a94'},
                bar: { dataLabels: {  enabled: true } }
            },
        },

        title: {
              text: ''
        },

        xAxis: {
            type: 'datetime',
            dateTimeLabelFormats: {
                month: '%e. %b',
                year: '%b'
            },
        },

        series: [{
            type : 'column',
            showInLegend: false,                
            gapSize: 1,
            data: []
        }]
}

In my AngularJS controller I wrote the method (relevant part): 在我的AngularJS控制器中,我编写了该方法(相关部分):

... 
var measurementData = [];   
$scope.setGraphValues = function () {
    ...
    var data = $scope.tableData;
    for(var i = 0; i < data.length; i++) {
        measurementData.push([Date.UTC(yearPart, monthPart,
            dayPart, hourPart, minutePart),data[i].measureData]);
    }
    ...
    $scope.highchartsNG.series[0].data = measurementData;
}

Now everything is OK. 现在一切正常。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM