Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

v2: Assign all nextProps dataset properties to chart #109

Merged
merged 5 commits into from
May 18, 2016
Merged

v2: Assign all nextProps dataset properties to chart #109

merged 5 commits into from
May 18, 2016

Conversation

ianks
Copy link

@ianks ianks commented Apr 19, 2016

This resolves my issue posted in #84

Essentially, only the data was being updated from the datasets. This PR makes its so all of the properties from the dataset are now assigned to the new chart. This will allow for things like:

  1. Updating a label
  2. Updating a fill color
  3. etc.

It also re-introduces the redraw prop to force a re-render of the canvas.

I have only tested this with the Line chart, so if anyone has any production apps where there make use of Doughnut charts, etc. please give this branch a whirl!

@ianks ianks changed the title Assign all nextProps dataset properties to chart v2: Assign all nextProps dataset properties to chart Apr 19, 2016
@ianks
Copy link
Author

ianks commented Apr 23, 2016

Anyone give this branch a whirl yet?

@nrempel
Copy link

nrempel commented Apr 25, 2016

I've installed this branch to test out v2 functionality. So far everything works great for me.

Thanks for putting in that effort!

@stevewillard
Copy link

It's working great for me, too!

@dmhood
Copy link

dmhood commented Apr 30, 2016

Works for me as well

@gor181
Copy link
Contributor

gor181 commented Apr 30, 2016

Tested with Doughnuts and Pie charts. Works great!

this.state.chart = Chart[chartType](ctx, {
data: nextProps.data,
options: nextProps.options
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to use setState here? Thank you for this commit!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dougmolineux I would agree.
Even moving this.initializeChart from componentDidMount to componentWillMount to avoid unecessary re-render.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is possible since initializeChart relies on the chart being mounted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also might not be possible to use setState since it is asynchronous, and the chart being available is required to be sync the way the code is currently written. I'd rather not turn this PR into a full re-factor.

@gor181
Copy link
Contributor

gor181 commented May 3, 2016

@ianks can you make the changes mentioned in comments if you find them suitable? How can I assist?

@ianks
Copy link
Author

ianks commented May 3, 2016

I'll make the changes when I get home tomorrow.

@russelldc
Copy link

Does the new combining feature in v2 work with these changes?

@ianks
Copy link
Author

ianks commented May 9, 2016

@russelldc I am not sure. I have not tested it. Can you give it a try?

@eluciano11
Copy link

Hi @russelldc, I'm using combined charts with this branch and it works properly.

Example:
screen shot 2016-05-09 at 10 37 39 pm

@austinpray austinpray merged commit c711d75 into reactjs:chartjs-v2 May 18, 2016
@fscz
Copy link

fscz commented May 22, 2016

It still does not work for me. Fix: in core.js

replace

var chartDataset = chart.data.datasets[setIndex];

      for (var property in set) {
        if (set.hasOwnProperty(property)) {
          chartDataset[property] = set[property];
        }
      }

with

var chartDataset = {};

      for (var property in set) {
        if (set.hasOwnProperty(property)) {
          chartDataset[property] = set[property];
        }
      }
      chart.data.datasets[setIndex] = chartDataset;

@RezaRahmati
Copy link

I get this error using chartjs:2.1.6

core.js:60 Uncaught TypeError: (intermediate value)[chartType] is not a function
classData.initializeChart @ core.js:60

@nesbtesh
Copy link

nesbtesh commented Aug 8, 2016

How do I install chart.js-v2 with npm to help with the testing ?

@ianks
Copy link
Author

ianks commented Aug 8, 2016

@nesbtesh add this to your package.json

   "react-chartjs": "git+https://github.com/jhudson8/react-chartjs.git#chartjs-v2",

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

Successfully merging this pull request may close these issues.