Example #1
0
        /// <summary>
        /// Fill charts with data
        /// </summary>
        /// <param name="charts">list of charts</param>
        /// <exception cref="InvalidProgramException">window.Content is not a FrameworkElement</exception>
        protected virtual void FillCharts(ArrayList charts)
        {
            Window window = null;

            // fill charts
            foreach (IChart chart in charts)
            {
                if (chart == null)
                {
                    continue;
                }
                Canvas chartCanvas = chart as Canvas;
                if (String.IsNullOrEmpty(chart.TableName))
                {
                    continue;
                }
                if (String.IsNullOrEmpty(chart.TableColumns))
                {
                    continue;
                }

                DataTable table = _data.GetDataTableByName(chart.TableName);
                if (table == null)
                {
                    continue;
                }

                if (chartCanvas != null)
                {
                    IChart newChart = (IChart)chart.Clone();

                    FrameworkElement windowContent = newChart as FrameworkElement;
                    if (windowContent == null)
                    {
                        throw new InvalidProgramException("newChart is not a FrameworkElement");
                    }

                    newChart.DataColumns = null;

                    newChart.DataView    = table.DefaultView;
                    newChart.DataColumns = chart.TableColumns.Split(',', ';');
                    newChart.UpdateChart();

                    windowContent.Measure(new System.Windows.Size(chartCanvas.Width, chartCanvas.Height));
                    windowContent.Arrange(new System.Windows.Rect(0, 0, chartCanvas.Width, chartCanvas.Height));
                    windowContent.UpdateLayout();

                    RenderTargetBitmap bitmap = new RenderTargetBitmap((int)(windowContent.RenderSize.Width * 600d / 96d), (int)(windowContent.RenderSize.Height * 600d / 96d), 600d, 600d, PixelFormats.Pbgra32);
                    bitmap.Render(windowContent);
                    chartCanvas.Children.Add(new Image()
                    {
                        Source = bitmap
                    });
                }
                else
                {
                    chart.DataColumns = null;

                    chart.DataView    = table.DefaultView;
                    chart.DataColumns = chart.TableColumns.Split(',', ';');
                    chart.UpdateChart();
                }
            }

            if (window != null)
            {
                window.Close();
            }
        }
        /// <summary>
        /// Fill charts with data
        /// </summary>
        /// <param name="charts">list of charts</param>
        /// <exception cref="InvalidProgramException">window.Content is not a FrameworkElement</exception>
        protected virtual void FillCharts(ArrayList charts)
        {
            Window window = null;

            // fill charts
            foreach (IChart chart in charts)
            {
                if (chart == null)
                {
                    continue;
                }
                Canvas chartCanvas = chart as Canvas;
                if (String.IsNullOrEmpty(chart.TableName))
                {
                    continue;
                }
                if (String.IsNullOrEmpty(chart.TableColumns))
                {
                    continue;
                }

                DataTable table = _data.GetDataTableByName(chart.TableName);
                if (table == null)
                {
                    continue;
                }

                if (chartCanvas != null)
                {
                    // HACK: this here is REALLY dirty!!!
                    IChart newChart = (IChart)chart.Clone();
                    if (window == null)
                    {
                        window                 = new Window();
                        window.WindowStyle     = WindowStyle.None;
                        window.BorderThickness = new Thickness(0);
                        window.ShowInTaskbar   = false;
                        window.Left            = 30000;
                        window.Top             = 30000;
                        window.Show();
                    }
                    window.Width   = chartCanvas.Width + 2 * SystemParameters.BorderWidth;
                    window.Height  = chartCanvas.Height + 2 * SystemParameters.BorderWidth;
                    window.Content = newChart;

                    newChart.DataColumns = null;

                    newChart.DataView    = table.DefaultView;
                    newChart.DataColumns = chart.TableColumns.Split(',', ';');
                    newChart.UpdateChart();

                    FrameworkElement windowContent = window.Content as FrameworkElement;
                    if (windowContent == null)
                    {
                        throw new InvalidProgramException("window.Content is not a FrameworkElement");
                    }
                    RenderTargetBitmap bitmap = new RenderTargetBitmap((int)(windowContent.RenderSize.Width * 600d / 96d), (int)(windowContent.RenderSize.Height * 600d / 96d), 600d, 600d, PixelFormats.Pbgra32);
                    bitmap.Render(window);
                    chartCanvas.Children.Add(new Image()
                    {
                        Source = bitmap
                    });
                }
                else
                {
                    chart.DataColumns = null;

                    chart.DataView    = table.DefaultView;
                    chart.DataColumns = chart.TableColumns.Split(',', ';');
                    chart.UpdateChart();
                }
            }

            if (window != null)
            {
                window.Close();
            }
        }