morrisjs / morris.js

Pretty time-series line graphs
http://morrisjs.github.com/morris.js/
6.92k stars 1.23k forks source link

[Suggestion/Feature request] Bar Chart Update For Dynamic Data (data, bar color, label, ykeys) #558

Open adityasatrio opened 9 years ago

adityasatrio commented 9 years ago

Hello

i`m using bar chart from morris.js for several month, but i facing difficulty when i have dynamic data in bar chart (data, bar color, label, ykeys ). When the data become dynamic, the bar color, label and ykeys object are become dynamic too, the objects are dependent to the dynamic data.

i would suggest and it will be nice to add feature to update configuration in bar chart, or anyone can suggest me to how to do this in my case ?

nabbl commented 9 years ago

Yes... Want to know this too...

There is a setData function when the data is dynamic. But what if the xkey and/or ykeys change? Or you get new seriesdata? Destroy Chart and Draw a new one?

JelteF commented 9 years ago

You can just change the options dictionary and call setData afterwards with the data. The new options will be used then. On Feb 4, 2015 12:29 PM, "nabblschnur" notifications@github.com wrote:

Yes... Want to know this too...

There is a setData function when the data is dynamic. But what if the xkey and/or ykeys change? Or you get new seriesdata? Destroy Chart and Draw a new one?

— Reply to this email directly or view it on GitHub https://github.com/morrisjs/morris.js/issues/558#issuecomment-72839805.

nabbl commented 9 years ago

Well this seems to work JelteF. However it forces me to give the dictionary ALL of the different options (even "goal" , "smooth" and so on which should not be required...)

Here my code for better understanding:

                  var data = $scope[attrs.data],
                  xkey = $scope[attrs.xkey],
                  ykeys = $scope[attrs.ykeys],
                  labels = $scope[attrs.labels];

                  area.options =
                      {
                          data: data,
                          xkey: xkey,
                          ykeys: ykeys,
                          labels: labels
                          //goals: [50],
                          //smooth: false
                      };

                 area.setData(data);

i get an error when I dont put all the options inside: "Error: this.options.goals is undefined"

JelteF commented 9 years ago

Just set the keys in the .options dictionary instead of replacing it. That way it will work. On Feb 4, 2015 4:01 PM, "nabblschnur" notifications@github.com wrote:

Well this seems to work JelteF. However it forces me to give the dictionary ALL of the different options (even "goal" , "smooth" and so on which should not be required...)

Here my code for better understanding:

              var data = $scope[attrs.data],
              xkey = $scope[attrs.xkey],
              ykeys = $scope[attrs.ykeys],
              labels = $scope[attrs.labels];

              area.options =
                  {
                      data: data,
                      xkey: xkey,
                      ykeys: ykeys,
                      labels: labels
                      //goals: [50],
                      //smooth: false
                  };

             area.setData(data);

i get an error when I dont put all the options inside: "Error: this.options.goals is undefined"

— Reply to this email directly or view it on GitHub https://github.com/morrisjs/morris.js/issues/558#issuecomment-72869100.