簡體   English   中英

使用 StackedAreaSeries 反轉圖表中圖例項的順序

[英]Reverse the order of legend items in chart with a StackedAreaSeries

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);

這是我到目前為止得到的。 我在“productionSeries”中添加了 5 個 SeriesDefinition,它們顯示得很好:第一個在底部,下面堆疊在上面。 我現在的問題是圖例以與添加項目相同的方式對項目進行排序。 所以圖表底部的第一個 SeriesDefinitions 出現在頂部的圖例中。所以它是顛倒的,看起來很混亂。 有沒有辦法扭轉傳說項目或以某種方式重新排列它們?

我還沒有發現任何關於這個問題的信息,據我所知,不幸的是沒有 WinRTXaml 工具包的文檔。

我希望有人可以在這里幫助我或有小費,謝謝。

恐怕代碼本身將成為您的主要文檔。 我看到解決此問題的兩種主要方法是 - 更改添加圖例項的順序(在控件本身中 - 您需要更改數據可視化控件的代碼)或通過替換來更改它們的顯示順序StackPanel現在最有可能在那里使用某種ReverseOrderStackPanel實現。 第三種方法可能是繪制您自己的圖例,第四種方法可能是在生成視覺元素后對其進行迭代,並通過操縱視覺樹對它們進行重新排序。

最終,雖然控件確實支持一些自定義,但如果您想要更多自定義可視化或更好的性能,我建議使用 Win2D 繪制自己的圖表

可以訪問系列中自動添加的 Legenditems(“productionSeries.LegendItems”)並重新排列它們。 在下面的代碼中,我 go 通過圖例的反向列表並構建一個新列表,然后我再次將其添加到系列中。 刪除后當然是原來的。

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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM