2013-01-23 33 views
0

我有一個非常簡單的Visiblox表工作正常:渲染Visiblox圖表上業務報告沒有圖形用戶界面引發的NullReferenceException

<charts:Chart Grid.Row="1" Height="100" x:Name="VisiChart"> 
    <charts:Chart.Series> 
     <charts:LineSeries/> 
    </charts:Chart.Series> 
</charts:Chart> 

設置我DataSeries在後臺代碼:

VisiChart.Series[0].DataSeries = MyDataSeries; 

就那麼簡單。

我可以使用此方法視覺元素搶位圖:

private static RenderTargetBitmap AsBmpToClipboard(FrameworkElement element) 
{ 
    var width = (int)Math.Round(element.ActualWidth); 
    var height = (int)Math.Round(element.ActualHeight); 
    var bmpCopied = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default); 
    var dv = new DrawingVisual(); 
    using (var dc = dv.RenderOpen()) 
    { 
     var vb = new VisualBrush(element); 
     dc.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height))); 
    } 
    bmpCopied.Render(dv); 
    Clipboard.SetImage(bmpCopied); // clipboard it for testing reasons 
    return bmpCopied; 
} 

現在,我在報告中或任何使用此位圖。這工作。

問題來了:如果我想用沒有GUI的圖表圖像創建我的報表(在服務器應用程序中,例如Windows服務或IIS中),我從圖表中獲得NullReferenceException

我所做的是創建包含圖表的控件。然後我在控件上調用Measure()以使其工作。這就是我得到:

NullReferenceException 
at Visiblox.Charts.Chart.OnApplyTemplateInternal() 
    at Visiblox.Charts.ChartBase.OnApplyTemplate() 
    at System.Windows.FrameworkElement.ApplyTemplate() 

我想我必須手動設置圖表的模板,但我在哪裏找到VisiBlox默認模板?我如何使用它們?還是有另一個問題?

非常感謝。

---編輯---

所以,我想,如果我叫一個控制檯應用程序一個VisiBox圖(或包含圖表元素)的測量()我總是得到這個異常。所以,我也可以改變這個問題的標題如何在控制檯應用程序

回答

0

確定使用VisiBlox圖表,我想通了答案:

1)包裹visiblox東西在

InvalidationHandler.ForceImmediateInvalidate = true; 
// here comes the chart 
InvalidationHandler.ForceImmediateInvalidate = false; 

告訴它實際渲染。

2)手動設置數據,而不是通過DataContext。如果未顯示組件,則可能未連線。

3)手動設置圖表的樣式。默認值在Visiblox Generic.xaml文件中。