Automatic Sorting Refresh After Chart Data Update

  • Last update:December 11, 2025
  • Overview

    Version

    FineReport Version

    11.0

    Problem

    If you use the chart.sortChart(sortType) API to sort chart data, the chart will not automatically refresh the sorting when the data source updates, as shown in the following figure.

    Solution

    You can enable Background Detection in Special Effect and add a Loading Start event to the chart.

    Example

    Designing the Report

    1. Create a general report, and create a dataset with the SQL query statement: SELECT * FROM Sales_Volume_new limit ${int(rand()*5+4)}

    Inserting a Chart

    Merge the required cells, click the icon on the upper toolbar, select Column Chart, and click OK, as shown in the following figure.

    Setting Chart Data

    Select the column chart, choose Cell Element > Data, set Data Source to Dataset Data, Dataset to ds1, Category to Salesperson, Series Name to Field Name, Field Name and Series to Sales_Volume, and Summary to Sum, as shown in the following figure.

    Setting the Chart Special Effect

    Select the column chart, choose Cell Element > Special Effect, set Animation Effect and Background Detection to On, and set Time Interval to 2, as shown in the following figure.

    Adding a Loading Start Event

    Choose Template > Web Attribute > Data Entry Setting, select Set for This Template Separately in Following Settings, and add a Loading Start event in Event Setting, as shown in the following figure.

    The JavaScript code is as follows:

    iconNote: 

    1. As charts refresh frequently in this solution, interaction anomalies may occur. For example, the time interval between each refresh varies slightly in the effect preview figure.

    2. To achieve the same effect in an FRM report, you can add an After Initialization event in the report block using the same JavaScript code.

    setTimeout(function() {
                            var chart = FR.Chart.WebUtils.getChart("A1").vanCharts.charts[0]; 
                            chart.sortChart();
                            function sortChartAfterRefresh(chart, sortType) {
                                        chart._update = chart._update || chart.update;
                                        chart.update = function() {
                                                    chart._update.call(chart);
                                                    chart.sortChart(sortType);
                                                    chart.sortChart(sortType);
                                        }
                            }
                            sortChartAfterRefresh(chart, 1);

                },
                1000)


    Effect Display

    Save the report, and click Pagination Preview. The following figure shows the preview effect.

    iconNote:
    The function is not supported on mobile terminals.

    Template Download

    For details, you can download the template: Automatic Sorting Refresh After Data Update.cpt 

    Attachment List


    Theme: Chart
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy