1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace livechart
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
revenueBindingSource.DataSource = new List<Revenue>();
cartesianChart1.AxisX.Add(new LiveCharts.Wpf.Axis
{
Title = "Mois",
Labels = new [] {"jan","fev","mar","avr","mai","juin","juill","aout","sep","oct","nov","dec"}
});
cartesianChart1.AxisY.Add(new LiveCharts.Wpf.Axis
{
Title = "Revenue",
LabelFormatter = value=>value.ToString("C")
});
cartesianChart1.LegendLocation = LiveCharts.LegendLocation.Right;
}
private void btn_charg_Click(object sender, EventArgs e)
{
// init données
cartesianChart1.Series.Clear();
SeriesCollection series = new SeriesCollection();
var années = (from o in revenueBindingSource.DataSource as List<Revenue>
select new { année = o.année }).Distinct();
foreach(var an in années)
{
List<double> values = new List<double>();
for (int month = 1; month <= 12; month ++)
{
double value = 0;
var data = from o in revenueBindingSource.DataSource as List<Revenue>
where o.année.Equals(an.année) && o.mois.Equals(month)
orderby o.mois ascending
select new { o.total, o.mois };
if(data.SingleOrDefault() != null)
value = data.SingleOrDefault().total;
values.Add(value);
}
series.Add(new LineSeries() { Title = an.année.ToString(), Values = new ChartValues<double>(values) });
}
cartesianChart1.Series = series;
}
}
} |
Partager