c3js / c3js/c3

Load javascript array to chart using function parameter as dataset name

Open
#2,628 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
9.3k
Forks
1.4k
Avg merge
6d 16h
Merged PRs (30d)
1

Description

Hi,

I would like to call an onclick function to load javascript arrays on an existing chart. This works fine if I unshift the dataset name to the start of javascript containing my dataset. But that means I've mutated my dataset. What I'd like to do is pass the dataset name and dataset to a function and do something like this:

function addDatasetFromArray(datasetId, datasetArray) {
chartDailyDataset.load({
columns: [datasetId, datasetArray]
}
)
}

but this doesn't work.

I could create a local copy of the array and unshift the dataset name to the start of the array but ideally this extra processing wouldn't be necessary.

If I try this:

function addDatasetFromArray(datasetId, datasetArray) {
chartDailyDataset.load({
json: {
datasetId: datasetArray,
}
}
)
}

the dataset array displays ok but the chart calls the dataset "datasetId", not the string in the function parameter datasetId. In another helper function I'm passing the dataset name in the datasetId function parameter to unload charts so that works OK. And the Firefox debugger shows the string passed correctly in the function parameter above.

I think I could maybe setup a json object with name and array and use that but again that's extra processing I'd like to avoid if possible.

So is there an existing way to do pass the dataset name as per my example above? I haven't been working with c3.js long so quite possible I've missed it. If not, is this something that could be added?

Thanks

David

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.