Approved
Last Updated: 03 Jan 2017 20:53 by ADMIN
ADMIN
Martin Ivanov
Created on: 25 Feb 2015 13:26
Category: ChartView
Type: Bug Report
0
ChartView: The CartesianGridLineAnnotation's label is not displayed initially when it uses a LabelDefinition with custom Template
The CartesianGridLineAnnotation's label is not displayed initially when it uses a LabelDefinition with custom Template. The annotation displays after resize of the chart (or after another layout pass).

Subscribe for PanOffsetChanged event of the chart control and reset the LabelDefinition of the annotations if they just appeared in the viewport. Here is an example for a possible appraoch for achieveing this:

private bool isInVisibleRange = false;
void chart_PanOffsetChanged(object sender, ChartPanOffsetChangedEventArgs e)
{
    foreach (CartesianGridLineAnnotation annotation in this.chart.Annotations)
    {
        if (double.Parse(annotation.Value.ToString()) >= this.verticalAxis.ActualVisibleRange.Minimum &&
            double.Parse(annotation.Value.ToString()) <= this.verticalAxis.ActualVisibleRange.Maximum)
        {
            if (!this.isInVisibleRange)
            {
                // code below resets the label definition of the annotation which triggers an update of its layout
                var definition = annotation.LabelDefinition;
                annotation.LabelDefinition = new ChartAnnotationLabelDefinition();
                annotation.LabelDefinition = definition;
 
                this.isInVisibleRange = true;
            }
             
        }
        else
        {
            this.isInVisibleRange = false;
        }
    }
}
0 comments