简体   繁体   English

在双轴高图表中将y轴值转换为百万

[英]Convert the y-axis values to Millions in dual axis high charts

I am using dual-axis highcharts. 我正在使用双轴高图。 In the y-axis the values are too big to read. 在y轴上,值太大而无法读取。 I wold like to convert them to shortcuts like 1K for 1000 and 1.0L for 100000 and 1.0M for 1000000 and 35.8M for 35869982 and 3.5M for 3550977. 我希望将它们转换为1000K的1K和100000的1.0L以及1000000的1.0M和35869982的35.8M以及3550977的3.5M的快捷方式。

This is my FIDDLE 这是我的FIDDLE

 $(function () {
$('#container').highcharts({
    chart: {
        zoomType: 'xy'
    },
    title: {
        text: 'Average Monthly Temperature and Rainfall in Tokyo'
    },
    subtitle: {
        text: 'Source: WorldClimate.com'
    },
    xAxis: [{
        categories: ['MAR-2014', 'APR-2014', 'MAY-2014', 'JUN-2014',
            'JUL-2014', 'AUG-2014', 'SEP-2014', 'OCT-2014', 'NOV-2014', 'DEC-2014'],
        crosshair: true
    }],
    yAxis: [{ // Primary yAxis
        labels: {
            format: '{value}',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        },
        title: {
            text: 'VOLUME',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        }
    }, { // Secondary yAxis
        title: {
            text: 'REVENUE',
            style: {
                color: Highcharts.getOptions().colors[0]
            }
        },
        labels: {
            format: '{value}',
            style: {
                color: Highcharts.getOptions().colors[0]
            }
        },
        opposite: true
    }],
    tooltip: {
        shared: true
    },
    legend: {
        layout: 'vertical',
        align: 'left',
        x: 120,
        verticalAlign: 'top',
        y: 100,
        floating: true,
        backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
    },
    series: [{
        name: 'Revenue',
        type: 'column',
        yAxis: 1,
        data: [35869982, 26090976, 26595718, 33914250, 25999278, 36579864, 35843674, 28008920, 27718356, 29014230],
        tooltip: {
            valueSuffix: ' '
        }

    }, {
        name: 'volume',
        type: 'spline',
        data: [3379865, 2373769, 2401815, 3222316, 2459713, 5864469, 5139453, 3341922, 3229963, 3550977],
        tooltip: {
            valueSuffix: ''
        }
      }]
    });
   });

Here I have rounded up where I want to make changes in the below figure 在这里,我想要在下图中进行更改

在此输入图像描述

You need to make a use of formatter: 你需要使用formatter:

formatter: function(){
              return this.value/1000000 + "M";
            }

Fiddle 小提琴

To utilize the built in "shortening" functionality you can just remove your yAxis.label.format . 要利用内置的“缩短”功能,您只需删除yAxis.label.format You have currently set it to {value} , which is the default, but manually setting it seems to prevent the metric prefixes from being applied. 您当前已将其设置为{value} ,这是默认值,但手动设置它似乎会阻止应用度量标准前缀。

Look at this JSFiddle example , where all I've changed is removing the following line from both of your y-axis labels: 看看这个JSFiddle示例 ,我所做的就是从两个y轴标签中删除以下行:

format: '{value}'

With this automatic shortening the following metric prefixes may be applied: 通过此自动缩短,可以应用以下度量标准前缀

[ "k" , "M" , "G" , "T" , "P" , "E"]

You can set your own values with the lang.numericSymbols option ( API ). 您可以使用lang.numericSymbols选项( API )设置自己的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM