Sweetz
Sweetz

Reputation: 342

Adding color through a function in flot graph

Can i add color dynamically by calling through a function passed by the user. I already have the options variable defined by default, the color which the user passes should sit in the option variable. Is this possible? please help

var options = {
  series: {
   lines: {
    show: true
  },
  points: {
   show: true
  },
  color: '#00c7ce'--> user should pass dynamically
},
   xaxis: {
    mode: "time",
    tickSize: [1, "month"],
    tickLength: 0,              
    },
  yaxis: {
    show: false
  }
}

};

Upvotes: 1

Views: 147

Answers (1)

Blake
Blake

Reputation: 1077

You should be able to pass a color to the options. Setup your input then use that variable as your color.

   <input id="userInput"></input>
   var usrColor = $("#userInput").val(); 

   var options = {

    series: {

    lines: { show: true},
    points: {show: true, radius: 4},
    color: usrColor
    }


};

fiddle - http://jsfiddle.net/Rnusy/4/

Upvotes: 3

Related Questions