gpt4 book ai didi

javascript - 在 dxChart 中自定义工具提示

转载 作者:行者123 更新时间:2023-11-30 09:47:57 27 4
gpt4 key购买 nike

我正在使用 DevExtreme 的 dxchart 做我的第一步。目前我有以下代码:

HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>DevExtreme Chart</title>
<!--FRAMEWOKR-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script src="./lib/globalize.min.js"></script>
<script src="./lib/dx.charts.js"></script>
<!--JS-->
<script type="text/javascript" src="chart.js"></script>
</head>
<body>
<div id="chartContainer" style="width:100%; height: 440px"></div>
</body>
</html>

JS:

$(document).ready(function(){
var dataSource = [
{
argument: '15.06.2016',
puls: 102,
temperatur: 37.6,
weight: 91
},
{
argument: '16.06.2016',
puls: 99,
temperatur: 35.1,
weight: 88
},
{
argument: '17.06.2016',
puls: 87,
temperatur: 38.0,
weight: 87
},
{
argument: '18.06.2016',
puls: 91,
temperatur: 36.3,
weight: 87
},
{
argument: '19.06.2016',
puls: 112,
temperatur: 37.1,
weight: 90
}
];

$("#chartContainer").dxChart({
dataSource: dataSource,
commonSeriesSettings: {
type: "spline",
label: {
visible: false,
connector: {
visible: false
}
},
argumentField: "argument",
axis: "pulsAxe"
},
tooltip: {
enabled: true,
customizeTooltip: function(obj) {
return {
text: obj.seriesName
}
}
},
legend: {
verticalAlignment: "top",
horizontalAlignment: "right"
},
"export": {
enabled: true
},
title: {
text: "Hugo Amacher | 15.08.1977 (M)",
subtitle: {
enabled: true,
text: "Ich bin ein Untertitel..."
}
},
zoomingMode: "all",
series: [
{
name: "Puls",
valueField: "puls"
},
{
name: "Temperatur",
valueField: "temperatur",
axis: "temperaturAxe"
},
{
name: "Gewicht",
valueField: "weight",
axis: "weightAxe"
}
],
valueAxis: [
{
name: "pulsAxe",
title: "Puls",
position: "left",
label: {
customizeText: function(value) {
return value.value + " bpm"
}
}
},
{
name: "temperaturAxe",
title: "Temperatur",
position: "left",
label: {
customizeText: function(value) {
return value.value + " °C"
}
}
},
{
name: "weightAxe",
title: "Gewicht",
position: "left",
label: {
customizeText: function(value) {
return value.value + " kg"
}
}
}
]
});
});

我的结果是这样的:

enter image description here

如您所见,有一个简单的样条图,图表上具有三个不同的 y 轴和该轴的三个不同的值范围。对于每把斧头,我都有一个标签(bpm、°C 和 kg)。我还实现了 dxchart 的工具提示。当我悬停一个点时,工具提示中只有值。我还想在工具提示中动态添加值后的标签。这意味着,当我悬停斧头“Puls”的值时,它应该显示例如:91 bpm。我怎样才能做到这一点。我尝试使用自定义工具提示:http://js.devexpress.com/Documentation/ApiReference/Data_Visualization_Widgets/dxChart/Configuration/tooltip/?version=16_1#customizeTooltip

我有想法,检查 seriesName 并在返回中分配标签,就像这样,但它没有用:

tooltip: {
enabled: true,
customizeTooltip: function(point) {
if (point.seriesName == "Puls") {
return {
text: point.value + " bpm"
}
} else if (point.seriesName == "Gewicht") {
return {
text: point.value + " kg"
}
} else if (point.seriesName == "Temperatur") {
return {
text: point.value + " °C"
}
}
}
},

最佳答案

enter image description here您好,请检查 Plunker https://plnkr.co/edit/6Uoh30bb8qBNWIIbyX0O?p=preview

检查你的图书馆包括

HTML

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/globalize/0.1.1/globalize.min.js"></script>
<script type="text/javascript" src="https://cdn3.devexpress.com/jslib/15.2.5/js/dx.chartjs.js"></script>
<script src="script.js"></script>
</head>

<body>
<div id="chartContainer" style="width:100%; height: 440px"></div>
<!-- Put your html here! -->
</body>

</html>

JS

// Add your javascript here
$(function(){
var dataSource = [
{
argument: '15.06.2016',
puls: 102,
temperatur: 37.6,
weight: 91
},
{
argument: '16.06.2016',
puls: 99,
temperatur: 35.1,
weight: 88
},
{
argument: '17.06.2016',
puls: 87,
temperatur: 38.0,
weight: 87
},
{
argument: '18.06.2016',
puls: 91,
temperatur: 36.3,
weight: 87
},
{
argument: '19.06.2016',
puls: 112,
temperatur: 37.1,
weight: 90
}
];

$("#chartContainer").dxChart({
dataSource: dataSource,
commonSeriesSettings: {
type: "spline",
label: {
visible: false,
connector: {
visible: false
}
},
argumentField: "argument",
axis: "pulsAxe"
},
tooltip: {
enabled: true,
customizeTooltip: function(obj) {
console.log(obj.seriesName)
if (obj.seriesName == "Puls") {
return {
text: obj.value + " bpm"
}
} else if (obj.seriesName == "Gewicht") {
return {
text: obj.value + " kg"
}
} else if (obj.seriesName == "Temperatur") {
return {
text: obj.value + " °C"
}
}

// return {
// text: obj.seriesName
// }
}
},
legend: {
verticalAlignment: "top",
horizontalAlignment: "right"
},
"export": {
enabled: true
},
title: {
text: "Hugo Amacher | 15.08.1977 (M)",
subtitle: {
enabled: true,
text: "Ich bin ein Untertitel..."
}
},
zoomingMode: "all",
series: [
{
name: "Puls",
valueField: "puls"
},
{
name: "Temperatur",
valueField: "temperatur",
axis: "temperaturAxe"
},
{
name: "Gewicht",
valueField: "weight",
axis: "weightAxe"
}
],
valueAxis: [
{
name: "pulsAxe",
title: "Puls",
position: "left",
label: {
customizeText: function(value) {
return value.value + " bpm"
}
}
},
{
name: "temperaturAxe",
title: "Temperatur",
position: "left",
label: {
customizeText: function(value) {
return value.value + " °C"
}
}
},
{
name: "weightAxe",
title: "Gewicht",
position: "left",
label: {
customizeText: function(value) {
return value.value + " kg"
}
}
}
]
});
});

关于javascript - 在 dxChart 中自定义工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38007034/

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