jQuery UI Widgets Forums Chart Pie chart flickers on update

This topic contains 1 reply, has 2 voices, and was last updated by  Dimitar 8 years, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Pie chart flickers on update #80862

    roamingstar
    Participant

    Is there a way i can avoid pie chart to flciker when it updates on a setinterval i am using refresh chart feature after updating data set with dataadapter

    Pie chart flickers on update #80878

    Dimitar
    Participant

    Hello roamingstar,

    If you use the method update there will be no flickering. Please try the following example:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdraw.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxchart.core.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var data = [{ name: 'a', value: 10 }, { name: 'b', value: 3 }, { name: 'c', value: 7}];
    
                // prepare chart data as an array
                var source =
                {
                    datatype: "json",
                    datafields: [
                        { name: 'name' },
                        { name: 'value' }
                    ],
                    localdata: data
                };
    
                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",
                    description: "(source: wikipedia.org)",
                    enableAnimations: true,
                    showLegend: false,
                    showBorderLine: true,
                    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: 'value',
                                            displayText: 'name',
                                            labelRadius: 120,
                                            initialAngle: 15,
                                            radius: 170,
                                            centerOffset: 0
                                        }
                                    ]
                            }
                        ]
                };
    
                // setup the chart
                $('#chartContainer').jqxChart(settings);
    
                setInterval(function () {
                    var newData = [{ name: 'a', value: Math.random() * 10 }, { name: 'b', value: Math.random() * 10 }, { name: 'c', value: Math.random() * 10}]
                    source.localdata = newData;
                    dataAdapter.dataBind();
                    $('#chartContainer').jqxChart('update');
                }, 1000);
            });
        </script>
    </head>
    <body class='default'>
        <div id='chartContainer' style="width: 850px; height: 500px;">
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

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

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

You must be logged in to reply to this topic.