ios – Swift chart legend not exhibiting

Spread the love

For the swift chart under, the chart legend just isn’t exhibiting. I attempted so as to add .chartForgroundStyle() modifier for Value and Sentiment, nevertheless it causes the construct to fail for the error “Day trip for a thunk to construct”. How do I repair this and add a legend for the 2 Line Marks?

struct Entry {
    let date: Date
    let closePrice: Float
... View
    @State var entries: [Entry]
    @State var sentiments: [Entry]

Chart {
                ForEach(self.sentiments, id: .date) { sentiment in
                        x: .worth("Date",,
                        // TODO: take away -1 for actual sentiment information
                        y: .worth("Sentiment", sentiment.closePrice - 1),
                        sequence: .worth("Sentiment", "B")
                ForEach(self.entries, id: .date) { entry in
                        x: .worth("Date",,
                        y: .worth("Value", entry.closePrice),
                        sequence: .worth("Value", "A")
                    let curGradient = LinearGradient(
                        gradient: Gradient (
                            colours: [
                        startPoint: .high,
                        endPoint: .backside
                        x: .worth("Date",,
                        yStart: .worth("Value", spherical(minY - ((maxY - minY) / 100) * 20)),
                        yEnd: .worth("PriceEnd", entry.closePrice)
//            .chartForegroundStyleScale(["Price": .green, "Sentiment": .blue])
            .chartLegend(place: .high, alignment: .heart)
            .chartYScale(area: minY - ((maxY - minY) / 100) * 20...maxY + ((maxY - minY) / 100) * 20)
                AxisMarks(values: .stride(by: .day))
                { date in
                    AxisValueLabel(format: .dateTime.weekday(.slim), centered: true)
            }.chartYAxis {
                AxisMarks(place: .main)

Edit: For context, the chart plots inventory value and sentiment information to see how properly sentiment information predicts the worth. The structs for entries and sentiments are added above.

Leave a Reply

Your email address will not be published. Required fields are marked *