How to change the text color for SwiftUI Chart's legend text?

For a macOS app using Xcode 14.1. I have a bar chart with two bars for each interval. See screen chart below. I want to change the "Invoice" and Payments" text I can't seem to find a modifier for the Legend text. How do you change the text color for SwiftUI Chart's legend text?

It may not be the best answer, but one option is to use your own SwiftUI View in the legend, as the content can be specified:

        .chartLegend(position: .bottom, alignment: .top, spacing: 16) {
            Text("Invoices Payments").foregroundColor(.blue) // just an example View
        }

You can group each Circle / Text entry into a LegendItem view, and render a collection of two (in this case). In this case it doesn't buy too much, compared to just using SwiftUI. I'll add a better solution if I find one.

I just checked, this legend label color is currently driven by secondaryLabelColor (described at developer.apple.com and referenced in the Color section of Apple's Human Interface Guidelines), so the specific color value depends on whether the theme is dark or light (except on Apple Watch). So, using content mentioned above is the way to go. However, consider that ideally there's stylistic unity across multiple charts, apps from different makers and between charts and other parts of the application. So it's a good idea to consider using the default, and file feedback if it doesn't seem sufficient, explaining what you miss in the current version, and why, and what option would fit the bill.

Thanks for the reply, I have been doing some research on secondaryLabelColor and can't find any examples as well as attempting to add it to my swiftUI view but not really sure how to code. Do you have any usage examples of this?

Also, how did you go about figuring out the legend color is driven by secondaryLabelColor.

Thanks

How to change the text color for SwiftUI Chart's legend text?
 
 
Q