public static CSV ConverteCsv(string csvLine) { CSV csvValues = null; if (!string.IsNullOrEmpty(csvLine)) { string[] values = csvLine.Split(','); csvValues = new CSV(); csvValues.dataVenda = Convert.ToDateTime(values[1]); csvValues.nomeProduto = values[3]; csvValues.qtdVendida = Convert.ToDouble(values[4]); } return(csvValues); }
public void ProcessChart() { var caminhoArquivo = ConfigurationSettings.AppSettings["caminhoArquivo"].ToString(); var file = Directory.GetFiles(caminhoArquivo, "*csv").OrderByDescending(d => new FileInfo(d).CreationTime).First(); List <CSV> CSVItems = File.ReadAllLines(file) .Skip(1) .Select(v => CSV.ConverteCsv(v)) .Where(x => x != null && x.qtdVendida > 0) .GroupBy(x => new { x.nomeProduto, x.dataVenda }) .Select(x => new CSV { dataVenda = x.Key.dataVenda, nomeProduto = x.Key.nomeProduto, qtdVendida = x.Sum(y => y.qtdVendida) }) .OrderBy(x => x.qtdVendida) .ToList(); var listaNome = new List <string>(); var listaDataString = new List <string>(); List <DateTime> distinctDates = CSVItems.Select(x => x.dataVenda).Distinct().OrderBy(y => y.Date).ToList(); foreach (var item in distinctDates) { listaDataString.Add(item.ToShortDateString()); } cartesianChart1.AxisX.Add(new Axis() { Labels = listaDataString }); cartesianChart1.AxisY.Add(new Axis { LabelFormatter = (value => value.ToString()), Separator = new Separator() }); AddItemsToChart(CSVItems, distinctDates); }