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

Problem with BalloonMarker in lineChart #2892

Closed
Schabaani opened this issue Oct 17, 2017 · 8 comments
Closed

Problem with BalloonMarker in lineChart #2892

Schabaani opened this issue Oct 17, 2017 · 8 comments

Comments

@Schabaani
Copy link

I am using this version of BalloonMarker.
You see 3 images below. The last image doesn't show very well. What change in codes can solve my problem?

screen shot 2017-10-17 at 10 10 00 am

screen shot 2017-10-17 at 10 09 53 am

screen shot 2017-10-17 at 10 10 05 am

@Schabaani
Copy link
Author

Schabaani commented Oct 17, 2017

I don't know why chart is nil.

let chart = self.chartView
So lines below are false:

        else if chart != nil && origin.x + width + offset.x > chart!.bounds.size.width
        {
            offset.x = chart!.bounds.size.width - origin.x - width - padding
        }


       else if chart != nil && origin.y + height + offset.y > chart!.bounds.size.height
        {
            offset.y = chart!.bounds.size.height - origin.y - height - padding
        }

I change to:

       else if  origin.x + width + offset.x > UIScreen.main.bounds.width
        {
            offset.x = UIScreen.main.bounds.width - origin.x - width - padding
        }

        else if  origin.y + height + offset.y > UIScreen.main.bounds.height
        {
            offset.y = UIScreen.main.bounds.height - origin.y - height - padding
        }

and it is working. Any suggestion why chart is nil?

@Schabaani
Copy link
Author

I guess there is a bug in BalloonMarker initializer. It needs one more parameter for chartView.

    public init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets, chart: Charts.ChartViewBase)
    {
        super.init()
        
        self.color = color
        self.font = font
        self.textColor = textColor
        self.insets = insets
        self.chartView = chart
        
        _paragraphStyle = NSParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle
        _paragraphStyle?.alignment = .center
    }

When initializing marker, pass your chart as last parameter:

let marker = BalloonMarker(color: UIColor.red, font: UIFont.systemFont(ofSize:12.0), textColor: UIColor.darkText, insets: UIEdgeInsetsMake(8.0, 8.0, 20.0, 8.0), chart: chartView)

and now self.chart is not nil

@thierryH91200
Copy link
Contributor

you have forget
chartView.marker = marker
marker.chartView = chartView

@thierryH91200
Copy link
Contributor

thierryH91200 commented Oct 17, 2017

try my balloon marker

RectMarker.swift.zip

    let marker = RectMarker(color: #colorLiteral(red: 0.9994240403, green: 0.9855536819, blue: 0, alpha: 1), font: NSFont.systemFont(ofSize: CGFloat(12.0)), insets: NSEdgeInsets(top: 8.0, left: 8.0, bottom: 4.0, right: 4.0))
    marker.chartView = chartView
    marker.minimumSize = CGSize(width: CGFloat(60.0), height: CGFloat(30.0))
    chartView.marker = marker

and change
set1 = LineChartDataSet(values: yVals1, label: "what you want")

capture d ecran 2017-10-17 a 13 24 39

capture d ecran 2017-10-17 a 13 24 32

@Schabaani
Copy link
Author

Thanks, I forget marker.chartView = chartView.
I guess it is better to set this value in initializer, like me. This is safer.
Thanks again

@liuxuan30
Copy link
Member

liuxuan30 commented Oct 27, 2017

be careful if creating a retain cycle here marker.chartView = chartView

@fabien-ml
Copy link

MarkerImage class have @objc open weak var chartView: ChartViewBase?' it avoid the retain cycle problem , no ?

@PrashanthPasi
Copy link

PrashanthPasi commented Nov 9, 2020

Finally one Line of code save 😀
marker.chartView = chartView

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

5 participants