/// <summary> /// Exports the specified model to a file. /// </summary> /// <param name="model">The model.</param> /// <param name="fileName">Name of the file.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> public static void Export(PlotModel model, string fileName, double width, double height, IRenderContext textMeasurer = null) { using (var svgrc = new SvgRenderContext(fileName, width, height, textMeasurer)) { model.Update(); model.Render(svgrc); } }
/// <summary> /// Exports the specified model to a stream. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The output stream.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> public static void Export(PlotModel model, Stream stream, double width, double height, IRenderContext textMeasurer = null) { using (var svgrc = new SvgRenderContext(stream, width, height, true, textMeasurer)) { model.Update(); model.Render(svgrc); } }
/// <summary> /// Exports the specified model to a stream. /// </summary> /// <param name="model">The model.</param> /// <param name="stream">The output stream.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <param name="textMeasurer">The text measurer.</param> public static void Export(PlotModel model, Stream stream, double width, double height, bool isDocument, IRenderContext textMeasurer) { using (var rc = new SvgRenderContext(stream, width, height, true, textMeasurer, model.Background)) { model.Update(); model.Render(rc, width, height); rc.Complete(); rc.Flush(); } }
public static void Export(PlotModel model, string fileName, int width, int height, Brush background = null) { using (var bm = new Bitmap(width, height)) { using (Graphics g = Graphics.FromImage(bm)) { if (background != null) { g.FillRectangle(background, 0, 0, width, height); } var rc = new GraphicsRenderContext { RendersToScreen = false }; rc.SetGraphicsTarget(g); model.Update(); model.Render(rc, width, height); bm.Save(fileName, ImageFormat.Png); } } }
/// <summary> /// Exports the specified plot model to a stream. /// </summary> /// <param name="model">The plot model.</param> /// <param name="stream">The stream to write to.</param> /// <param name="width">The width of the export image.</param> /// <param name="height">The height of the exported image.</param> /// <param name="background">The background.</param> public static void Export(PlotModel model, Stream stream, double width, double height, OxyColor background = null) { var canvas = new Canvas { Width = width, Height = height }; if (background != null) { canvas.Background = background.ToBrush(); } canvas.Measure(new Size(width, height)); canvas.Arrange(new Rect(0, 0, width, height)); var rc = new SilverlightRenderContext(canvas); model.Update(); model.Render(rc, width, height); canvas.UpdateLayout(); var image = canvas.ToImage(); image.WriteToStream(stream); }
/// <summary> /// Exports to string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <returns> /// The plot as a svg string. /// </returns> public static string ExportToString(PlotModel model, double width, double height, bool isDocument = false, IRenderContext textMeasurer = null) { string svg; using (var ms = new MemoryStream()) { var svgrc = new SvgRenderContext(ms, width, height, isDocument, textMeasurer); model.Update(); model.Render(svgrc); svgrc.Complete(); svgrc.Flush(); ms.Flush(); ms.Position = 0; var sr = new StreamReader(ms); svg = sr.ReadToEnd(); } return(svg); }
protected override Image DoCreateChartImage() { var plotModel = new PlotModel(""); var ls = new LineSeries("") { Points = Parameters.SeriaData.Select(t => new DataPoint(t.Key, t.Value) as IDataPoint).ToList() }; plotModel.Series.Add(ls); plotModel.Axes.Add(new LinearAxis(AxisPosition.Left)); plotModel.Axes.Add(new LinearAxis(AxisPosition.Bottom)); var bitmap = new Bitmap(Parameters.ChartWidth, Parameters.ChartHeight); using (var graphics = Graphics.FromImage(bitmap)) { var graphicsRenderContext = new GraphicsRenderContext { RendersToScreen = false }; graphicsRenderContext.SetGraphicsTarget(graphics); plotModel.Update(); plotModel.Render(graphicsRenderContext, Parameters.ChartWidth, Parameters.ChartHeight); return bitmap; } }
/// <summary> /// Exports to string. /// </summary> /// <param name="model">The model.</param> /// <param name="width">The width (points).</param> /// <param name="height">The height (points).</param> /// <param name="textMeasurer">The text measurer.</param> /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param> /// <returns> /// The plot as a svg string. /// </returns> public static string ExportToString(PlotModel model, double width, double height, bool isDocument = false, IRenderContext textMeasurer = null) { string svg; using (var ms = new MemoryStream()) { var svgrc = new SvgRenderContext(ms, width, height, isDocument, textMeasurer); model.Update(); model.Render(svgrc); svgrc.Complete(); svgrc.Flush(); ms.Flush(); ms.Position = 0; var sr = new StreamReader(ms); svg = sr.ReadToEnd(); } return svg; }