jQuery UI Widgets Forums Chart Pie chart Label

This topic contains 1 reply, has 2 voices, and was last updated by  Martin 3 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Pie chart Label #120419

    nico77
    Participant

    Good evening,
    I’m trying to customize label text in pie chart. I followed the example on example. In the example the formatfunction is used with a json var referring to itemIndex and field name, below the code

    formatFunction: function(value, itemIndex) {
           return dataStatCounter[itemIndex].Month;
     },
    

    where dataStatCounter is the Json var. In my project the json data are returned from php file, so if I refer to source or datadapter in the code i get in my label the follow error: Cannot read property ‘STATUS’ of undefined. STATUS is the field name.
    below a part of my code.

    
    var tortaGiornaliera =
    {
        datatype: "json",
        datafields: [
            { name: 'STATUS' },
            { name: 'PERC' }
        ],
        url: "tortaGiornalieraJson.php?giorno=" +  "<?php echo($giorno); ?>"
    };
    
    var dataAdapter = new $.jqx.dataAdapter(tortaGiornaliera,{ async: true, autoBind: true, loadError: function (xhr, status, error) { alert('Error loading "' + DataSource.url + '" : ' + error); } });
    var settingsTorta = {
    
        title: "",
        description: '',
        enableAnimations: false,
        showLegend: false,
        showBorderLine: true,
        padding: { left: 5, top: 5, right: 5, bottom: 5 },
        titlePadding: { left: 0, top: 0, right: 0, bottom: 10 },
        source: dataAdapter,
        colorScheme: 'scheme02',
        seriesGroups:
            [
                {
                    type: 'pie',
                    showLabels: true,
                    series:
                        [
                            {
                                dataField: 'PERC',
                                displayText: 'STATUS',
                                labelRadius: 120,
                                initialAngle: 15,
                                radius: 80,
                                centerOffset: 0,
                                formatFunction: function(value, itemIndex) {
                                  return tortaGiornaliera[itemIndex].STATUS;
                                },
                                formatSettings: { sufix: '%', decimalPlaces: 1
                                  },
                              }
                        ]
                }
            ]
    };
    
    $('#tortaGiornaliera').jqxChart(settingsTorta);
    

    The chart is loaded correctly but the labels show the above error.
    Thanks in advance for any suggestions.
    Nicola

    Pie chart Label #120423

    Martin
    Participant

    Hello Nicola,

    When you are using a dataAdapter instead of a plain array as in the example that you have sent you would need to use:

    formatFunction: function(value, itemIndex) {
        return dataAdapter.records[itemIndex].STATUS;
    }

    Best Regards,
    Martin Yotov

    jQWidgets Team
    https://www.jqwidgets.com/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.