javascript - consoleTVs charts 6.x add function in options
问题描述
I,m Laravel 5.8 and trying to build a chart with custom tooltips using Laravel Chart ( ConsoleTVs/Charts ) https://charts.erik.cat/ , I need to use functions inside the options but couldn't find the proper why to do so:
if i will use normal chartjs my code will be like so :
var ctx = document.getElementById("barChart").getContext('2d');
var Total = eval(Amount.join('+')).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels:Labels,
datasets: [{
label: "Disbursements Total $" + Total,
backgroundColor: ["rgba(249, 57, 86, 1)", "rgba(146, 221, 161, 1)", "rgba(146, 186, 221, 1)", "rgba(200, 146, 221, 1)", "rgba(194, 221, 146, 1)", "rgba(221, 146, 146, 1)"],
data: Amount,
borderWidth: 1
}]
},
options: {
responsive: true,
legend: {
display: true,
},
tooltips: {
callbacks: {
label: function(value, context) {
var values = Number(value.yLabel)
return ' $' + values.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,') + " Disbursed of $" + Total + " in " + context.labels[value.index];;
}
}
},
plugins: {
datalabels: {
anchor: 'end',
align: 'top',
formatter: function(value, context) {
return '$' + value.replace(/\d(?=(\d{3})+\.)/g, '$&,');
},
display: function (context) {
return context.chart.isDatasetVisible(context.datasetIndex);
},
font: {
weight: 'bold'
}
}
},
scales: {
yAxes: [{
ticks: {
beginAtZero:true,
callback: function(value) {
return '$' + value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
}
}]
}
}
});
But when using Laravel Charts
$chart = new TestChart;
$chart->labels(['place1', 'place2', 'place3']);
$chart->dataset('Disbursements Total $', 'bar', [1, 2, 3])
->backgroundcolor(collect(["rgba(249, 57, 86, 1)", "rgba(146, 221, 161, 1)", "rgba(146, 186, 221, 1)", "rgba(200, 146, 221, 1)", "rgba(194, 221, 146, 1)", "rgba(221, 146, 146, 1)"]))
->options([
'tooltip' => [
'show' => true,
'callbacks' => [
'label' => function(value, context) {
?
}
]
// or false, depending on what you want.
]
]);
How can i add my function in a php array or better if there is a function in Laravel chart that can accept a json so i can copy my options as it is?
Please can someone help me :)
解决方案
推荐阅读
- css - S3 CSS 资产未加载,但之前已加载。为什么会停下来?
- unix - 用于从 bzip 文件中的一个文件中搜索内容的 unix 命令
- angular - PrimeNG 控件未显示无效
- android - 使用 chaquopy 在 android 应用程序中运行 python 会产生致命错误
- r - Subset rows that contain string in any column
- vue.js - Vuetify 单选按钮未显示为选中状态
- java - Java 扫描仪定界符检测到 ';' 但不是'\n'
- javascript - Jasmine Data Provider 不工作(jasmine_data_provider_1.using 不是函数)
- java - 将数据发送到队列并在同一函数中侦听数据
- firebase - 设置用户属性后如何获取更新的远程配置值