Rotan075
Rotan075

Reputation: 2615

Use comma values as datapoints within a PieChart

I am using HighCharts and I want to be able to use comma values as data input. The standard approach of Highcharts is to create a Piechart by using for example the following datapoints:

data: [{
            name: 'Microsoft Internet Explorer',
            y: 0.1
        }, {
            name: 'Chrome',
            y: 0.5
        }]

Via an external source I retrieve my data (dutch annotation instead of US-us) as follows:

data: [{
            name: 'Microsoft Internet Explorer',
            y: 0,1
        }, {
            name: 'Chrome',
            y: 0,5
        }]

This wil not work because Highcharts can not handle this because it interperates the y points as two values.

Does anyone knows a solution how I could use comma as data y input points perhaps by using a formatter?

For a demo see this JSFIDDLE

Upvotes: 1

Views: 226

Answers (2)

Ferhat BAŞ
Ferhat BAŞ

Reputation: 797

Hi I am not sure what is your aim if you would like see on tooltip than you set below code before initialize chart you can find Internationalization

Highcharts.setOptions({
lang: {
    decimalPoint: ','
}
});

Edited for working code

Highcharts.setOptions({
lang: {
    decimalPoint: ','
}
});
Highcharts.chart('container', {
chart: {
    plotBackgroundColor: null,
    plotBorderWidth: null,
    plotShadow: false,
    type: 'pie'
},
title: {
    text: 'Browser market shares January, 2015 to May, 2015'
},
series: [{
    name: 'Brands',        
    data: [{
        name: 'Microsoft Internet Explorer',
        y: parseFloat(('1,5').replace(/\,/g, '.'))
    }, {
        name: 'Chrome',
        y: parseFloat(('4').replace(/\,/g, '.'))
    }]
}]
});

Upvotes: 1

Wouter Bouwman
Wouter Bouwman

Reputation: 1013

You could replace the comma value with a dot value by using replace and parsing it into a float:

y: parseFloat(('1,5').replace(/\,/g, '.'))

http://jsfiddle.net/y30ktm2a/

Upvotes: 1

Related Questions