Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

How do I call functions with multiple parameters ? #67

Open
ajaybc opened this issue Mar 10, 2017 · 3 comments
Open

How do I call functions with multiple parameters ? #67

ajaybc opened this issue Mar 10, 2017 · 3 comments

Comments

@ajaybc
Copy link

ajaybc commented Mar 10, 2017

I need to use the xAxis.ticks function which accepts 2 parameters eg. .ticks(d3.time.weeks, 2). If it was just 1 parameter I could do I what I did with tick format below.
<...... xAxis={{tickFormat : function (d) { return d3.time.format('%Y-%m-%d %H:%M')(new Date(d)) }}} ../>

How do I call multiparameter functions using react-nvd3 ?

@topicus
Copy link
Contributor

topicus commented Mar 10, 2017

@ajaybc You can use a closure:

function formatter(offset) {
    return function(d) {
       return d3.time.format('%Y-%m-%d %H:%M')(new Date(d + offset));
    }
}
<...... xAxis={{tickFormat : formatter(10000)}} ../>

@ajaybc
Copy link
Author

ajaybc commented Mar 10, 2017

@topicus Thanks for the reply. But I was asking how to use .ticks(d3.time.weeks, 2) because that function expects 2 parameters. Sorry if the question seemed confusing

@topicus
Copy link
Contributor

topicus commented Mar 10, 2017

@ajaybc I think it doesn't work as d3.
Tick function it's not inherited from d3 but used inside nvd3 as you can see in the link https://github.com/novus/nvd3/blob/master/src/models/axis.js#L52

You might play with tickValues and tickFormat to achieve the same result.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants