4

I have an issue that I have been able to replicate on JFiddle. Link: http://jsfiddle.net/h5sSR/

$(function() {
var chart = new Highcharts.StockChart({

    chart: {
        renderTo: 'container'
    },

    tooltip: {
        backgroundColor: {
            linearGradient: {
                x1: 0, 
                y1: 0, 
                x2: 0, 
                y2: 1
            },
            stops: [
                [0, 'white'],
                [1, '#EEE']
            ]
        },
        xDateFormat: '%m/%e/%y %H:%M',
        borderColor: 'gray',
        borderWidth: 1
    },

    rangeSelector: {
        selected: 1
    },

    series: [{
        name: 'USD to EUR',
        data: usdeur
    }]
});
});

The Problem: I need the xDateFormat attribute to be applied under ToolTip at all times (month / day / year hour : minute). It works perfectly when you have a small amount of data selected. It uses a different format when you have a large amount of data selected to view.

The Example: Try it on the JFiddle (link above). It initializes to a small amount of data visible and when you hover, you will see the Date like so: 12/3/12 0:0. That's perfect. Now drag the navigator to the beginning and hover on the graph, the DateFormat changes to (Week from Day of Week, Month Day, Year).

How to Solve: Why is this happening and how can I apply the xDateFormat attribute all the time regardless of how much data is being displayed?

4

3 回答 3

5

看看文档:http ://api.highcharts.com/highstock#tooltip.xDateFormat

工具提示标题中日期的格式。如果使用数据分组,则默认是根据最近点的接近程度进行智能猜测。它是从 #plotOptions.dataGrouping.dateTimeLabelFormats 数组中提取的。

因此,您可以在这里找到应该更改的内容:http: //api.highcharts.com/highstock#plotOptions.series.dataGrouping.dateTimeLabelFormats - 适用于相同格式的所有表单,并且可以正常工作。

于 2013-03-05T13:01:19.310 回答
3

这是解决此问题的新代码(在 Pawel Fus 将我链接到解决方案之后):

plotOptions : {
                    series : {
                        dataGrouping : {
                            dateTimeLabelFormats : {
                                millisecond: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M'],
                                second: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M'],
                                minute: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M'],
                                hour: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M'],
                                day: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M'],
                                week: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M'],
                                month: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M'],
                                year: ['%m/%e/%y %H:%M', '%m/%e/%y %H:%M', '-%H:%M']
                            }
                        }
                    }
                },

这将“完成”。这里是更新的 JFiddle 链接:http: //jsfiddle.net/h5sSR/1/

于 2013-03-05T16:57:15.370 回答
0

HighStockchart 默认分组数据https://api.highcharts.com/highstock/plotOptions.series.dataGrouping.dateTimeLabelFormats

就我而言,我只是禁用了数据分组并设置xDateFormat它对我有用

plotOptions: {
        series: {
          dataGrouping: {
            enabled: false
          }
        }
}
于 2021-12-15T18:24:44.660 回答