我设法创建了一个包含多个数据集的Chart.js折线图。但是,如何修改工具提示,以便当我将鼠标悬停在某个点上时,会显示数据集的标签以及£符号?
例如,从我的屏幕截图中,我想显示:
git reset --hard origin/master
javascript代码:
31/10/2015
(label) - £100.00
(label) - £240.00
(label) - £150.00
更新:
我设法显示带有以下更新的£符号:
<script type="text/javascript">
gon.balances.reverse();
var balancesSortByAccId = gon.balancesSortByAccId;
var data = {
labels: [],
datasets: []
};
//loop through all accounts to generate datasets
for(var account in gon.balancesSortByAccId){
var balances = [];
var dates = [];
var accountData = gon.balancesSortByAccId[account];
for (var i in accountData) {
balances.push(parseFloat(accountData[i].balance).toFixed(2));
dates.push(convertDate(accountData[i].date));
for (var date in dates)
if (data.labels.indexOf(dates[date]) <= -1)
data.labels.push(dates[date]);
}
var colour = getRandomColor();
var chartjs_balances = {
label: account,
fillColor: "rgba(220,220,220,0.2)",
strokeColor: colour,
pointColor: colour,
pointStrokeColor: colour,
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: balances
};
data.datasets.push(chartjs_balances);
}
var options = {
responsive: true,
};
//draw graph
var ctx = document.getElementById("history_canvas").getContext("2d");
var myLineChart = new Chart(ctx).Line(data, options);
//convert date to dd/mm/yyyy format
function convertDate(inputFormat) {
function pad(s) { return (s < 10) ? '0' + s : s; }
var d = new Date(inputFormat);
return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('/');
}
//return random color for each dataset
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
但是,输出结果如下,并不完全是我想要的,因为它显示日期而不是帐户标签:
var options = {
responsive: true,
multiTooltipTemplate: "<%%=label%>: £<%%= value %>"
};
答案 0 :(得分:1)
我设法通过以下方式解决了这个问题:
var options = {
responsive: true,
multiTooltipTemplate: "<%%=datasetLabel%>: £<%%= value %>",
};