Forum Discussion

zohebakber's avatar
zohebakber
Cloud Apps
11-23-2023

Line chart - Custom sort break by values

Hi Team,

Can anyone help me share the script to custom sort the break by values in the line chart.

I tried the same approach for the line chart as for pivot rows:
https://community.sisense.com/t5/knowledge/pivot2-table-row-custom-sort/ta-p/9096#:~:text=In%20a%20custom%20column%2C%20add,Another%20Category

However, this approach is not working.

Please share your thoughts.

Thanks

cc: harikm007 Ido_QBeeQ Oleg 

2 Replies

Replies have been turned off for this discussion
  • Hi zohebakber ,

    You can use the widget snippet below to change the order of the lines / legend in the break by:

     

    let order = ['Greece', 'Alaska']
    
    widget.on('processresult', (w, args) => {
      const unlistedItems = args.result.series.filter((i) => { return !order.includes(i.name) })
      order = [...order, ...unlistedItems]
      args.result.series.sort((a, b) => { 
    	  return order.indexOf(b.name) - order.indexOf(a.name) 
      })
    })
    

     

     What we are doing here is:

    • defining an order for the items we're interested in,
    • putting any items we didn't declare at the end of the order list and then,
    • ordering the lines based on our new order list.

    Let me know if this works for you.

    Thanks,

    Daniel

    RAPID BI

    [email protected]

    RAPID BI - Sisense Professional Services | Implementations | Custom Add-ons