Пример #1
0
        /// <summary>
        /// Adds a color to the specified serie. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="model">Serie from model.</param>
        /// <exception cref="System.ArgumentNullException">If <paramref name="model" /> is <c>null</c>.</exception>
        public static void AddSerieColor(ChartSerieModel model)
        {
            SentinelHelper.ArgumentNull(model);

            var xmlSerieList = ChartXmlHelper.GetElementsByTagName("c:v");
            var textNode     = xmlSerieList.FirstOrDefault(n => n.ParentNode.ParentNode.Name.Equals("ser") && n.InnerText.Equals(model.Name));

            if (textNode == null)
            {
                return;
            }

            var charType = model.ChartType;

            switch (charType)
            {
            case KnownChartType.Pie3D:
                break;

            default:
                var areaChartSeriesNode = textNode.ParentNode.ParentNode;
                areaChartSeriesNode.AddShapePropertiesNode(model);
                break;
            }
        }
Пример #2
0
        /// <summary>
        ///		Crea una serie
        /// </summary>
        private ChartSerieModel CreateSerie(List <string> labels, string nameField, string valueField)
        {
            Dictionary <string, double> values = new Dictionary <string, double>();
            ChartSerieModel             serie  = new ChartSerieModel();

            // Inicializa el diccionario
            foreach (string label in labels)
            {
                values.Add(label, 0);
            }
            // Asigna las propiedades
            serie.Name = valueField;
            // Añade los elementos al diccionario
            foreach (DataRow row in QueryViewModel.DataResults.Rows)
            {
                string label = GetString(row[nameField]);

                // Añade el valor al diccionario
                values[label] += GetDouble(row[valueField]);
            }
            // Añade los elementos a la serie
            for (int index = 0; index < labels.Count; index++)
            {
                serie.Items.Add(new ChartSeriePointModel
                {
                    X = index,
                    Y = values[labels[index]]
                }
                                );
            }
            // Devuelve la serie
            return(serie);
        }
Пример #3
0
        /// <summary>
        /// Adds a <c>spPr</c> node (Shape properties) to the node of type <c>ser</c> (Area Chart Series) specified. Not supported in <c>EPPlus</c> library.
        /// </summary>
        /// <param name="node"><c>ser</c> node (Area Chart Series).</param>
        /// <param name="model">Serie from model.</param>
        /// <remarks>
        /// For more information please see <a href="http://www.schemacentral.com/sc/ooxml/e-draw-chart_spPr-1.html">http://www.schemacentral.com/sc/ooxml/e-draw-chart_spPr-1.html</a>
        /// </remarks>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="node" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="model" /> is <c>null</c>.</exception>
        public static void AddShapePropertiesNode(this XmlNode node, ChartSerieModel model)
        {
            SentinelHelper.ArgumentNull(node);
            SentinelHelper.ArgumentNull(model);

            var shapePropertiesNode = ChartXmlHelper.CreateOrDefaultAndAppendElementToNode(node, "c:spPr");

            shapePropertiesNode.AddSolidFillNode(model.GetColor());
        }
Пример #4
0
        protected async Task <IActionResult> DetailsInternalAsync <T>(string tagType, string tag, string viewName = "TagDetails") where T : TagModel, new()
        {
            var details = await _api.GetAsync <dto.Model.TagDetails>($"tags/{tagType.ToCleanQuery()}/{tag.ToCleanQuery()}");

            var transactions = await _api.GetAsync <IEnumerable <dto.Model.Transaction> >($"transactions/tag/{tagType.ToCleanQuery()}/{tag.ToCleanQuery()}");

            var request = new TagStatisticsRequest
            {
                Range          = EDateRange.Months,
                DateStart      = new DateTime(DateTime.Today.Year - 1, DateTime.Today.Month, 1).AddMonths(1),
                DateEnd        = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(1).AddMilliseconds(-1),
                IncludeSubTags = true,
                ReturnSubTags  = true,
            };

            var stats = await _api.PostAsync <IEnumerable <dto.Model.TagStatisticsModel> >($"tags/{tagType.ToCleanQuery()}/{tag.ToCleanQuery()}/statistics", System.Text.Json.JsonSerializer.Serialize(request), "application/json");

            var dicStats = stats.ToDictionary(s => (Year: s.Year, Month: s.Month.Value));

            var statsWithEmptyMonthsFilled = new List <dto.Model.TagStatisticsModel>();

            // --- Initialisation des données du tableau
            var chart     = new ChartModel();
            var dicSeries = new Dictionary <string, ChartSerieModel>();

            var serie = new ChartSerieModel {
                Id = "total", Label = "Total", Type = "line"
            };

            dicSeries.Add(serie.Id, serie);
            chart.Series.Add(serie);

            serie = new ChartSerieModel {
                Id = "average", Label = "Moyenne", Type = "line"
            };
            dicSeries.Add(serie.Id, serie);
            chart.Series.Add(serie);

            serie = new ChartSerieModel {
                Id = $"tag:{details.Key}", Label = details.Caption ?? details.Key, Group = "main", BackgroundColor = ChartModel.DefaultColors[0]
            };
            dicSeries.Add(serie.Id, serie);
            chart.Series.Add(serie);

            var first = stats.FirstOrDefault();

            if (first != null)
            {
                int colorId = 1;

                foreach (var subTagTotal in first.SubTagTotals)
                {
                    serie = new ChartSerieModel {
                        Id = $"tag:{subTagTotal.Tag.Key}", Label = subTagTotal.Tag.Caption ?? subTagTotal.Tag.Key, Group = "main", BackgroundColor = ChartModel.DefaultColors[colorId++]
                    };
                    dicSeries.Add(serie.Id, serie);
                    chart.Series.Add(serie);
                }
            }

            var average = stats.Average(s => s.Total);

            // --- Initialisation des données du tableau
            for (var date = request.DateStart.Value; date <= request.DateEnd.Value; date = date.AddMonths(1))
            {
                chart.Labels.Add(date.ToString("MMM yy"));

                if (dicStats.TryGetValue((date.Year, date.Month), out TagStatisticsModel stat))
                {
                    dicSeries["total"].Values.Add(stat.Total);
                    dicSeries["average"].Values.Add(average);
                    dicSeries[$"tag:{details.Key}"].Values.Add(stat.TagTotal);

                    foreach (var subTagTotal in stat.SubTagTotals)
                    {
                        dicSeries[$"tag:{subTagTotal.Tag.Key}"].Values.Add(subTagTotal.Amount);
                    }
                }