Highcharts将小数的数字格式设置为逗号

Highcharts将小数的数字格式设置为逗号,highcharts,Highcharts,我有一个人口金字塔的数据集,我使用高图,但我有一些问题与决策者。Highcharts接受分隔符为“”,但数据集有“”,因此在逗号之后,它将被视为一个新值。我的意思是,对于“5,12”,它不接受5.12,它接受5,12,分别是两个值。我怎样才能解决这个问题?(我无法将“,”更改为“,”,因为它需要从数据库中获取数据) {数据集%中的项的%1} //年龄类别 变量类别=[ '0-4', '5-9', '10-14', '15-19', '20-24', '25-29', '30-34', '35-

我有一个人口金字塔的数据集,我使用高图,但我有一些问题与决策者。Highcharts接受分隔符为“”,但数据集有“”,因此在逗号之后,它将被视为一个新值。我的意思是,对于“5,12”,它不接受5.12,它接受5,12,分别是两个值。我怎样才能解决这个问题?(我无法将“,”更改为“,”,因为它需要从数据库中获取数据)


{数据集%中的项的%1}
//年龄类别
变量类别=[
'0-4', '5-9', '10-14', '15-19',
'20-24', '25-29', '30-34', '35-39', '40-44',
'45-49', '50-54', '55-59', '60-64', '65-69',
'70-74', '75-79', '80-84', '85-89', '90+'
];
Highcharts.chart('容器'{
图表:{
类型:'bar'
},
标题:{
文字:“人口金字塔”
},
副标题:{
文本:“来源:”
},
xAxis:[{
类别:类别,,
相反:错,
标签:{
步骤:1
}
},{//右侧的镜像轴
相反:是的,
相反:错,
类别:类别,,
链接到:0,
标签:{
步骤:1
}
}],
亚克斯:{
标题:{
文本:空
},
标签:{
格式化程序:函数(){
返回Math.abs(this.value)+'%';
}
}
},
打印选项:{
系列:{
堆叠:“正常”
}
},
工具提示:{
格式化程序:函数(){
返回“+this.series.name+”,age“+this.point.category+”
+ “人口:”+Highcharts.numberFormat(Math.abs(this.point.y)), } }, 系列:[{ 名字:“男人”, 数据:[ -{{item.men_population_0_4_percentage}, -{{item.men_population_5_9_percentage}, -{{item.men_population_10_14_percentage}, -{{item.men_population_15_19_percentage}, -{{item.men_population_20_24_percentage}, -{{item.men_population_25_29_percentage}, -{{item.men_population_30_34_percentage}, -{{item.men_population_35_39_percentage}, -{{item.men_population_40_44_percentage}, -{{item.men_population_45_49_percentage}, -{{item.men_population_50_54_percentage}, -{{item.men_population_55_59_percentage}, -{{item.men_population_60_64_percentage}, -{{item.men_population_65_69_percentage}, -{{item.men_population_70_74_percentage}, -{{item.men_population_75_79_percentage}, -{{item.men_population_80_84_percentage}, -{{item.men_population_85_89_percentage}, -{{item.men_人口{u 90以上}, ] }, { 姓名:'妇女', 数据:[ {{item.women_population_0_4_percentage}, {{item.women_population_5_9_percentage}, {{item.women_population_10_14_percentage}, {{item.women_population_15_19_percentage}, {{item.women_population_20_24_percentage}, {{item.women_population_25_29_percentage}, {{item.women_population_30_34_percentage}, {{item.women_population_35_39_percentage}, {{item.women_population_40_44_percentage}, {{item.women_population_45_49_percentage}, {{item.women_population_50_54_percentage}, {{item.women_population_55_59_percentage}, {{item.women_population_60_64_percentage}, {{item.women_population_65_69_percentage}, {{item.women_population_70_74_percentage}, {{item.women_population_75_79_percentage}, {{item.women_population_80_84_percentage}, {{item.women_population_85_89_percentage}, {{item.women_population_90_over_percentage}, ] }] }); {%endfor%}
当逗号设置为小数分隔符时,值之间的逗号将出现错误,例如“{item.women\u population\u 0\u 4\u percentage}”,
{{item.women\u population\u 5\u 9\u percentage},“…”那么我该如何解决这个问题呢?

您可以通过JS将逗号更改为点。例如:

var data = ['5,12', '10,4'];

data.forEach(function(el, i) {
    data[i] = parseFloat(el.replace(/,/g, '.'))
});

Highcharts.chart('container', {
    series: [{
        data: data
    }]
});


现场演示:

您可以通过JS将逗号更改为点。例如:

var data = ['5,12', '10,4'];

data.forEach(function(el, i) {
    data[i] = parseFloat(el.replace(/,/g, '.'))
});

Highcharts.chart('container', {
    series: [{
        data: data
    }]
});

现场演示:

用于数据库

    var data_men = [
                  '-{{ item.men_population_0_4_percentage }}',
                  '-{{ item.men_population_5_9_percentage }}',
                  .
                  .
                  .
                  ];
    var data_women = [
                  '{{ item.women_population_0_4_percentage }}',
                  '{{ item.women_population_5_9_percentage }}',
                  .
                  .
                  .
                  ];

    data_men.forEach(function(el, i) {
        data_men[i] = parseFloat(el.replace(/,/g, '.'))
    });

    data_women.forEach(function(el, i) {
        data_women[i] = parseFloat(el.replace(/,/g, '.'))
    });
    .
    .
    .
    series: [{
                //color: 'blue',
                name: 'Male',
                data: data_men
              }, {
                color: 'pink',
                name: 'Female',
                data: data_women
              }]
    .
    .
    .
感谢您提供数据库

    var data_men = [
                  '-{{ item.men_population_0_4_percentage }}',
                  '-{{ item.men_population_5_9_percentage }}',
                  .
                  .
                  .
                  ];
    var data_women = [
                  '{{ item.women_population_0_4_percentage }}',
                  '{{ item.women_population_5_9_percentage }}',
                  .
                  .
                  .
                  ];

    data_men.forEach(function(el, i) {
        data_men[i] = parseFloat(el.replace(/,/g, '.'))
    });

    data_women.forEach(function(el, i) {
        data_women[i] = parseFloat(el.replace(/,/g, '.'))
    });
    .
    .
    .
    series: [{
                //color: 'blue',
                name: 'Male',
                data: data_men
              }, {
                color: 'pink',
                name: 'Female',
                data: data_women
              }]
    .
    .
    .
多谢各位