views:

136

answers:

1

So I am using this jquery plugin to create a nice pie chart on my website. The problem is that the plugin is rounding the values very oddly.

This is the table I give to it:

        <table id="pieChart">
            <caption>Priebežné výsledky ankety</caption>

            <thead>
                <tr>
                    <th></th>
                    <th>Túto formu vzdelávania využívame už dlhšiu dobu.</th>
                    <th>Som zástancom štandardnej prezenčnej formy vzdelávania.</th>
                    <th>Plánujeme v najbližšom období zaviesť takúto efektívnu formu vzdelávania.</th>
                    <th>Doteraz som nepočul o takejto forme vzdelávania, ale zaujalo ma to.</th>

                </tr>
            </thead>
                <tbody>
                <tr>
                    <th>100</th>

                    <td>7.7</td>
                    <td>30.8</td>

                    <td>53.8</td>
                    <td>7.7</td>

                </tr>
            </tbody>
        </table>

But the values that appear in the pie chart are as follows:

7.2 (should be 7.7)
30.9 (should be 30.8)
54.6 (should be 53.8)
7.2 (should be 7.7)

What is a reason behind this? I guess this could be some weird rounding at the side of Google Charts API?

UPDATE:

The jquery plugin generates iframe like this:

<iframe scrolling="no" height="300" frameborder="0" width="720" name="Chart_Frame_22518" id="Chart_Frame_22518" marginheight="0" marginwidth="0"></iframe>
A: 

I changed this in the jQuery plugin:

rows.each(function(index){
        $(this).find('td').each(function(index2){
            data.setCell(index2, index+1, parseInt($(this).text()));
        });
});

To this:

rows.each(function(index){
        $(this).find('td').each(function(index2){
            data.setCell(index2, index+1, parseFloat($(this).text()));
        });
});

Basically I switched parseInt() for parseFloat().

And it seems to work :)

Richard Knop