Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a BarChart from fetched data from CoreData?

I’m trying to create a barchart from fetched data from a CoreData model.
I’m trying to use https://github.com/AppPear/ChartView in particular the release v1.5.5.
The request returns me from the database an array of Entities, let’s say its [Entity]. (Entity has two attributes a date and an Int64)
I want to use this data to create the barchart with the labels created by like the example on the github readme :

BarChartView(data: ChartData(values: [("2018 Q4",63150), ("2019 Q1",50900), ("2019 Q2",77550), ("2019 Q3",79600), ("2019 Q4",92550)]), title: "Sales", legend: "Quarterly") // legend is optional

In Particular the init of ChartData I wanna use is public init<N: BinaryInteger>(values:[(String,N)])

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Now I tried to map (using .map() ) the array that the fetchRequest gives to me but unsuccessfully.
How do I transform the data from the array, into the required signature of the init of ChartData ?
Or do you have any other suggestion in order to accomplish this task, like some order packages I could use instead of the one mentioned before?

>Solution :

Have you tried ChartData(values: fetchRequestResult.map { ("\($0.date)", $0.int64value) }?
Regarding other libs, you should have a look into Charts. It’s in more wide known and used by a lot of apps

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading