首页 文章

Highcharts - 柱形图与空列在x轴上的日期

提问于
浏览
2

是否有任何方法可以使用 datetime 类型使用't render empty column if I' m的列或折线图?因为我想在没有周末的情况下显示最近7天,但这似乎不可能 .

示例:http://jsfiddle.net/G5S9L/7/

预计:不显示6月17日/ 18日

我尝试的第二件事是使用 category 类型 . 在这种情况下,图表只是呈现系列数据中指定的这些列 . 但我的图表由多个系列组成,每个系列都会有一些差距 . Highchart与类别名称不匹配,并将所有y值相互匹配 .

例如:http://jsfiddle.net/G5S9L/6/

预计:周四有2列/柱以及周一

这些样本非常简单 . 我知道我可以生成一个包含x轴所有值的主列表,并根据主列表对每个系列进行排序,并用NULL值填充空白 . 但这为我的统计数据生成数据带来了沉重的开销 . 因为并非所有系列都具有相同的源来确定x轴的范围 .

2 回答

  • 2

    有了Highcharts吗?实现这一目标并非简单的方法 .

    但是,使用Highstock,只需使用 xAxis.ordinal = true ,一切都会正常工作 . 见:http://jsfiddle.net/G5S9L/8/

  • 0

    对于第二个问题,您可以简单地扩展Point类(wrap applyOptions方法),并设置xAxis的类别 .

    (function (H) {
        H.wrap(H.Point.prototype, 'applyOptions', function (applyOptions, options, x) {
            var point = applyOptions.call(this, options, x),
                series = point.series;
    
            // check if 
            // 1. there is a name(category)
            // 2. xAxis has the categories defined
            // 3. x value equals xIncrement
            if (point.name && series.xAxis.categories && point.x === series.xIncrement - 1) {
    
                // find a matching category?
                var idx = series.xAxis.categories.indexOf(point.name);
                if (idx >= 0) {
                    point.x = idx;
                }
            }
    
            return point;
        });
    
    })(Highcharts);
    

    见小提琴:http://jsfiddle.net/G5S9L/17/

相关问题