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

yAxis Double values? #105

Closed
gesabo opened this issue Jul 29, 2021 · 1 comment
Closed

yAxis Double values? #105

gesabo opened this issue Jul 29, 2021 · 1 comment

Comments

@gesabo
Copy link

gesabo commented Jul 29, 2021

@willdale I can't seem to figure out what I am doing wrong here, attempting to display yAxis Labels in a double format e.g. 15.8 but they are all the same here? 🤔

image


import SwiftUI
import SwiftUICharts

struct DemoChart: View {
    
    @State var data : LineChartData = weekOfData()
    
    var body: some View {
        VStack {
            FilledLineChart(chartData: data)
                .filledTopLine(chartData: data,
                               lineColour: ColourStyle(colour: .red),
                               strokeStyle: StrokeStyle(lineWidth: 3))
                .touchOverlay(chartData: data, unit: .suffix(of: "Steps"))
                .pointMarkers(chartData: data)
                .yAxisPOI(chartData: data,
                          markerName: "Normal Range Max",
                          markerValue: 16.22,
                          labelPosition: .center(specifier: "%.0f"),
                          labelColour: Color.black,
                          labelBackground: Color(red: 1.0, green: 0.75, blue: 0.25),
                          lineColour: Color(red: 1.0, green: 0.75, blue: 0.25),
                          strokeStyle: StrokeStyle(lineWidth: 3, dash: [5,10]))
                .yAxisPOI(chartData: data,
                          markerName: "Normal Range Min",
                          markerValue: 15.78,
                          labelPosition: .center(specifier: "%.0f"),
                          labelColour: Color.white,
                          labelBackground: Color(red: 0.25, green: 0.75, blue: 1.0),
                          lineColour: Color(red: 0.25, green: 0.75, blue: 1.0),
                          strokeStyle: StrokeStyle(lineWidth: 3, dash: [5,10]))
                .averageLine(chartData: data,
                             strokeStyle: StrokeStyle(lineWidth: 3, dash: [5,10]))
                .xAxisGrid(chartData: data)
                .yAxisGrid(chartData: data)
                .xAxisLabels(chartData: data)
                 .yAxisLabels(chartData: data)  //if I comment out this line, yAxis labels are ints? 
                .yAxisLabels(chartData: data, specifier: "%.2f")
                .headerBox(chartData: data)
                .legends(chartData: data, columns: [GridItem(.flexible()), GridItem(.flexible())])
                .id(data.id)
                .frame(minWidth: 150, maxWidth: 900, minHeight: 150, idealHeight: 500, maxHeight: 600, alignment: .center)
                .padding(.horizontal)
        }
        .navigationTitle("Filled Line")
    }
    
    static func weekOfData() -> LineChartData {
        let data = LineDataSet(dataPoints: [
            LineChartDataPoint(value: 15.8, xAxisLabel: "M", description: "Monday"),
            LineChartDataPoint(value: 15.8, xAxisLabel: "T", description: "Tuesday"),
            LineChartDataPoint(value: 16.4,  xAxisLabel: "W", description: "Wednesday"),
            LineChartDataPoint(value: 15.9, xAxisLabel: "T", description: "Thursday"),
            LineChartDataPoint(value: 16.2, xAxisLabel: "F", description: "Friday"),
            LineChartDataPoint(value: 16.1, xAxisLabel: "S", description: "Saturday"),
            LineChartDataPoint(value: 15.6,  xAxisLabel: "S", description: "Sunday")
        ],
        legendTitle: "Test One",
        pointStyle: PointStyle(),
        style: LineStyle(lineColour: ColourStyle(colours: [Color.red.opacity(0.50),
                                                           Color.red.opacity(0.00)],
                                                 startPoint: .top,
                                                 endPoint: .bottom),
                         lineType: .line))
        
        return LineChartData(dataSets: data,
                             metadata: ChartMetadata(title: "Some Data", subtitle: "A Week"),
                             xAxisLabels: ["Monday", "Thursday", "Sunday"],
                             chartStyle: LineChartStyle(infoBoxPlacement: .header,
                                                        markerType: .full(attachment: .point),
                                                        xAxisLabelsFrom: .chartData(rotation: .degrees(0)), yAxisNumberOfLabels : 7,
                                                        yAxisLabelType: .numeric,
                                                        baseline: .minimumValue,
                                                        topLine: .maximumValue))
    }
}

struct DemoChart_Previews: PreviewProvider {
    static var previews: some View {
        DemoChart()
    }
}



@willdale
Copy link
Owner

The xAxisLabels are fixed as of v2.8.3.

@gesabo gesabo closed this as completed Aug 2, 2021
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

2 participants