チャートデータをソートする

  • 作成者:ayuan0625
  • 編集回数:13次
  • 最終更新:ayuan0625 于 2020-12-14
  • I. Overview

    1.1 Problem

    If the chart data is fetched through sql statement, it can be sorted directly in sql. But if you use other methods to get the data, and you want to sort the chart by numerical value, how to do that?

    11.gif


    1.2 Solution

    After obtaining the chart object to be sorted through vanchart.sortChart(sortType) , you can set the chart sorting method. 

    Note:

    • Parameter sortType defines the sort type, and is optional. Values are 1 or -1. Where it is 1 means ascending order, -1 means descending order.

    • If you do not write sortType parameters, the chart will be switched to the opposite sort sequence based on the current sequence.

    • This method does not support mobile terminals.    

    II. Example

    2.1 Report design

    Add a chart and bind the data source to it.

    image.png


    2.2 Add click event

    Place a button above the chart and add a click event to it.

    image (1).png

    Add following JS; For example, sort in ascending order:

    var chart = FR.Chart.WebUtils.getChart("chart0").vanCharts.charts[0]; //Get the first chart tab of the chart0 component, which is the default chart
    chart.sortChart(1); //Set sorting type


    2.3 Preview effect

    Click save and preview. You can see that the chart series values are sorted in ascending order after clicking the button:

    11.gif

    III. Download template

    Attachment List


    Theme: FineReport カスタム開発
    • いいね
    • 良くない
    • 閲覧しただけ