private string GetSparkLineImage (IEnumerable <float> samples, int width, int height, int id, SPWeb web // this because im using impersonate user ) { var chart = new Chart (); var series = new Series (); chart.Series.Add (series); / / Sparklines use the 'Spline' chart type to show a smoother trend with a line chart series.ChartType = SeriesChartType.Spline; / / Since the line is the only thing you see on the chart, you might want to / / Increase its width. Interestingly, you need to set the BorderWidth property / / In order to ACCOMPLISH that. series.BorderWidth = 2; / / Add samples to the series int i = 0; DateTime start = new DateTime (2010, 1, 1); foreach (var sample in samples) { i + +; / / Add 5 to the sample so line does not get cut off at the bottom of the image Chart.Series [0]. Points.AddXY (start.AddYears (i) sample); / / Chart.Series [0]. Points.AddXY (i, sample); } / / Start hiding Both sets of axes, labels, gridlines and tick marks var = new ChartArea ChartArea (); chart.ChartAreas.Add (ChartArea); chartArea.AxisX.LabelStyle.Enabled = false; chartArea.AxisY.LabelStyle.Enabled = false; chartArea.AxisX.MajorGrid.Enabled = false; chartArea.AxisY.MajorGrid.Enabled = false; chartArea.AxisX.MajorTickMark.Enabled = false; chartArea.AxisY.MajorTickMark.Enabled = false; chartArea.AxisX.LineWidth = 0; chartArea.AxisY.LineWidth = 0; / / Code Pilot chart.ChartAreas [0]. AxisX.Minimum = 0; chart.ChartAreas [0]. AxisX.Maximum = 20; Chart.Series [0]. IsXValueIndexed = true; Chart.Series [0]. YValuesPerPoint = 4; min = int (int) chart.ChartAreas [0]. AxisX.Minimum; int max = (int) chart.ChartAreas [0]. AxisX.Maximum; if (max> Chart.Series [0]. Points.Count) Chart.Series = max [0]. Points.Count; var points Chart.Series = [0]. Points.Skip (min). Take (max - min); var minValue = points.Min (x => x.YValues [0]); var maxValue = points.Max (x => x.YValues [0] * 2); chart.ChartAreas [0]. AxisY.Minimum = minValue; chart.ChartAreas [0]. AxisY.Maximum = maxValue; / / End Code Pilot / / Add an extra 5 pixels since the samples were adjusted up by 5 / / This Prevents the line from being truncated / / ChartArea.AxisY.Maximum maxValue = + 900; / / = ChartArea.AxisY.Minimum minValue - 100; / / Re-adjust the size of the chart to reduce unnecessary white space chart.Width = width; chart.Height = height; / / Get bytes of PNG image var s = new MemoryStream (); chart.SaveImage (s, ChartImageFormat.Png); s.Position = 0; Web.Lists SPList list = ["MyLibrary"]; SPFolder folder = list.RootFolder; web.AllowUnsafeUpdates = true; byte [] picFile s.ToArray = (); var fname = folder.Files.Add ("img" + id + ". png", picFile, true); s.Position = 0; arq.Url return; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)