Ejemplo n.º 1
0
 public abstract Image Draw(
     GraphDefinition graphDefinition,
     IEnumerable <PersistedCityStatisticsWithFinancialData> statistics,
     Font font,
     Size size);
        public override Image Draw(
            GraphDefinition graphDefinition,
            IEnumerable <PersistedCityStatisticsWithFinancialData> statistics,
            Font font,
            Size size)
        {
            using (var chartMemoryStream = new MemoryStream())
            {
                var chart = new Chart
                {
                    Width       = new Unit(size.Width),
                    Height      = new Unit(size.Height),
                    Palette     = ChartColorPalette.Berry,
                    BorderColor = Color.DodgerBlue
                };

                chart.ChartAreas.Add("Test");

                var dataTable = ConvertIntoDataTable(graphDefinition, statistics);

                chart.DataBindCrossTable(dataTable.Rows, "Type", "TimeCode", graphDefinition.Title, String.Empty);

                chart.Titles.Add(graphDefinition.Title);

                chart.Font.Name = font.Name;
                chart.Font.Size = new FontUnit(font.SizeInPoints);

                chart.ChartAreas[0].BackGradientStyle  = GradientStyle.TopBottom;
                chart.ChartAreas[0].BackSecondaryColor = Color.LightSkyBlue;
                chart.ChartAreas[0].BackColor          = Color.LightBlue;

                chart.Legends.Add("Legend");

                foreach (var series in chart.Series)
                {
                    series.ChartType   = SeriesChartType.Line;
                    series.BorderWidth = series.BorderWidth * 4;

                    series.Color = graphDefinition.GraphSeriesSet.Single(x => x.Label == series.Name).Color;
                }
                if (graphDefinition.IsCurrency)
                {
                    chart.ChartAreas.Single().AxisY.LabelStyle.Format = "{0:C}";
                }

                graphDefinition.DataMeter.WithResultIfHasMatch(dataMeter =>
                {
                    foreach (var meter in dataMeter.Thresholds)
                    {
                        chart
                        .ChartAreas[0]
                        .AxisY
                        .CustomLabels
                        .Add(meter.MinMeasureUnitThreshold, meter.MaxMeasureUnitThreshold, meter.Category.ToString());
                    }
                });

                chart.SaveImage(chartMemoryStream);

                return(Bitmap.FromStream(chartMemoryStream));
            }
        }
Ejemplo n.º 3
0
        public override Image Draw(
            GraphDefinition graphDefinition,
            IEnumerable <PersistedCityStatisticsWithFinancialData> statistics,
            Font font,
            Size size)
        {
            using (var chartMemoryStream = new MemoryStream())
            {
                var chart = new ZedGraph.GraphPane();

                foreach (var axis in new[] { chart.XAxis, chart.YAxis as Axis })
                {
                    axis.Scale.IsUseTenPower = false;
                    axis.Scale.Format        = "F0";
                }

                chart.XAxis.Title.Text = "Time";
                chart.XAxis.Type       = AxisType.LinearAsOrdinal;
                chart.YAxis.Type       = AxisType.Linear;
                chart.YAxis.Title.Text = graphDefinition.Title;

                foreach (var z in graphDefinition.GraphSeriesSet)
                {
                    var pointPairList = new PointPairList();

                    foreach (var statistic in statistics)
                    {
                        pointPairList.Add(statistic.PersistedCityStatistics.TimeCode, z.GetValue(statistic));
                    }

                    chart.AddCurve(z.Label, pointPairList, z.Color, SymbolType.None);
                }

                chart.Title.Text = graphDefinition.Title;

                if (graphDefinition.IsCurrency)
                {
                    chart.YAxis.ScaleFormatEvent += (pane, axis, val, index) =>
                    {
                        return(val.ToString("C"));
                    };
                }

                graphDefinition.DataMeter.WithResultIfHasMatch(dataMeter =>
                {
                    chart.YAxis.ScaleFormatEvent += (pane, axis, val, index) =>
                    {
                        var meter = dataMeter.Thresholds.SingleOrDefault(
                            x => x.MinMeasureUnitThreshold <= val && x.MaxMeasureUnitThreshold > val);

                        if (meter != null)
                        {
                            return(meter.Category.ToString());
                        }
                        return(string.Empty);
                    };
                });

                return(chart.GetImage());
            }
        }