GithubHelp home page GithubHelp logo

Comments (4)

ivnsch avatar ivnsch commented on August 23, 2024

You don't have to use map. The chart just needs an array of ChartAxisValue. How you generate this array is up to you. The examples use map because it makes the code easier to read (this has a performance penalty though, since it iterates over all the array, but it's irrelevant for small datasets).

For numbers you can use ChartAxisValueFloat, where you can pass a formatter. ChartAxisValue should not be instantiated directly (this is like an "abstract class" if you are familiar with that). This class doesn't have any information about how to display the double, if it generated labels and you pass e.g. 2.3423422342425 it would show all the decimal digits and that's in most cases not what you want.

So you can simply:

let xValues = [
    ChartAxisValueFloat(1),
    ChartAxisValueFloat(2.5),
    ChartAxisValueFloat(3)
]

(This will use the default formatter which shows max 2 fraction digits - if you need something different, pass it to the initializer).

from swiftcharts.

sniis84 avatar sniis84 commented on August 23, 2024

I've tried several times but your example helped me figuring out that a CGFloat is needed by the library.
I just had to use CGFloat(X[i]) in my code to solve it.
I suggest to add documentation about that in the method definition while the use types in the commands

from swiftcharts.

ivnsch avatar ivnsch commented on August 23, 2024

Actually, you have a point - there's no real reason to use CGFloat here. Somebody changed recently the internal representation to Double (because CGFloat causes problems with dates), so it's converted to Double anyways. It makes sense to replace ChartAxisValueFloat with ChartAxisValueDouble. I'll leave this open as an enhancement issue.

Also, the behaviour/documentation of ChartAxisValue has to be improved, such that it's clear that it's not meant to be instantiated directly.

from swiftcharts.

ivnsch avatar ivnsch commented on August 23, 2024

Improvements implemented

from swiftcharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.