I am trying to format my dataTable with thousands or with (,). but I have not been able to, I have seen forums and I have not been able to, I will share my code with you. The variable Venta is theq
I want to format data: sale both in the graph and in the dataTable.
<div class="">
<figure class="highcharts-figure">
<div id="container"></div>
</figure>
</div>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script>
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: 'Ventas Mensuales',
align: 'left',
style: {
fontSize: '16px'
}
},
xAxis: {
categories: mes, // What returns mes is ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre','Octubre', 'Noviembre', 'Diciembre'];
crosshair: true,
accessibility: {
description: 'Meses'
}
},
yAxis: {
min: 0,
title: {
text: 'Ventas Mensuales'
}
},
tooltip: {
valueSuffix: ' (COP)'
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0,
dataLabels: {
enabled: true,
formatter: function() {
return '$' + Highcharts.numberFormat(this.y, 0);
}
}
}
},
series: [{
name: 'Ventas',
data: venta // What returns is ['1356940858.000000', '1945419126.000000', '934706589.000000', '1803607453.000000', '78415027.000000']
// data: valoresY
}],
data: {
table: 'datatable'
},
exporting: {
tableCaption: "Tabla de Ventas Mensualesss"
}
});
</script>```
Esperaba el valor del dataTable export formateado en miles
2
Answers
If you want the chart values to have thousands separator you can set them by setting global options:
If you want to format label, you can pass custom formatting after the value so in your case:
Put all together example:
You could extend the
export-data
module to do formatting on the values that are presented in the data table, for example like this (see JSFiddle demonstration):The caveat here is that it breaks sorting by that column, because it no longer compares numbers, but rather it compares strings. The simple approach to this is to disable sorting with
allowTableSorting
(API). A complicated variation is to only disable sorting by the series values, which is another extension, for example like this (included in JSFiddle above):