mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-13 11:46:55 +01:00
Add chart data property setter and unit tests
Chart data can now be entirely replaced using `chart.data = {...}` thanks to the new property setter (instead of using `chart.config.data = {}`). Also update the documentation, as suggested by @ldaguise and @kennethkalmer, with a note about versions prior 2.6.
This commit is contained in:
committed by
Evert Timberg
parent
85ee592b2a
commit
cc90c5c643
@@ -57,6 +57,25 @@ describe('Chart', function() {
|
||||
expect(chart.data.datasets[1].data).toBe(ds1.data);
|
||||
});
|
||||
|
||||
it('should define chart.data as an alias for config.data', function() {
|
||||
var config = {data: {labels: [], datasets: []}};
|
||||
var chart = acquireChart(config);
|
||||
|
||||
expect(chart.data).toBe(config.data);
|
||||
|
||||
chart.data = {labels: [1, 2, 3], datasets: [{data: [4, 5, 6]}]};
|
||||
|
||||
expect(config.data).toBe(chart.data);
|
||||
expect(config.data.labels).toEqual([1, 2, 3]);
|
||||
expect(config.data.datasets[0].data).toEqual([4, 5, 6]);
|
||||
|
||||
config.data = {labels: [7, 8, 9], datasets: [{data: [10, 11, 12]}]};
|
||||
|
||||
expect(chart.data).toBe(config.data);
|
||||
expect(chart.data.labels).toEqual([7, 8, 9]);
|
||||
expect(chart.data.datasets[0].data).toEqual([10, 11, 12]);
|
||||
});
|
||||
|
||||
it('should initialize config with default options', function() {
|
||||
var callback = function() {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user