javascript - Amcharts Candle-Stick气球文本以错误的格式显示时间戳

我正在使用amcharts绘制烛台图案图。 图表显示效果很好,但气球以其他格式显示了时间戳。

在此处输入图片说明

在此处输入图片说明

实际上,这些值采用“ HH:MM:SS”格式,但是气球显示的格式有所不同。 仅在“中间:”(即14:23:49 )中正确显示的位置

这是我的代码:

var chart = AmCharts.makeChart("chartdiv", {
  "type": "serial",
  "theme": "light",
  "titles": [{
    "text": "amCharts Box Plot Example",
    "size": 15
  }],
  "graphs": [{
    "type": "candlestick",
    "balloonText": "High: [[high]]\n Open: [[open]]\n Mid: [[mid]]\n Close: [[close]]\nLow: [[low]]",
    "highField": "high",
    "openField": "open",
    "closeField": "close",
    "valueField": "close",
    "lowField": "low",
    "fillColors": "#ffffff",
    "lineColor": "blue",
    "lineAlpha": 1,
    "fillAlphas": 0.9,
    "columnWidth": 0.4
  }, {
    "type": "column",
    "columnWidth": 0.2,
    "valueField": "high",
    "openField": "high",
    "lineColor": "blue",
    "lineThickness": 3,
    "showBalloon": false,
    "clustered": false
  }, {
    "type": "column",
    "columnWidth": 0.2,
    "valueField": "low",
    "openField": "low",
    "lineColor": "blue",
    "lineThickness": 3,
    "showBalloon": false,
    "clustered": false
  }, {
    "type": "column",
    "columnWidth": 0.4,
    "valueField": "mid",
    "openField": "mid",
    "lineColor": "orange",
    "lineThickness": 3,
    "showBalloon": false,
    "clustered": false
  }
"chartCursor": {
    "valueLineEnabled": true,
    "valueLineBalloonEnabled": true
  },
  "categoryField": "exp",
  "categoryAxis": {
    "title": "Experiment No.",
    "gridPosition": "start",
    "tickPosition": "start",
    "tickLength": 10,
    "axisAlpha": 0.7,
    "gridAlpha": 0
  },

   "dataDateFormat": "HH:NN:SS",
                        //"dataProvider": chartData,
                        "valueAxes": [{
                                "id": "v1",
                                "position": "left",
                                "title": "Time of the Day",
                                "type": "date",
                               // "minimumDate": minDateStr,
                               // "maximumDate": maxDateStr,
                                "markPeriodChange": false,
                                "autoGridCount": false,
                                "gridCount": 7,
                                "minPeriod": "ss",
                            }

                        ],

下面是dataProvider:

 "dataProvider": [{
    "exp": 1,
    "high": "07:54:00",
    "open": "07:45:00",
    "mid": "05:23:49",
    "close":"04:48:37",
    "low": "03:44:57",
    "interimSLA": "12:30:00",
    "targetedSLA": "08:00:00",
  }, {
    "exp": 2,
    "high": "09:54:00",
    "open": "08:10:00",
    "mid": "05:23:49",
    "close":"04:48:37",
    "low": "03:44:57",
    "interimSLA": "12:30:00",
    "targetedSLA": "08:00:00",
  }, {
    "exp": 3,
   "high": "17:54:00",
    "open": "15:20:00",
    "mid": "14:23:49",
    "close":"12:48:37",
    "low": "11:44:57",
    "interimSLA": "12:30:00",
    "targetedSLA": "08:00:00",
  }, {
    "exp": 4,
   "high": "11:54:00",
    "open": "08:10:00",
    "mid": "05:23:49",
    "close":"04:48:37",
    "low": "02:44:57",
    "interimSLA": "12:30:00",
    "targetedSLA": "08:00:00",
  }, {
    "exp": 5,
   "high": "15:54:00",
    "open": "12:50:00",
    "mid": "05:23:49",
    "close":"04:48:37",
    "low": "03:44:57",
    "interimSLA": "12:30:00",
    "targetedSLA": "08:00:00",
  }]

不知道为什么它不能全部显示给定格式。 我需要明确格式化它们吗? 任何建议将不胜感激。

通常,您可以将图形对象中的dateFormat设置为所需的输出格式(在这种情况下为HH:NN:SS ),它将起作用,但是它似乎不会影响[[open]][[value]] 在这种情况下,您唯一的选择是使用balloonFunction并手动格式化它们。

这是一个基本演示,仅从数据中返回直接字符串值,而无需重新格式化:

 var chart = AmCharts.makeChart("chartdiv", { "type": "serial", "theme": "light", "titles": [{ "text": "amCharts Box Plot Example", "size": 15 }], "graphs": [{ "type": "candlestick", "balloonText": "High: [[high]]\\n Open: [[open]]\\n Mid: [[mid]]\\n Close: [[close]]\\nLow: [[low]]", "highField": "high", "balloonFunction": function(graphDataItem) { var dataItem = graphDataItem.dataContext; return "High: " + dataItem.high + "<br>Open: " + dataItem.open + "<br>Mid: " + dataItem.mid + "<br>Close: " + dataItem.close + "<br>Low: " + dataItem.low }, //"dateFormat": "HH:NN:SS", //does not work with all fields "openField": "open", "closeField": "close", "valueField": "close", "lowField": "low", "fillColors": "#ffffff", "lineColor": "blue", "lineAlpha": 1, "fillAlphas": 0.9, "columnWidth": 0.4 }, { "type": "column", "columnWidth": 0.2, "valueField": "high", "openField": "high", "lineColor": "blue", "lineThickness": 3, "showBalloon": false, "clustered": false }, { "type": "column", "columnWidth": 0.2, "valueField": "low", "openField": "low", "lineColor": "blue", "lineThickness": 3, "showBalloon": false, "clustered": false }, { "type": "column", "columnWidth": 0.4, "valueField": "mid", "openField": "mid", "lineColor": "orange", "lineThickness": 3, "showBalloon": false, "clustered": false }], "chartCursor": { "valueLineEnabled": true, "valueLineBalloonEnabled": true }, "categoryField": "exp", "categoryAxis": { "title": "Experiment No.", "gridPosition": "start", "tickPosition": "start", "tickLength": 10, "axisAlpha": 0.7, "gridAlpha": 0 }, "dataDateFormat": "HH:NN:SS", "dataProvider": [{ "exp": 1, "high": "07:54:00", "open": "07:45:00", "mid": "05:23:49", "close": "04:48:37", "low": "03:44:57", "interimSLA": "12:30:00", "targetedSLA": "08:00:00", }, { "exp": 2, "high": "09:54:00", "open": "08:10:00", "mid": "05:23:49", "close": "04:48:37", "low": "03:44:57", "interimSLA": "12:30:00", "targetedSLA": "08:00:00", }, { "exp": 3, "high": "17:54:00", "open": "15:20:00", "mid": "14:23:49", "close": "12:48:37", "low": "11:44:57", "interimSLA": "12:30:00", "targetedSLA": "08:00:00", }, { "exp": 4, "high": "11:54:00", "open": "08:10:00", "mid": "05:23:49", "close": "04:48:37", "low": "02:44:57", "interimSLA": "12:30:00", "targetedSLA": "08:00:00", }, { "exp": 5, "high": "15:54:00", "open": "12:50:00", "mid": "05:23:49", "close": "04:48:37", "low": "03:44:57", "interimSLA": "12:30:00", "targetedSLA": "08:00:00", }], "valueAxes": [{ "id": "v1", "position": "left", "title": "Time of the Day", "type": "date", // "minimumDate": minDateStr, // "maximumDate": maxDateStr, "markPeriodChange": false, "autoGridCount": false, "gridCount": 7, "minPeriod": "ss" } ], }); 
 html, body { width: 100%; height: 100%; margin: 0px; } #chartdiv { width: 100%; height: 100%; } 
 <script src="//www.amcharts.com/lib/3/amcharts.js"></script> <script src="//www.amcharts.com/lib/3/serial.js"></script> <script src="//www.amcharts.com/lib/3/themes/light.js"></script> <div id="chartdiv"></div> 

转载请注明来自askonline.tech,本文标题:javascript - Amcharts Candle-Stick气球文本以错误的格式显示时间戳


 Top