Hello,
This is a tough one to explain, and even tougher to demonstrate. I've tried to build a sample project to demonstrate this issue, but I'm unable to re-create it in my sample.
This only happens in our full-fledged implementation.
The basic setup is as follows:
When the chart is being rendered, it is receiving data from the server and being rendered like so (slightly obfuscated so that object names aren't specific to my project - anywhere you see "My" is a business object name, but other than that, this code is untouched):
private void buildChart(MyReport report)
{
// Clear chart
MyChart.ItemsSource = null;
MyChart.SeriesMappings.Clear();
MyChart.DefaultView.ChartTitle.Content = null;
MyChart.DefaultView.ChartArea.Legend.Items.Clear();
MyChart.DefaultView.ChartArea.DataSeries.Clear();
// Set NoDataControl Text
MyChart.DefaultView.ChartArea.NoDataString = report.NoDataLabel;
// Axes titles
MyChart.DefaultView.ChartArea.AxisX.Title = report.XAxisTitle;
MyChart.DefaultView.ChartArea.AxisY.Title = report.YAxisTitle;
// Axes setup
MyChart.DefaultView.ChartArea.AxisY.MinValue = (double) report.YAxisMin;
MyChart.DefaultView.ChartArea.AxisY.MaxValue = (double) report.YAxisMax;
MyChart.DefaultView.ChartArea.AxisY.Step = (double) report.YAxisStep;
// X-Axis Scrolling
MyChart.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.ScrollAndZoom;
MyChart.DefaultView.ChartArea.ZoomScrollSettingsX.MinZoomRange = 0.1;
MyChart.DefaultView.ChartArea.ZoomScrollSettingsX.RangeStart = (double)report.XAxisScrollRangeStart;
MyChart.DefaultView.ChartArea.ZoomScrollSettingsX.RangeEnd = (double)report.XAxisScrollRangeEnd;
// Disable scrolling if the entire chart fits in the render area
if (report.XAxisScrollRangeStart == 0 && report.XAxisScrollRangeEnd == 1)
{
MyChart.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.None;
}
// Show or hide legend based on chart type
switch (report.ChartType)
{
case QasrChartType.Bar:
MyChart.DefaultView.ChartArea.Legend.Visibility = Visibility.Collapsed;
break;
case QasrChartType.Line:
MyChart.DefaultView.ChartArea.Legend.Visibility = Visibility.Visible;
break;
default:
throw new EnumSwitchException(report.ChartType);
}
// If there is no data, hide the legend
if (report.DataPoints.Count == 0)
{
MyChart.DefaultView.ChartArea.Legend.Visibility = Visibility.Collapsed;
}
// Create series data
List<
List
<MyDataPoint>> seriesData = new List<
List
<MyDataPoint>>();
// Create Series Mappings
int collectionIndex = 0;
foreach (string seriesName in report.DataPoints.Keys)
{
SeriesDefinition seriesDefinition = null;
switch (report.ChartType)
{
case MyChartType.Bar:
seriesDefinition = new BarSeriesDefinition();
break;
case MyChartType.Line:
seriesDefinition = new LineSeriesDefinition();
break;
default:
throw new EnumSwitchException(report.ChartType);
}
// Add series mappings
SeriesMapping seriesMapping = createSeriesMapping(seriesName, seriesDefinition);
seriesMapping.CollectionIndex = collectionIndex;
MyChart.SeriesMappings.Add(seriesMapping);
// Add series data
seriesData.Add(new List<
MyDataPoint
>());
seriesData[collectionIndex].AddRange(report.DataPoints[seriesName]);
collectionIndex++;
}
// Set chart ItemsSource to the series data
MyChart.ItemsSource = seriesData;
if (report.ChartType == MyChartType.Line && report.DataPoints.Count > 0)
{
// Legend
buildLegend();
}
// Initial load is complete
_isInitialLoad = false;
}
Due to the highly dynamic nature of the data, I was forced to use codebehind to setup the chart.
Either way, the following odd behavior occurs:
This chart has clickable data points (the ItemClick event is wired up elsewhere). When any data point is clicked, whether it be a line or bar chart, a new report is retrieved from the server, and the chart is re-rendered.
When re-rendered, the chart automatically puts itself in "user has started zooming with their mouse mode", meaning that the zoom box (the draggable zoom selection area) is drawn. To make matters more odd, by clicking the selection it doesn't actually zoom. The highlight box just disappears.
I have tried everything imaginable to try to fix this issue. Since the only difference between my sample project and the real project is that the Telerik "Vista" theme is used, I'm thinking it may have something to do with that.
I'm at my wits end, however, as to how to workaround the issue.
I have tried the following:
1: Set MyChart.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode to ScrollMode.None, then change it back to ScrollMode.ScrollAndZoom after the chart has rendered
2: Tried the above on another thread, where it is set to "None", waits 1 second, then gets set back to ScrollAndZoom. Amazingly, 1 second later, when ScrollAndZoom is turned back on, the highlight box *still* shows up without any user interaction.
3: Tried waiting until the DataBound event is fired before changing the ScrollMode back to ScrollAndZoom - same problem.
4: A host of other attempts which all lead to the same problem.
Whatever is happening, it appears that some flag is set after I clear my chart and either before or after I render the chart that says "the user has started zooming in the ChartArea with their mouse", although this isn't the case. Again, actually clicking to "zoom" does nothing - it seems that this flag just puts it in some kind of "draw the highlight area" mode.
I would even settle on a solution that requires me to use reflection to manually set this flag to false if you can point me towards some internal or private property that I can use to force it.
To confound matters even worse, this problem doesn't manifest itself on every chart render, and despite methodically trying to figure out exactly which sequence of events causes this happen, it seems to be completely random.
I know that this is a difficult one because I cannot produce a sample project. My main goal by posting this is in the hopes that you can point me towards some internal / private property that I can force using Reflection.
[Edit: I should mention that I was originally using Q1 2011 and tried upgrading to Q3 2011, but that didn't fix my problem. Issue still persists in Q3 2011]
[Edit 2: Upon further research and some testing, I've discovered that in Silverlight, it's impossible to set a private property (as opposed to full .NET where this isn't a problem). Using Reflector, I was able to determine that the ChartArea.DragZoomLayerControl has a property called "isDragging", which is private, which I have no way to change with these absurd security restrictions in Silverlight. Any other suggestions would be greatly appreciated.]
Thanks for your time on this difficult one,
Jon