Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll UIImageView on X-axes along with x-vals #1775

Closed
walinaqvi opened this issue Nov 3, 2016 · 6 comments
Closed

Scroll UIImageView on X-axes along with x-vals #1775

walinaqvi opened this issue Nov 3, 2016 · 6 comments

Comments

@walinaqvi
Copy link

walinaqvi commented Nov 3, 2016

I just tried to add UIImageView on x-axes along with x-vals ,i get x coordinate of image from getPosition method of BarChartView and i'm hardcoding y coordinate something like this :

CGPoint imagePos = [_chartView getPosition:[yVals objectAtIndex:i] axis:AxisDependencyRight]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(imagePos.x, 30, 10, 10)];

and then i'm adding these images on BarChartView:
[_chartView addSubview:imageView];
its working fine when im not zooming or scrolling the Chart,the moment i'm scrolling the chart these images are fixed on same place and not scrolling along with X-Axes labels .

Is there any public property like UIScrollView,Where should i add these images ,So these images also scroll along with Bars of graph.

@liuxuan30
Copy link
Member

liuxuan30 commented Nov 9, 2016

that's because you add them with static coordinates and never update them. You should check how the renderer works. Basically, every time you scroll, you should update. However I don't think using a view is a good option.

@waliHaider
Copy link

Can you tell me any other approach or is there any class that can be subclass to achieve this?

@liuxuan30
Copy link
Member

I would say use CoreGraphics to do this, just like how this library do. You can take a look at x axis render how it draws the label

@walinaqvi
Copy link
Author

walinaqvi commented Nov 11, 2016

I just added code to draw image in drawLabel method of ChartXAxisRenderer and it worked.

Thanks Xuan

@ghost
Copy link

ghost commented Nov 14, 2016

@walinaqvi : Can you share your code with modification ? Thank you

@walinaqvi
Copy link
Author

In ChartXAxisRenderer.swift i modified the signature of drawLabel method also added code to draw image

internal func drawLabel(context context: CGContext, label: String, xIndex: Int, x: CGFloat, y: CGFloat, align: NSTextAlignment, attributes: [String: NSObject], constrainedToSize: CGSize, img:UIImage)
    {

        let rect = CGRect(x: x, y: y, width: 10, height: 10)
        img.drawInRect(rect);


        let ynew = y+15;
        let formattedLabel = _xAxis.valueFormatter?.stringForXValue(xIndex, original: label, viewPortHandler: viewPortHandler) ?? label
        ChartUtils.drawMultilineText(context: context, text: formattedLabel, point: CGPoint(x: x, y: ynew), align: align, attributes: attributes, constrainedToSize: constrainedToSize)

    }

and in ChartXAxisRendererBarChart.swift i passes appropriate image while calling method drawLabel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants