assert.equal(6, g.getValue(3, 0));
});
+it('should throw on strings in native format', () => {
+ assert.throws(() => {
+ new Dygraph('graph', [['1', '10'], ['2', '20']])
+ }, /expected number or date/i);
+
+ assert.throws(() => {
+ new Dygraph('graph', [[new Date(), '10'], [new Date(), '20']])
+ }, /expected number or array/i);
+});
+
var assertData = function(g) {
var expected = dataArray;
And error bars will be calculated automatically using a binomial distribution.
For further documentation and examples, see http://dygraphs.com/
-
*/
import DygraphLayout from './dygraph-layout';
return ret;
};
+// In native format, all values must be dates or numbers.
+// This check isn't perfect but will catch most mistaken uses of strings.
+function validateNativeFormat(data) {
+ const firstRow = data[0];
+ const firstX = firstRow[0];
+ if (typeof firstX !== 'number' && !utils.isDateLike(firstX)) {
+ throw new Error(`Expected number or date but got ${typeof firstX}: ${firstX}.`);
+ }
+ for (let i = 1; i < firstRow.length; i++) {
+ const val = firstRow[i];
+ if (val === null || val === undefined) continue;
+ if (typeof val === 'number') continue;
+ if (utils.isArrayLike(val)) continue; // e.g. error bars or custom bars.
+ throw new Error(`Expected number or array but got ${typeof val}: ${val}.`);
+ }
+}
+
/**
* The user has provided their data as a pre-packaged JS array. If the x values
* are numeric, this is the same as dygraphs' internal format. If the x values
return null;
}
+ validateNativeFormat(data);
+
var i;
if (this.attr_("labels") === null) {
console.warn("Using default labels. Set labels explicitly via 'labels' " +
<script type="text/javascript">
g2 = new Dygraph(document.getElementById("graphdiv2"),
[
- [1,10,100],
- [2,20,80],
- [3,50,60],
- [4,70,80]
+ ['1', '10', '100'],
+ ['2', '20', '80'],
+ ['3', '50', '60'],
+ ['4', '70', '80']
],
{
labels: [ "x", "A", "B" ]