/// <summary> /// Create a chart control. /// The current GraphicsWindow.BackgroundColor will be used for the background. /// The current GraphicsWindow.PenColor and Font properties will be used for the label text. /// For Example: /// GraphicsWindow.FontName = "Segoe UI" /// GraphicsWindow.FontBold = "False" /// </summary> /// <param name="width">The width of the chart.</param> /// <param name="height">The height of the chart.</param> /// <returns>The chart shape name.</returns> public static Primitive AddChart(Primitive width, Primitive height) { GraphicsWindow.Show(); Type GraphicsWindowType = typeof(GraphicsWindow); Type ShapesType = typeof(Shapes); Canvas _mainCanvas; Dictionary<string, UIElement> _objectsMap; string chartName; try { MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase); method.Invoke(null, new object[] { }); method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase); chartName = method.Invoke(null, new object[] { "Control" }).ToString(); _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null); _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null); InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate { try { Chart chart = new Chart(width, height); chart.Name = chartName; _objectsMap[chartName] = chart; _mainCanvas.Children.Add(chart); return chartName; } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return ""; } }); return FastThread.InvokeWithReturn(ret).ToString(); } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); return ""; } }