当前位置: 首页>>代码示例>>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;未经允许,请勿转载。