Oxyplot - simple column chart - labels not appearing for highest value (ios but may happen in other systems)

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

lpinho wrote at 2014-01-09 15:46:

Hi,

I'm working with Xamarin and using this fantastic lib.
I'm using it for a few months without any problem, I'm now making my iPhone version of my application and when I plot it in the horizontal, the labels for the top value are not plotted/drawn.

I set the Frame background to green and the plot area background to white just to help to understand how I'm doing things.

Do you have any idea of what I can do to make these labels visible?
-Already tried to set padding and plot margins to 0 and I also tried not to set them at all.

Not working:

Image

Working:

Image

Code in draw method:
        public override void Draw(System.Drawing.RectangleF rect)
        {
            base.Draw(rect);

            KPIItemCollection dataSource = new KPIItemCollection();

            if (kpiCollectionPerTimeScale != null)
            {
                dataSource = GetSourceForChart();
            }

            UIColor selectedColor;
            string selectedFormat;
            Utilities.ColorAndFormatPicker(KPIType, out selectedColor, out selectedFormat);

            selectedColor = UIColor.FromRGBA(0f / 255f, 80f / 255f, 140f / 255f, 1.000f);

            PlotModel plotModel = new PlotModel();
            plotModel.TitleFont = "HelveticaNeue-Light";
            plotModel.Background = OxyColor.FromRgb(242, 242, 242);
            plotModel.PlotAreaBackground = OxyColors.White; //OxyColor.FromRgb(242, 242, 242);

            if (isPhone)
            {
                plotModel.PlotMargins = new OxyThickness(15, 0, 15, 20);
                plotModel.Padding = new OxyThickness(0, 0.25 * this.Frame.Height, 0, 0);
            }
            else
            {
                plotModel.Padding = new OxyThickness(0, 0.25 * this.Frame.Height, 0.08 * this.Frame.Width, 0);
            }
            plotModel.PlotAreaBorderThickness = 0;
            plotModel.Axes.Add(new CategoryAxis
            { 
                ItemsSource = dataSource, 
                LabelField = "Name", 
                AxislineStyle = LineStyle.Solid, 
                AxislineThickness = 0.1,
                GapWidth = 0.15,
                TickStyle = TickStyle.None,
            });

            if (isPhone)
            {
                plotModel.Axes[0].FontSize = 8;
            }

            plotModel.Axes.Add(new 
                        LinearAxis(AxisPosition.Left)
            { 
                IsAxisVisible = true,
                AxislineThickness = 1,
                TextColor = OxyColors.Transparent,
                TickStyle = TickStyle.None,
                AxislineColor = OxyColors.Transparent,

            });
            plotModel.DefaultFont = "HelveticaNeue-Light";


            plotModel.Series.Add(new ColumnSeries
            { 
                ItemsSource = dataSource, 
                ValueField = "Value", 
                FillColor = Utilities.FromUiColor(selectedColor), 
                LabelPlacement = LabelPlacement.Outside, 
                LabelFormatString = selectedFormat,
                FontSize = isPhone ? 10 : 20,
                TextColor = Utilities.FromUiColor(selectedColor),
            });

            plotModel.Update(true);
            var renderer = new MonoTouchRenderContext(UIGraphics.GetCurrentContext());
            plotModel.Render(renderer, rect.Width, rect.Height); 
}
Thanks for your help,

L. Pinho

objo wrote at 2014-01-10 09:17:

The labels of the ColumnSeries are clipped. I think the problem is the calculation of the actual max of the vertical axis. I have added issue
https://oxyplot.codeplex.com/workitem/10113

I think a workaround is to increase the MaximumPadding of the vertical axis.

objo wrote at 2014-01-10 09:18:

It's very cool to hear that it works well on iOS. Please post a link if you publish the app in the app store!

lpinho wrote at 2014-01-10 09:44:

Thanks for the workaround. I set its value to 0.05 and it looks good :)

Image

Thanks again for the help, I just love this library, I couldn't believe it when I found it, its flexible, it works and its free. This is a great asset for open source community.

Sure, when I publish it I will share it with you.