Tag: legend

在wpf工具包图表lineseries中为图例项目附近的矩形指定颜色

我正在动态地将lineseries添加到图表中,如下所示。 foreach (KeyValuePair<string, List<KeyValuePair>> tempSeries in yieldSeries) { LineSeries lineSeries = new LineSeries(); lineSeries.DependentValuePath = “Value”; lineSeries.IndependentValuePath = “Key”; lineSeries.ItemsSource = tempSeries.Value; lineSeries.Title = tempSeries.Key; lineSeries.SetResourceReference(FrameworkElement.StyleProperty,”CommonLineSeries”); lineSeries.Tag = Brushes.Red; lineSeries.Background = Brushes.Red; yieldTrendChart.Series.Add(lineSeries); } 我希望按照特定的顺序为特定的顺序指定特定的颜色以实现这一点我已经为折线添加了如下样式 问题颜色已成功分配给图形中的线条, 但图例附近的矩形仍然随机显示.net指定的颜色。 如何为矩形分配相同的颜色,因为我已将其分配给线?

使图表图例代表两种颜色

我在我的应用程序中创建了一个柱形图,如下所示: 如您所见,正值为绿色,负值为红色。 我需要在传奇中代表这一点。 我只是不知道如何。 我已经尝试过的: 我将CustomItems添加到Legend 。 这是代码: Legend currentLegend = chart.Legends.FindByName(chart.Series[series].Legend); if (currentLegend != null) { currentLegend.LegendStyle = LegendStyle.Table; LegendItem li = new LegendItem(); li.Name = series; li.Color = Color.Red; li.BorderColor = Color.Transparent; currentLegend.CustomItems.Add(li); } 这导致以下表示: 我可以忍受。 但是,只要我在图表中添加更多系列,元素的顺序就会被破坏。 这是一个例子: 我想有两个选项之一: 保持正面和负面颜色 或者更好的解决方案可能是在图例中只有一个双色的瓷砖。 像这样的东西: 你能帮我解决这个问题吗? 提前谢谢了!