簡體   English   中英

LiveCharts ColumnSeries 在運行時更新顏色

[英]LiveCharts ColumnSeries update Colours on Runtime

我在 WPF 上使用 LiveCharts 0.9.7 和 1.2.9 Geared Version 來顯示 ColumnSeries 上的人口數據。

這是我的場景:一開始,我用藍色填充列。 我想在運行時更改單個列值的顏色。

我試圖用SeriesCollection[0].Values[0]達到單個值,但是沒有 Fill 或 Color 選項,它只是Double

我還嘗試將SeriesCollection[0] to ColumnSeries但是我無法實現結果。 是否可以在運行時更新單個值的顏色?

public SeriesCollection SeriesCollection { get; set; } = new SeriesCollection
{
  new ColumnSeries
  {
    Title = "Population of Bodrum",
    Values = new ChartValues<double> { 1500, 2500, 3700, 2000, 1000},
    Fill = Brushes.Blue
  }
};

人口柱系列

您可以通過將CartesianMapper分配給ColumnSeries.Configuration來指定配置。

以下示例將給定圖表的第三列的顏色從藍色更改為紅色:

public class ChartDataModel
{
  public ChartDataModel()
  {
    this.BlueSeries = new ColumnSeries()
    {
      Title = "Population of Bodrum",
      Values = new ChartValues<double> { 1500, 2500, 3700, 2000, 1000 },
      Fill = Brushes.Blue
    };
    this.SeriesCollection = new SeriesCollection() { this.BlueSeries };
  }

  private void ChangeThirdChartPointColorToRed()
  {
    CartesianMapper<double> mapper = Mappers.Xy<double>()
      .X((value, index) => index)
      .Y(value => value)
      .Fill((value, index) => index == 2 ? Brushes.Red : Brushes.Blue);

    // Dynamically set the third chart point color to red
    this.BlueSeries.Configuration = mapper;
  }

  // The actual chart data source
  public SeriesCollection SeriesCollection { get; set; }

  private ColumnSeries BlueSeries { get; set; }
}

您還可以使用CartesianMapper根據其y值通過指定相應的謂詞來更改點的顏色。 要繪制超過 2,000 紅色值的所有值,您可以使用以下映射器:

 CartesianMapper<double> mapper = Mappers.Xy<double>()
   .X((value, index) => index)
   .Y(value => value)
   .Fill((value, index) => value > 2000 ? Brushes.Red : Brushes.Blue);

暫無
暫無

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

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