Reputation: 29458
I was wondering if there was a way to get a callback on when a visifire chart is done rendering. I've been trying to create a chart and save it the image. This works with a button press, but does not work if I do it without the button. My guess is because the chart is not done loading, but I'm not so sure. When the page gets loaded, I set the ObservableCollection values that are used in my XAML.
I basically have a few data series that looks like this:
<vc:Chart.Series>
<vc:DataSeries RenderAs="StackedColumn" LegendText="Portion sequenced" LightingEnabled="False" AxisYType="Primary" Color="#4198AF" DataSource="{Binding SequencedValues}">
<vc:DataSeries.DataMappings>
<vc:DataMapping MemberName="AxisXLabel" Path="Key"></vc:DataMapping>
<vc:DataMapping MemberName="YValue" Path="Value"></vc:DataMapping>
</vc:DataSeries.DataMappings>
These get populated by the ObservableCollection. So I first call my method DrawImage() to set the observablecollection values, then I call Save(). Like I said, the Save() method works on its own with a button press, but does not if I call it after I draw the image. I thought it initially had to do with the page not finished loading yet. But using
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding PageLoadCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
I only call DrawImage() and Save() when the page is loaded. I even tried putting a sleep timer for 5 seconds between DrawImage() and Save() just to see if there was a timing problem and I still only get my background image, but nothing with my DataSeries.
So my question is if there's a way to get called back after the Visifire chart loads, or if there is another solution I'm missing. Thanks.
Upvotes: 0
Views: 312
Reputation: 1533
Crystal,
If you are working with Silveright, then you can save the image only by user actions like button press, but if you are working with WPF then Chart can be saved as soon as the Chart is fully rendered. But if you want to save the Chart as soon as the collection is populated then you can perform Save() method after some delay(using timer). Please checkout the code below.
MyChart.Series[0].DataSource = collection; //Populate Data
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = new TimeSpan(0, 0, 0, 0, 3000);// give some delay
timer.Start();
void timer_Tick1(object sender, EventArgs e)
{
ExportToImage(new Uri("d:/visifire1.png"), MyChart);
}
Upvotes: 1