0

I have a chart with sample data: [1462218035, 2079623792, 2146097338, 2169087177] and in y axis label i convert it to human readable bytes:

yAxis: {
    labels: {
    useHTML: true,
    formatter: function () {
        return bytesToReadable(this.value, true);
    },
  },
}

bytesToReadable converts bytes to human readable data: 1,36 GB - 1,94 GB - 2 GB and it shows y labels like: 953,67 MB - 1,86 GB - 2,79 GB those are 2,000,000,000 - 4,000,000,000 - 6,000,000,000 converted by bytesToReadable. What i want is 2,000,000,000 - 4,000,000,000 - 6,000,000,000 generated by highcharts to be multiply of 1024 to be correct numbers after convert like 100 MB - 1GB - 4GB.

Fateme Fazli
  • 11,582
  • 2
  • 31
  • 48
  • can you try to clarify what you want? For example given data: `2,000,000,000 - 4,000,000,000 - 6,000,000,000` what is given/displayed by highcharts vs what you want to see? – depperm Feb 03 '20 at 12:07
  • @depperm It displays ```953,67 MB - 1,86 GB - 2,79 GB``` in labels, i want ```100 MB - 1GB - 4GB``` – Fateme Fazli Feb 03 '20 at 12:15
  • how do you go from 953,67MB to 100MB? Do you mean 1 GB? why does 1.86GB go to 1GB but 2.76GB goes to 4GB? that is what I don't understand – depperm Feb 03 '20 at 14:17
  • @depperm No it's just a sample, I just want that numbers to be rounded numbers without decimals. – Fateme Fazli Feb 03 '20 at 17:33
  • so show us the code of bytesToReadable and see [this answer](https://stackoverflow.com/a/14919494/3462319) – depperm Feb 03 '20 at 17:36
  • @depperm My bytesToReadable works correctly i dont want to round numbers in this function because decimals are important for me, I want yAxis lables defualt to be multiply of 1024 that when i convert by bytesToReadable it gives me correct numbers. – Fateme Fazli Feb 03 '20 at 17:46
  • Hi @Fateme Fazli, Please try to use `tickInterval` property. Example: http://jsfiddle.net/BlackLabel/6m4e8x0y/4806/ – ppotaczek Feb 03 '20 at 19:09
  • @ppotaczek It helped me so much thank you. – Fateme Fazli Feb 05 '20 at 14:50

1 Answers1

1

Use tickInterval property:

yAxis: {
  tickInterval: 1024
}

Live demo: http://jsfiddle.net/BlackLabel/6m4e8x0y/4806/

API Reference: https://api.highcharts.com/gantt/yAxis.tickInterval

ppotaczek
  • 36,341
  • 2
  • 14
  • 24