###前提・実現したいこと
chart.jsを使用しての横軸のラベルの書式の設定方法を教えてください。
###発生している問題・エラーメッセージ
横軸ラベルの書式が反映されません。
chart.js 2.1 を読み込んでます。
エラーメッセージ
###該当のソースコード
javascript
1var timeFormat = 'MM/DD/YYYY HH:mm'; 2 var config = { 3 type: 'line', 4 data: { 5 6labels: [ // Date Objects 7 "05/12/2017 01:20", 8 "05/12/2017 02:20", 9 "05/12/2017 03:20", 10 "05/12/2017 04:20", 11 "05/12/2017 10:20", 12 "05/12/2017 15:20", 13 "05/12/2017 20:20" 14 ], 15 16datasets: [ 17 { 18 label: "Dataset with point data", 19 backgroundColor: color(window.chartColors.green).alpha(0.5).rgbString(), 20 borderColor: window.chartColors.green, 21 fill: false, 22 data: [{ 23 x: "05/12/2017 01:29", 24 y: 10 25 }, { 26 x: "05/12/2017 10:29", 27 y: 20 28 }, { 29 x: "05/12/2017 19:29", 30 y: 30 31 }, { 32 x: "05/12/2017 22:29", 33 y: 2 34 } 35 ], 36 }] 37 } 38 , 39 options: { 40 title:{ 41 display: true, 42 text: "Chart.js Time Scale" 43 }, 44 scales: { 45 xAxes: [{ 46 type: "time", 47 time: { 48 format: timeFormat, 49 }, 50 scaleLabel: { 51 display: true, 52 labelString: '---Time---' 53 } 54 //displayFormats: 'h:mm:ss' // NG 55 //displayFormats: 'HH:mm' // NG 56 //displayFormats: timeFormat // NG 57 //displayFormats: "minute" // NG 58 //displayFormats: 'MMM YYYY' // NG 59 }, ], 60 yAxes: [{ 61 ticks: { 62 min: 0, // 原点0 63 max: 70 64 }, 65 66scaleLabel: { 67 display: true, 68 labelString: 'value' 69 } 70 }] 71 }, 72 } 73 }; 74
###試したこと
displayFormats を使用したのですが、変化なしでした。よろしくお願いします。
//displayFormats: 'h:mm:ss' // NG
//displayFormats: 'HH:mm' // NG
//displayFormats: timeFormat // NG
//displayFormats: "minute" // NG
//displayFormats: 'MMM YYYY' // NG
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー