Feature request: Adding new datasets at offset from origin in original chart
See original GitHub issueHi, I’m new to using Chart.JS and I’m a total noob in JS (but trying to learn) so please bear with me if this is somehow inappropriate.
For complete description of the rationale to this request please see this Q at stackoverflow.
I was trying to add some statistical projections (new datasets, both bar and lines) to the end of current datasets (combined bar/lines) but ran into some issues. I believe some of them can be fixed quickly and could make a good new feature.
First is the adding of multiple values to either labels or an existing dataset. I solved that as shown below, and I believe this could be implemented in a similar way by allowing [value1, value2,...,value_n]
in the push()
with evaluating if there are multiple values. Not very happy with repeating update()
for every step though.
var futureValues = [55618.9002849,55762.088929589,55905.277574278];
var futureLabels = [2017,2018,2019];
function addData() {
var index, count;
for (index = 0, count = futureLabels.length; index < count; ++index) {
myChart.data.labels.push(futureLabels[index]);
myChart.data.datasets[1].data.push(futureValues[index]);
}
myChart.update();
}
Second is the general issue of not being able to specify a “starting point” for datasets when plotting multiple sets with different origins. I don’t know if maybe there is a way but then it should be added to the documentation.
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (6 by maintainers)
You don’t need to call
myChart.update()
inside thefor-loop
. Just add all the values and update once. Theupdate
function tellsChartjs
you’re done modifying things and you want to the graphical result.Adding
min/max
values to your configuration might help to modify thestart/end
points of your x-axes (http://www.chartjs.org/docs/latest/axes/cartesian/time.html?h=min).If the vertical scaling is a problem, you could add multiple y-axes for the several datasets.
I think based on the conversation here, this is resolved and no further actions are needed