Axis Labels overlapping

Apr 28, 2010 at 6:13 AM

Hi,

I am displaying dates on the x-axis where the xaxis labels are rotated via the following snippet, the issue is that when the dates are close to each other they start overlapping, is there a way i can show/hide axis labels when i zoom-in/out depending if they can fit without overlapping

 

 

 

 

            GenericLocationalLabelProvider<CustomXAxisInfo, double> labelProvider = new GenericLocationalLabelProvider<CustomXAxisInfo, double>(customXAxisLabels, labels => labels.Name);
            GenericLocationalTicksProvider<CustomXAxisInfo, double> ticksProvider = new GenericLocationalTicksProvider<CustomXAxisInfo, double>(customXAxisLabels, labels => labels.Coordinate);
            axis.LabelProvider = labelProvider;
            axis.TicksProvider = ticksProvider;
            axis.LabelProvider.SetCustomView((li, uiElement) =>
            {
                FrameworkElement element = (FrameworkElement)uiElement;
                element.LayoutTransform = new RotateTransform(-90, 0, 0);
            });

 

Thanks much.

 

Apr 28, 2010 at 6:33 AM

Hi,

Use custom ticks

http://dynamicdatadisplay.codeplex.com/Thread/View.aspx?ThreadId=209121

Regards

Ravi.

Apr 29, 2010 at 5:59 AM

Hi,

 

Thanks for the info, in my case I am not using HorizontalDateTimeAxis, is there another TicksProvider i can use in this case?

Apr 29, 2010 at 9:27 AM

Never mind i created CustomGenericLocationalTicksProvider and it worked like a charm... Thanks though.

 

   public ITicksInfo<TAxis> GetTicks(Range<TAxis> range, int ticksCount)
        {
            EnsureSearcher();

            //minResult = searcher.SearchBetween(range.Min, minResult);
            //maxResult = searcher.SearchBetween(range.Max, maxResult);

            minResult = searcher.SearchFirstLess(range.Min);
            maxResult = searcher.SearchGreater(range.Max);

            Double minRange = range.Min.ToDouble();
            Double maxRange = range.Max.ToDouble();
            Double minStep = (maxRange - minRange)*.10;

            if (!(minResult.IsEmpty && maxResult.IsEmpty))
            {
                int startIndex = !minResult.IsEmpty ? minResult.Index : 0;
                int endIndex = !maxResult.IsEmpty ? maxResult.Index : collection.Count - 1;

                int count = endIndex - startIndex + 1;

                TAxis[] ticks = new TAxis[count];
                double lastVal = 0;
                for (int i = startIndex; i <= endIndex; i++)
                {
                    var val = axisMapping(collection[i]);
                    if(val.ToDouble() - lastVal > minStep)
                   {
                        ticks[i - startIndex] = val;
                       lastVal = val.ToDouble();

                    }
                }