1 pièce(s) jointe(s)
Est-ce possible de réaliser un LiveChart avec VS 2019 WinForm C# .net Framework
Bonjour,
J'ai suivi ce tuto : https://www.youtube.com/watch?v=ZO3edHKFb68
Malheureusement le rechargement à chaud ne se fait pas, je dois toujours appuyer sur le bouton de rechargement.
Mon programme form1.cs :
Code:
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;
}
}
} |
Ma classe "Revenue"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace livechart
{
public class Revenue
{
public int année { get; set; }
public int mois { get; set; }
public double total { get; set; }
}
} |
Mon résultat :
Pièce jointe 596931
On voit bien que le rechargement à chaud n'est pas possible.
Je ne vois pas comment faire.
Je vous remercie par avance.
Régis