|
Hello. I have the working chart below that shows 'revenue' and 'visits' as two seperate barmarks in a chart :) I would like to customize each bar though. i.e. I would like to add a Gradient to each of 'revenue' and 'visits', i'd also like to annotate them with the value represented by the barmark. I think I need to do somethibg with chartForegroundStyleScale, but i'm unsure of the syntax. Any ideas.
|
|
The Bar Gradient
The
Here my project
PS change your |
|
SOLVED! The Amazing @NigelGee strikes again. I can't thank you enough, i've learned so much from your answers here on HWS. I don't know if you're involved in the HWS business but thanks to your answers I think it's about time to get a subscription. |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Thank you for the question I would hide the legend and put the
and the add this to after the
PS now you can change the
so when you want to change the gradient you only have to do in one place PS if you look at the bottom of the post you see a heart, a checkmark and a link. If you click the check mark on the post that solve it then will display green border and put SOLVED it the title |
|
Thanks, i'll take a look at these. If I may i'd like to add another question to this thread, it could also be a useful for other readers. I've swapped the X and Y axis because the chart is displayed in a sheet in portrait mode. As you can tell its displaying visits which is a simple integer and revenue that's and integer but I need a currency symbol on the annotation. I can"t see how I can have one axis (visits) without a currency symbol and revenue with a currency symbol. I've been messaging with both .annotation and .chartForegroundStyleScale but no success so far. And the second and final question concerns the X axis the value of Revenue can be in the millions. The X axis starts at 0, then has points 10E6, 20E6. I simply want an x axis that starts at zero and end at the higest value barmark. Any ideas? |
|
In both closures you can use |
|
Hi @Hatsushira. Maybe I was not clear in my description. The annotation I refer to is including a value against a barmark in a bar chart. I wish I could post an image here but I think you see what I mean. So I have 12 months, for each month a bar showing Revenue and one showing Visits. I want a value with a currency symbol against the Revenue bar but not the visits. Maybe the following help..
|
|
Ah, now I get it. You could use a if statement in your annotation and check for the type. I'm currently not at Xcode so I can't try it myself. For your question about the value range you should be able to use.
|
|
@Hatsushira. Hi. Yes that what I thought but i'm unsure what condition I would use to determine if the barmark is Revenue or Visit. I'll look into .chartXScale(domain: 0...yourMaxValue). Thank you. All of this is pretty new and i've not come across this modifier until now :) |
|
You have a type property you use for grouping. This should give you the option to decide to show the currency symbol. Pseudocode here for your annotation:
For me this is all new, too. Have you seen Sean Allen's SwiftUI Bar Chart with Customizations |
|
Hi The Chart y axis is months not Vsits/Revenue and the x axis is the scale of the maximum amount number. This is why in my example i used the magic number of 1000 to make the two bars be in range of each other. So i replaced the 1000 with a multiply
With regards the annotation you can do this
PS found the you can customise the legand with this
So while project
PS preview timeout I think it because of the Gradient but does run in simulator. |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.