本帖最后由 dddsssssqq 于 2022-5-11 10:51 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using C1.WPF.Chart;
namespace FlexChartDemo;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private readonly List<int> _data = new();
private readonly List<SolidColorBrush> brushs = new() {
new SolidColorBrush(Colors.Red),
new SolidColorBrush(Colors.OrangeRed),
new SolidColorBrush(Colors.Orange),
new SolidColorBrush(Colors.Yellow),
new SolidColorBrush(Colors.YellowGreen),
new SolidColorBrush(Colors.GreenYellow)
};
private readonly int npts = 12;
private readonly Random rnd = new();
private List<DataItem> _data1;
private Series paretoLine;
public MainWindow() {
InitializeComponent();
for (var i = 0; i < 12; i++) {
_data.Add(rnd.Next(20, 100));
}
flexChart.ItemsSource = Data1;
flexChart.Series[0].SymbolRendering += Flexchart_SymbolRendering;
flexChart.Series[1].SymbolRendering += Flexchart_SymbolRendering;
}
public List<DataItem> Data1 {
get {
if (_data1 == null) {
var sum = _data.Sum() * 1.0;
var count = 0;
_data1 = new List<DataItem>();
for (var i = 0; i < npts; i++) {
count += _data[i];
_data1.Add(new DataItem {
Time = $"{i + 1}",
PDF = Math.Round(_data[i] / sum * 100, 2),
CDf = Math.Round(count / sum * 100, 2)
});
}
}
return _data1;
}
}
private void Flexchart_SymbolRendering(object? sender, RenderSymbolEventArgs e) {
e.Engine.SetFill(brushs[e.Index % 6]);
}
public class DataItem {
public string Time { get; set; }
public double CDf { get; set; }
public double PDF { get; set; }
}
} |