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

LineChartRenderer add options to drawValues #3467

Open
1 task done
igrrik opened this issue May 22, 2018 · 4 comments
Open
1 task done

LineChartRenderer add options to drawValues #3467

igrrik opened this issue May 22, 2018 · 4 comments

Comments

@igrrik
Copy link

@igrrik igrrik commented May 22, 2018

What did you do?

I implemented LineChart in my project and tried to subclass LineChartRenderer in order to change offset of values that are drawn in func drawValues(context: CGContext). The problem is that the only option is to copy all code of this method from LineChartRenderer into my subclass, but there are warnings, because _xBounds property has internal protection level.

What did you expect to happen?

I would like to be able to control value position of DataSet entries on LineChart. For example, in LineChartRenderer in func drawValues(context: CGContext) there is an alignment option, which is always set to .center, but I need to set it to left.

if dataSet.isDrawValuesEnabled {
                        ChartUtils.drawText(
                            context: context,
                            text: formatter.stringForValue(
                                e.y,
                                entry: e,
                                dataSetIndex: i,
                                viewPortHandler: viewPortHandler),
                            point: CGPoint(
                                x: pt.x,
                                y: pt.y - CGFloat(valOffset) - valueFont.lineHeight),
                            align: .center,
                            attributes: [NSAttributedStringKey.font: valueFont, NSAttributedStringKey.foregroundColor: dataSet.valueTextColorAt(j)])
                    }

Also it would be great to change offset for X and Y position.

Is there any option to do that without making fork?

Charts Environment

**Charts version/Branch/Commit Number: 3.1.1 Release **
Xcode version: 9.3.1
Swift version: 4.1
Platform(s) running Charts: iOS
macOS version running Xcode: 10.13.4

@pmairoldi
Copy link
Collaborator

@pmairoldi pmairoldi commented May 22, 2018

Thanks for the detailed report! We could add an option for text alignment. What exactly are you trying to achieve? Maybe there is already a way to do so without modifying the library.

@igrrik
Copy link
Author

@igrrik igrrik commented May 30, 2018

I couldn't find way to achieve it without modifying library. I've implemented this functionality in my fork, so I can create Pull Request.

@pmairoldi
Copy link
Collaborator

@pmairoldi pmairoldi commented Jun 8, 2018

Sounds good!

@antonbremer
Copy link

@antonbremer antonbremer commented Jun 26, 2018

Would be great indeed to be able to change value offsets.
For example, I would like to plot my values BELOW my scatter chart shapes, rather than above them.
Is this possible at all with the current library? From reading this ticket I get it's not at the moment..

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

No branches or pull requests

3 participants