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

Such a difficult chart, can be realized? #1183

Closed
shenyufei opened this issue Jun 28, 2016 · 2 comments
Closed

Such a difficult chart, can be realized? #1183

shenyufei opened this issue Jun 28, 2016 · 2 comments

Comments

@shenyufei
Copy link

72d54e42-c2f0-4194-aa18-c23a34bdfe7f

I believe we are smart people,can understand what I am talking about the effect.

@liuxuan30
Copy link
Member

liuxuan30 commented Jun 30, 2016

yes you can. however this requires you to understand the code and modify it. ChartsDemo can show a similar one already, just some texts has different offset, and a small line on the axis, and the unit.

Just try read the code about the axis renderer, and the bar chart renderer's drawValues()

As you see, people are asking for hundreds of customizations, and with just a few of us, we can't satisfy them all. You are more than welcome to contribute when you think an enhancement or feature is cool that may help others and file a PR for it.

@dxclancy
Copy link

dxclancy commented Jul 14, 2016

The only thing in your chart that the existing code does not do, I think, is draw the bar chart chunk values (your percentages) in the middle of the color and then the last one at the top.

To achieve this I changed the code in BarChartRenderer as in the following (this also makes it so that the value color is used for the value text and not the bar text, so that you can change your percentages to colors that contrast better with the chart colors):

+                            var previousY = CGFloat(0);
                             for k in 0 ..< transformed.count
                             {
                                 let x = valuePoint.x
                                 let y = transformed[k].y + (vals[k] >= 0 ? posOffset : negOffset)

                                 if (!viewPortHandler.isInBoundsRight(x))
                                 {
                                     break
                                 }

                                 if (!viewPortHandler.isInBoundsY(y) || !viewPortHandler.isInBoundsLeft(x))
                                 {
                                     continue
                                 }
+                                var heightRect = CGRect(x:0,y:0,width: 0, height: vals[k])
+                                trans.rectValueToPixel(&heightRect)
+                                let height = heightRect.height

+                                var textHeightAdjustment = valueTextHeight
+                                var drawY = y + (height / 2.0) - textHeightAdjustment
+                                if (k == (transformed.count - 1 ))
+                                {
+                                    textHeightAdjustment = valueTextHeight * 2
+                                    drawY = y - textHeightAdjustment;
+                                }
+//                                drawY = y
                                 drawValue(context: context,
                                     value: formatter.stringFromNumber(vals[k])!,
                                     xPos: x,
-                                    yPos: y,
+                                    yPos: drawY,
                                     font: valueFont,
                                     align: .Center,
-                                    color: dataSet.valueTextColorAt(j))
+                                    color: dataSet.valueTextColorAt(k))
+                                previousY = y;
                             }

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