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

When the X-Axis's text is too long, it will cover the radar chart. #1143

Closed
GitHubWanglei opened this issue Jun 15, 2016 · 8 comments
Closed

Comments

@GitHubWanglei
Copy link

GitHubWanglei commented Jun 15, 2016

When the X-Axis's text is too long, it will cover the chart.
1ce4a7df-1110-4640-916b-99ffd4410354
How can I solve this problem?

@liuxuan30
Copy link
Member

check out x axis renderer of radar chart renderAxisLabels(), I am not sure if this is by design or a bug

@GitHubWanglei
Copy link
Author

GitHubWanglei commented Jun 16, 2016

I have set the label position of X-Axis in my objective-c project like this:

//set xAxis
ChartXAxis *xAxis = self.radarChartView.xAxis;
xAxis.labelFont = [UIFont systemFontOfSize:12];
xAxis.labelTextColor = [self colorWithHexString:@"#057748"];
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.wordWrapEnabled = YES;
xAxis.labelWidth = 100;

But it had no effect.How can I set the label position correctly? Have any other properties or methods to solve this problem?

@liuxuan30
Copy link
Member

liuxuan30 commented Jun 16, 2016

I think it's about the anchor point of the label, so you may want to take a look at how the origin point is calculated, radar chart maybe a little tricky, because it could rotates, so just take a look at renderAxisLabels() if you can make some change first.
@danielgindi what you think, bug or by design?

@GitHubWanglei
Copy link
Author

In the ChartXAxisRendererRadarChart.swift file, I found the renderAxisLabels() method, in this method, I found some lines like this:

let p = ChartUtils.getPosition(center: center, dist: CGFloat(chart.yRange) * factor + xAxis.labelRotatedWidth / 2.0, angle: angle)

drawLabel(context: context, label: label!, xIndex: i, x: p.x, y: p.y - xAxis.labelRotatedHeight / 2.0, attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor], anchor: drawLabelAnchor, angleRadians: labelRotationAngleRadians)

I found the point p is thie X-Axis label's center, so, I think the point p should add some offset relative to the radarChartView's center, but how can I get the radarChartView's center.
The point p position and the problem in the image like this:
9e27b1b1-0974-4943-b2ae-955faf46dcaa

@liuxuan30 @danielgindi Can you fix this issue?

@GitHubWanglei
Copy link
Author

I found when the label is English text, it's no issue. like this:
85d20bdd-dcd6-40b0-80c1-306ab2fa349d
But when I use Chinese text, the issue will occur, like this:

1b3e69f2-dc21-4dc1-b7c9-640f56868532
What's wrong with this? @liuxuan30 @danielgindi

@liuxuan30
Copy link
Member

hey you don't have to "@" at anyone, someone seeing this will try to help.
I am not sure why right now, maybe the text render engine, I don't know.

Since you know where is the code, you can try first...

Quite busy recently

@GitHubWanglei
Copy link
Author

Thank you for your reply.

@danielgindi
Copy link
Collaborator

You have two questions in your screenshots:

  1. How can I get this center? - Call centerOffsets on the chart view, or contentCenter on the viewport.
  2. Why the missing offsets of the labels? Well, this must be how the text renderer handles the Chinese glyphs. It is given the correct instructions, as you can see with English, but renders incorrectly. It could be a bug in how CoreGraphics draws Chinese glyphs, but it is most probable that it is a bug in the specific font. So I would try a different font.

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