Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to expose update_values and add_data_point functions? #65

Closed
ianjdarrow opened this issue Nov 10, 2017 · 5 comments
Closed

How to expose update_values and add_data_point functions? #65

ianjdarrow opened this issue Nov 10, 2017 · 5 comments
Labels

Comments

@ianjdarrow
Copy link

When creating a new Chart object per the docs, the chart renders correctly but the functions referenced in the docs (including update_values and add_data_point) don't appear to be included in the newly-created object. This is true for both LineChart and BarChart, both of which inherit AxisChart where the desired methods live. Grateful for any assistance folks can provide in exposing these functions.

@pratu16x7
Copy link
Contributor

@ianjdarrow Hmm, would be easier to tell by seeing the usage. Can you share your code?

@ianjdarrow
Copy link
Author

ianjdarrow commented Nov 10, 2017

Of course - thanks. Here's the code:

import Chart from "frappe-charts/dist/frappe-charts.min.esm";

const owners = 
    [{ name: 'Ian', shares: 60 },
     { name: 'Ben', shares: 50 }];

const dataset = { 
    labels: owners.map(owner => owner.name),
    datasets: [{ values: owners.map(owner => owner.shares)}] 
};

const chart = new Chart({
    parent: '#chart',
    data: dataset,
    type: 'bar',
    height: 250,
});

As I mentioned, the chart renders properly, but the desired methods don't seem to be exposed. The chart displays properly and console.log(chart) yields a number of properties, but nothing from the API.

@pratu16x7
Copy link
Contributor

pratu16x7 commented Nov 12, 2017

@ianjdarrow You'll find them quite down nested in the prototype chain of the Chart object in the console output, given the inheritance. Aside, have you tried actually running the function? I assumed that the functions themselves didn't work.

@ianjdarrow
Copy link
Author

@pratu16x7  thanks so much! Knowing that the functions were nested way down the prototype chain, I was able to confirm that they was there. I have this working now. Not 100% sure what the issue was – probably my own stupidity – but very grateful for your help and your work on this library.

@pascalw
Copy link

pascalw commented Jan 30, 2018

It looks like these functions are not available on all chart types. For example PercentageChart extends from BaseChart which doesn't have the update_values function. Is there a way to dynamically update a PercentageChart?

I'm now using this, which seems to work:

this.frappe.data = nextProps.data;
this.frappe.refresh(true);

Is this the right way to do it? Would be nice if all charts could implement these functions for a consistent API.

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

No branches or pull requests

3 participants