c#实时图表线条不同颜色



我有两个时间序列,第一个是每天的价格,第二个是某一天的价格。我想画一行,但我不想画一天的价格。我找到了那个链接,但我不知道怎么做。

链接:https://github.com/Live-Charts/Live-Charts/issues/162#issuecomment-232700608

我的代码:

var dayConfig = Mappers.Xy < ChartModel > ().X(dayModel =>dayModel.DateTime.Ticks).Y(dayModel =>dayModel.Value);
SeriesCollection = new SeriesCollection(dayConfig) {
new LineSeries {
Title = hisse1,
Values = ChartModelList.AsChartValues(),
},
};
Formatter = value =>new DateTime((long) value).ToString("dd.MM.yyyy");
DataContext = this;

您可以在XAML或数据模型中定义系列颜色。

XAML

<wpf:CartesianChart Series="{Binding SeriesCollection}>
<wpf:CartesianChart.SeriesColors>
<wpf:ColorsCollection>
<Color>Yellow</Color>
<Color>Green</Color>
</wpf:ColorsCollection>
</wpf:CartesianChart.SeriesColors>
</wpf:CartesianChart>

C#

您通常可以设置FillStrokeStrokeThicknessStrokeDashArray等属性来自定义系列的颜色。

// Draw a sine
var chartValues = new ChartValues<Point>();
for (int x = 0; x < 361; x++)
{
var point = new Point() {X = x, Y = Math.Sin(x * Math.PI / 180)};
chartValues.Add(point);
}
this.SeriesCollection = new SeriesCollection
{
// Set the line series color directly on the series object
new LineSeries
{
Title = "Yellow Series",
Values = chartValues,
Fill = Brushes.Yellow,
Stroke = Brushes.Blue
},
// Or use a Mapper which offers more flexibility e.g. allowing conditional coloring
new LineSeries
{
Title = "Mixed Color Series",
Configuration = new CartesianMapper<Point>()
.X(point => point.X)
.Y(point => point.Y)
.Stroke(point => point.X > 50 ? Brushes.Red : Brushes.LightGreen)
.Fill(point => point.X > 50 ? Brushes.Red : Brushes.LightGreen),
Values = chartValues
}
};

相关内容

  • 没有找到相关文章

最新更新