jQWidgets Forums

jQuery UI Widgets Forums Chart Maximum Labels for Pie Chart

This topic contains 4 replies, has 2 voices, and was last updated by  Dimitar 12 years, 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Maximum Labels for Pie Chart #11556

    I have a pie chart that has 20+ sections/slices. The slices range from 50%, 20%, 10%, 9% then a bunch down to 1% How can I limit the number of labels shown… say that top 5. The problem is… the bottom 10 sections are so small the labels start overlap. Any suggestions.

    Maximum Labels for Pie Chart #11575

    Dimitar
    Participant

    Hello brewsterjones,

    To show labels only on some slices, you should use the formatFunction property of series. In the following example, labels to slices with a value less than 10% are not shown.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html lang="en">
    <head>
    <title id='Description'>jqxChart Pie Series Example</title>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxchart.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    // prepare chart data as an array
    var source =
    {
    datatype: "csv",
    datafields: [
    { name: 'Browser' },
    { name: 'Share' }
    ],
    url: '../sampledata/desktop_browsers_share_dec2011.txt'
    };
    var dataAdapter = new $.jqx.dataAdapter(source, { async: false, autoBind: true, loadError: function (xhr, status, error) { alert('Error loading "' + source.url + '" : ' + error); } });
    // prepare jqxChart settings
    var settings = {
    title: "Desktop browsers share in Dec 2011",
    description: "(source: wikipedia.org)",
    enableAnimations: true,
    showLegend: false,
    legendPosition: { left: 520, top: 140, width: 100, height: 100 },
    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: 'Share',
    displayText: 'Browser',
    labelRadius: 100,
    initialAngle: 15,
    radius: 130,
    centerOffset: 0,
    formatSettings: { sufix: '%', decimalPlaces: 1 },
    formatFunction: function (value) {
    if (value >= 10) {
    return value;
    };
    }
    }
    ]
    }
    ]
    };
    // setup the chart
    $('#jqxChart').jqxChart(settings);
    });
    </script>
    </head>
    <body class='default'>
    <div id='host' style="margin: 0 auto; width: 699px; height: 400px;">
    <div id='jqxChart' style="width: 680px; height: 400px; position: relative; left: 0px;
    top: 0px;">
    </div>
    </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Maximum Labels for Pie Chart #11616

    Thanks… but could not get it to work. when i added in the
    formatFunction: function (value) {
    if (value >= 10) {
    return value;
    };

    everything quit showing.

    Maximum Labels for Pie Chart #11617

    Was missing a closing bracket }… but now can’t get the FormatSettings to work properly… giving me a percentage 10 decimals out…

    Maximum Labels for Pie Chart #11690

    Dimitar
    Participant

    Hi brewsterjones,

    Please post a code snippet, so that we may be of help.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.