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

Chart not in centre of view #2502

Closed
kateNgo opened this issue Jun 5, 2017 · 10 comments
Closed

Chart not in centre of view #2502

kateNgo opened this issue Jun 5, 2017 · 10 comments

Comments

@kateNgo
Copy link

kateNgo commented Jun 5, 2017

My chart is not in the centre of chart view. It is at upper half of view. Anyone help me please
This is landscape:
landscape
This is portrait
portrait

@thierryH91200
Copy link
Contributor

thierryH91200 commented Jun 5, 2017

the height of longest label "Data, Measurement..........." Corresponds to the space between the axis and the legend with
xAxis.labelPosition = .bottomInside

old bug

it's the PR #2414

Charts with PR #2414

capture d ecran 2017-06-05 a 19 26 32

Charts without PR #2414

capture d ecran 2017-06-05 a 22 07 28

remove 8 lines in charts in class BarLineChartViewBase

   internal func calculateLegendOffsets(offsetLeft: inout CGFloat, offsetTop: inout CGFloat, offsetRight: inout CGFloat, offsetBottom: inout CGFloat)
    {
.......
            case .horizontal:
                
                switch _legend.verticalAlignment
                {
                case .top:
                    offsetTop += min(_legend.neededHeight, _viewPortHandler.chartHeight * _legend.maxSizePercent) + _legend.yOffset
/*                    if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
                    {
                        offsetTop += xAxis.labelRotatedHeight
                    }*/
                    
                case .bottom:
                    offsetBottom += min(_legend.neededHeight, _viewPortHandler.chartHeight * _legend.maxSizePercent) + _legend.yOffset
 /*                   if xAxis.isEnabled && xAxis.isDrawLabelsEnabled 
                    { 
                        offsetBottom += xAxis.labelRotatedHeight    
                    }*/
                    
                    
                default:
                    break
                }
            }
        }
    }

@kateNgo
Copy link
Author

kateNgo commented Jun 5, 2017

Thanks thierryH91200.
I do not think bug is from
xAxis.labelPosition = .bottomInside. When I change this into .top or .insideTop , the problem is still:
label top

@kateNgo
Copy link
Author

kateNgo commented Jun 6, 2017

I removed 8 lines in charts in class BarLineChartViewBase as your suggestion but the problem is still. Please help me to have a look.
Actually, the isssue does not happen if I do not make a 90 of rotate label ( xaxis.labelRotationAngle = CGFloat(90))

@thierryH91200
Copy link
Contributor

Have you built charts only again?
This is the only change I made
for me no problem

capture d ecran 2017-06-06 a 07 50 27

@kateNgo
Copy link
Author

kateNgo commented Jun 6, 2017

I have just cut these chart from the screens. I also tried to fixed as your recommendation but It does not work for me. When I debug, this function is not called when these charts created.

@thierryH91200
Copy link
Contributor

If the legend is true it is forced to pass in the function for calculateLegendOffsets
try
Just to see if you are entering this function
Regardless of the result

print ( offsetBottom )
offsetBottom += min(_legend.neededHeight, _viewPortHandler.chartHeight * .... etc
// if xAxis.isEnabled && xAxis.isDrawLabelsEnabled
// {
// offsetBottom += xAxis.labelRotatedHeight
// }
print ( offsetBottom )

@thierryH91200
Copy link
Contributor

other solution

legend.enabled = false

@kateNgo
Copy link
Author

kateNgo commented Jun 7, 2017

when legend.enabled = false, the chart is at right position where I want
legendfalse

However, I need legend to show more infor about the chart like the below:
legendtrue

@thierryH91200
Copy link
Contributor

  try
// MARK: legend
       let legend = chartView.legend
       legend.enabled = true
       legend.orientation = .horizontal
       legend.horizontalAlignment = .left
       legend.verticalAlignment = .top
       legend.drawInside = true

@kateNgo
Copy link
Author

kateNgo commented Jun 7, 2017

Thanks for your time. The problem is gone. You helped me a lot.

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