Fixed sorting of the legend and grouping

now it sorts alphabetically or by the order the setting.legend part of
the chart.json has