-
Notifications
You must be signed in to change notification settings - Fork 324
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
Adding an average line #8
Comments
@PAULUSfranCIRCUS you would need to calculate the average yourself, but once that is done this is doable using this plugin |
could you show us an example of the Data that you are sending to chartJS? for example with my data object I actually send chartJS an object with an array of annotations, then just use that for my annotations. |
Thanks Adondriel! The data that I want to send is from the example within the Embed Api plugin for Google Analytics, that uses Chart.js https://ga-dev-tools.appspot.com/embed-api/third-party-visualizations/ within the first graph i would like to include an average line for both data arrays (first week and last week). Which is within this line of code:
} |
The way you are creating your chart seems very odd to me.
Where the annotations are an option on your grid themselves. Make sure you are using chartjs v2. You will also need to calculate your averages from the data before creating your annotations. |
@PAULUSfranCIRCUS Ah yes, Just checked the page you were talking about and yea, they use chartjs 1.0.2 which is the old version. This plugin is for 2.0 as far as I can tell (since it uses 2.0's plugin system) My above example is a fairly good idea for what a simple(or complex for some I guess) chart creation script would look like with 2.0. |
Great! Well, yes I am bound by the quirks of the Google Analytics embed API. In this particular case it also uses moment.js so maybe that's making it look odd. Thanks for noticing that it is 1.0.2 and not the 2.0 version. Leaves me out of luck i guess |
You could probably update that version couldn't you? can you not edit the scripts they are referencing? Also if not I found this stackoverflow thread when I was looking into this for 2.0 and the solution I found was for v1. http://stackoverflow.com/questions/31092489/chart-js-draw-horizontal-line The answer from dFelinger is what I would suggest (since it supports multiple lines.) |
I realize this is a bit old, but just putting this out there for future reference. If you need an average line, you can do this without the annotation plugin simply by adding another data series computed from your other data series using https://github.com/Tom-Alexander/regression-js. |
I spend hours searching whether it's possible to add a horizontal line that has a y value that is based on the average of another data array. I came to this awesome plugin to the Chart.js but still couldn't find this function.
Is this somehow possible? Much appreciated!
The text was updated successfully, but these errors were encountered: