當前位置: 首頁>>代碼示例>>C#>>正文


C# Chart.Measure方法代碼示例

本文整理匯總了C#中Chart.Measure方法的典型用法代碼示例。如果您正苦於以下問題:C# Chart.Measure方法的具體用法?C# Chart.Measure怎麽用?C# Chart.Measure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Chart的用法示例。


在下文中一共展示了Chart.Measure方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RenderChartToImage

        public static void RenderChartToImage(Chart elementToRender, GraphableSensor[] sensors, int width, int height, bool renderFullDataSeries, string filename)
        {
            if (elementToRender == null)
                return;
            Debug.WriteLine("Turning on immediate invalidate");
            //Force immediate invalidation
            InvalidationHandler.ForceImmediateInvalidate = true;

            Debug.WriteLine("Creating new chart");
            var clone = new Chart();

            clone.Width = clone.Height = double.NaN;
            clone.HorizontalAlignment = HorizontalAlignment.Stretch;
            clone.VerticalAlignment = VerticalAlignment.Stretch;
            clone.Margin = new Thickness();

            clone.Title = elementToRender.Title;
            clone.XAxis = new DateTimeAxis { Title = "Date" };
            clone.YAxis = new LinearAxis { Range = (IRange<double>)elementToRender.YAxis.Range, Title = elementToRender.YAxis.Title };

            for (var i = 0; i < elementToRender.Series.Count; i++)
            {
                var series = elementToRender.Series[i];
                var sensor = sensors[i];

                if (sensor.Sensor.Name != series.DataSeries.Title)
                {
                    Debug.WriteLine("Mismatched titles! Oh Dear!");
                    continue;
                }

                var lineSeries = new LineSeries
                                     {
                                         LineStroke = ((LineSeries)series).LineStroke,
                                         DataSeries =
                                             renderFullDataSeries
                                                 ? new DataSeries<DateTime, float>(sensor.Sensor.Name, sensor.DataPoints)
                                                 : series.DataSeries
                                     };
                clone.Series.Add(lineSeries);
            }

            var size = new Size(width, height);

            Debug.WriteLine("Rendering new chart of size {0}", size);
            clone.Measure(size);
            clone.Arrange(new Rect(size));
            clone.UpdateLayout();

            var renderer = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Pbgra32);

            renderer.Render(clone);

            var pngEncoder = new PngBitmapEncoder();
            pngEncoder.Frames.Add(BitmapFrame.Create(renderer));

            Debug.WriteLine("Saving to file");
            using (var file = File.Create(filename))
            {
                pngEncoder.Save(file);
            }

            Debug.WriteLine("Turning off immediate invalidate");
            //Reset the invalidation handler
            InvalidationHandler.ForceImmediateInvalidate = false;

            EventLogger.LogInfo(null, "Image Exporter", "Saved graph as image to: " + filename);
        }
開發者ID:rwlamont,項目名稱:AllItUp,代碼行數:68,代碼來源:Common.cs


注:本文中的Chart.Measure方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。