question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom objects as data for datasets?

See original GitHub issue

First of all, pardon me if this feature has already been asked for or even exists. I’ve tried to search for it through the documents, the issues here and on Stack Overflow with no success. I also read the issue #937 but couldn’t find any implementation of it.

Using Chart.js I’ve encountered situations where I would like to have custom objects as data for the datasets (for example when I have custom tooltip content and would need to get a specific value to display that is not part of the plotted value). Of course if this is supported there need to be some kind of formatter function that will return what data to plot.

For example, consider this possible approach:

const chartData = [
    { name: "John", age: 25, occupation: "Teacher" },
    { name: "Eric", age: 31, occupation: "Lawyer" },
    { name: "Maria", age: 52, occupation: "Surgeon" }
];

const myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: chartData.map(data => data.name),
        datasets: [
            {
                label: 'Age',
                data: chartData,
                formatter: data => data.age
            }
        ]
    }
});

Then in, for example, the tooltip callbacks we can get the occupation of each person because its part of the data that is being supplied as parameters.

I know I can get the same results by mapping some id from the tooltip to some map which is the data but it gets very cluttered and not as consistent if you need to do this multiple times.

Is there any implemented way to achieve this today, or is it something that’s wished for?

Thanks BR

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
benmccanncommented, Jan 17, 2019

It could be nice to support data in any format and to also accept a function to map that data to our x and y values. Also related: https://github.com/chartjs/Chart.js/issues/4601

0reactions
benmccanncommented, Feb 8, 2019

@atav32 if you want to contribute to this feature, probably the best way to get started would be to start a discussion on the Slack channel (link here). @kurkle just mentioned in the Slack channel that he’s exploring a solution

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add a Custom Object to an App's Recipe and Dataset Unit
Explore the Data Added from the Custom Object in the Account Dataset · From Analytics Studio, click Browse | All Items | Datasets....
Read more >
Data bind custom objects - Visual Studio - Microsoft Learn
Bind objects as data sources in Visual Studio. Use design-time tools for working with custom objects as the data source in your application....
Read more >
Simplest way to do Object Detection on custom datasets
n this article, we are going to discuss developing custom trained object detection model using 'Detecto' which is a Python package.
Read more >
Train a custom object detection model using your data
Learn how to train a custom object detection model for Raspberry Pi to detect less common objects like versions of a logo using...
Read more >
Object Detection Model on Custom Dataset - YouTube
objectdetection #computervision #deeplearningThink of self driving car system or video security surveillance it is not enough to identify an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found