1

HighCharts の HTML-table-to-chart スクリプトを使用して、テーブルから折れ線グラフを作成しようとしています。

私はx軸を持ちたいdatetimeので、ここに私がやったことです:

  • Date.parse(this.innerHTML)行ヘッダーを日付文字列に変換するために使用します。
  • xAxis オプション オブジェクトに設定typeします。datetime

日付変換は機能しており、デフォルトのツールチップに正しく表示されますが、グラフ自体は x 値を日時ではなくカテゴリのように扱っています。ポイントオブジェクトの設定方法に関係していると思いますが、修正方法がわかりません。

Highcharts.visualize = function(table, options) {

    // the categories
    options.xAxis.categories = [];

    $('tbody th', table).each(function(i) {
        var date = Date.parse(this.innerHTML);
        options.xAxis.categories.push(date);
    });

    // the data series
    options.series = [];
    $('tr', table).each(function(i) {
        var tr = this;
        $('th, td', tr).each(function(j) {
            if (j > 0) { // skip first column
                if (i === 0) { // get the name and init the series
                    options.series[j - 1] = {
                        name: this.innerHTML,
                        data: []
                    };
                } else { // add values
                    options.series[j - 1].data.push(parseFloat(this.innerHTML));
                }
            }
        });
    });

    charts[charts.length] = new Highcharts.Chart(options);
};

助言がありますか?

ここにフィドルがあります:http://jsfiddle.net/supertrue/et2Vy/

4

3 に答える 3

0

dateTimeLabelFormats : Object 日時軸の場合、スケールは適切な単位に自動的に調整されます。このメンバーは、各ユニットに使用されるデフォルトの文字列表現を提供します。置換コードの概要については、dateFormat を参照してください。デフォルト: { 秒: '%H:%M:%S', 分: '%H:%M', 時: '%H:%M', 日: '%e. %b'、週: '%e. %b', month: '%b \'%y', year: '%Y' } ハイチャート参照の例

いずれにせよ、これは正しい答えではないかもしれませんが、これが役立つことを願っています:)

于 2012-06-14T07:08:28.590 に答える