0
productionSeries = new StackedAreaSeries();
.
.
.
foreach (IEnergyConverter conv in model.GetProducer())
            {
                    SeriesDefinition ser = new SeriesDefinition //creating a new seriesdefinition
                    {
                        Title = conv.Name,
                        IndependentValuePath = "X_Value",
                        DependentValuePath = "Y_Value"
                    };
                productionSeries.SeriesDefinitions.Add(ser); //Add to the StackedAreaSeries
                producerSources.Add(new ObservableCollection<Datapoint>()); //producerSources holds the Data that is updated during execution
                ser.ItemsSource = producerSources.Last(); // Data Binding
            }
.
.
.
View.chart.Series.Add(productionSeries);

This is what i got so far. I am adding 5 SeriesDefinitions to "productionSeries" and they are displayed fine: the first is at the bottom and the following stacked upon. My problem now is that the legend orders the items in the same way as they were added. So the first SeriesDefinitions which is at the bottom in the diagram appears in the legend at the top.. So is it reversed and looks confusing. Is there a way to reverse the legend items or to rearrange them somehow?

I havent found anything about this problem and as far as I know unfortunately there is no documentation of the WinRTXaml Toolkit.

I hope somebody can help me out here or has a tip, thanks.

2 Answers2

0

The code itself is going to be your main documentation, I'm afraid. Two main ways I see for addressing this are - change the order legend items are added (in the control itself - you'll need to change the code of the data visualization controls) or change the order in which they're displayed by replacing the StackPanel that's most likely used there right now with some kind of a ReverseOrderStackPanel implementation. A third way might be to draw your own legend and a fourth one might be to iterate through the visual elements once they're generated and reorder them by manipulating the visual tree.

Ultimately, while the controls do support some customization, I recommend using Win2D to draw your own charts if you want more customized visualization or better performance.

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • 1
    thank you for the quick answer and sorry for the late response... below I post another solution which my coworker found and is pretty simple. – julianhemde Jun 15 '20 at 10:09
0

It is possible to access the automatically added Legenditems in the series ("productionSeries.LegendItems") and rearrange them. In the code below I go through the reversed list of legenditems and build a new list, which I then add to the series again. After deleting the original one of course.

List<LegendItem> legendItemList = new List<LegendItem>();

foreach (LegendItem x in productionSeries.LegendItems.Reverse())
{
    x.Foreground = new SolidColorBrush(Windows.UI.Colors.Black); //optional
    legendItemList.Add(x);
}
productionSeries.LegendItems.Clear();         //Deleting the wrong ordered items
foreach (LegendItem item in legendItemList)
{
    productionSeries.LegendItems.Add(item);   //Adding same items again, in different order
}