Reputation: 3240
I have a very simple Visiblox chart that works fine:
<charts:Chart Grid.Row="1" Height="100" x:Name="VisiChart">
<charts:Chart.Series>
<charts:LineSeries/>
</charts:Chart.Series>
</charts:Chart>
I set my DataSeries
in the code-behind:
VisiChart.Series[0].DataSeries = MyDataSeries;
Simple as that.
I can grab a bitmap from a visual element using this method:
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;
}
Now I use this bitmap in a report or whatever. This works.
And here comes my problem: If I want to create my report with the image of the chart without a GUI (in a server application, e.g. a Windows service or in IIS) I get a NullReferenceException
from the chart.
What I do is to create my control that contains the chart. Then I call Measure()
on the control to make it do its work. That's where I get:
NullReferenceException
at Visiblox.Charts.Chart.OnApplyTemplateInternal()
at Visiblox.Charts.ChartBase.OnApplyTemplate()
at System.Windows.FrameworkElement.ApplyTemplate()
I guess I have to set the chart's template manually, but where do I find the default templates from VisiBlox? And how do I apply them? Or is there another problem?
Many thanks.
--- EDIT ---
So, I figured that if I call Measure() on a VisiBox chart (or an element that contains the chart) in a Console Application I get always this Exception. So I could also change the title of this question to How to use VisiBlox charts in a Console Application
Upvotes: 0
Views: 206
Reputation: 3240
ok, i figured the answer:
1) wrap the visiblox stuff in
InvalidationHandler.ForceImmediateInvalidate = true;
// here comes the chart
InvalidationHandler.ForceImmediateInvalidate = false;
to tell it to actually render.
2) set the data manually and not via DataContext. This may not be wired, if the component is not displayed.
3) set the style of the chart manually. The defaults are somewhere in Visiblox Generic.xaml file.
Upvotes: 0