狛ログ

2014年9月7日日曜日

Highcharts JS で Highcharts error #14。

オフィス狛 技術部です。

あるシステムで Highcharts JS を使っているのですが、
新しいグラフを追加する事になり、データ提供元のWebAPIを利用しJSONを取得して表示したところ、
以下のエラーになりました。
Highcharts error #14: www.highcharts.com/errors/14

軸のデータが変わっただけで、グラフ表示形式も、JSON形式も他のグラフと違いないはず・・・
とりあえず、エラーメッセージには親切にもURLが付いているのでアクセスしてみます。

String value sent to series.data, expected Number
This happens if you pass in a string as a data point, for example in a setup like this:
series: [{
data: ["3", "5", "1", "6"]
}]
Highcharts expects the data values to be numbers. The most common reason for this is that data is parsed from CSV or from a XML source, and the implementer forgot to run parseFloat on the parsed value. For performance reasons internal type casting is not performed, and only the first value is checked (since 2.3).

読み解くと、x、y軸に表示するデータは、数値扱いにしなければならない。
という事のようです。
上記の例だと、
 series: [{
     data: [3, 5, 1, 6]
 }]
このようにダブルクォーテーションを取る・・・という事ですね。

実は今回のWebAPIも弊社が作成しているので、WebAPI側を修正する事が出来ました。
逆に言うと、他社のWebAPIを利用する場合に、こんな現象に遭遇したら・・・嫌ですね。