gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 00:54:53 25 4
gpt4 key购买 nike

我正在使用 amcharts 来绘制蜡烛图。图表渲染良好,但气球以其他格式显示时间戳。

enter image description here

enter image description here

实际上,这些值采用“HH:MM:SS”格式,但气球以某种不同的格式显示。因为它仅在“Mid:”(即 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]] 之外的值[[值]]。在这种情况下,您唯一的选择是使用 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>

关于javascript - Amcharts Candle-Stick 气球文本以错误格式显示时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56670907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com