nerffei opened a new issue #10223: Echartjs 对TypedArray的支持问题 URL: https://github.com/apache/incubator-echarts/issues/10223 ### Version 4.2.1 ### Steps to reproduce 我需要用echarts渲染一些折线图,但是我的数据源是TypedArray,我的配置大概如下面 ```javascript { xAxis: { type: 'value' }, yAxis: { type: 'value' }, dataset: { dimensions:[ { name: 'x', type: 'float'}, { name: 'y', type: 'float'} ], source: [ x, y ], }, series: { type: 'line', sampling: 'max', encode: { 'y': 'y', 'x': 'x' }, seriesLayoutBy: 'row' } } ``` 其中**dataset.source**中的**x**,**y**是**float64Array** ### What is expected? 正确的显示折线图 ### What is actually happening? 页面空白没有显示任何信息 --- 但是如果我用 ```javascript Array.from(x) Array.from(y) ``` 即把typedarray转化成array之后, 图表能正常显示 我尝试去定位这个问题. 我在 **lib/data/helper/sourceHelper.js**中的函数**detectSourceFormat**中发现了些问题, 这个函数的功能好像是决定source类型 ```javascript function detectSourceFormat(datasetModel) { var data = datasetModel.option.source; // 这个data来自于配置中的source .... for (var i = 0, len = data.length; i < len; i ) { var item = data[i]; if (item == null) { continue; // 问题出现在这边判断上, 如果是source是[typedarray, typedarray], 无法识别为typedarray } else if (isArray(item)) { sourceFormat = SOURCE_FORMAT_ARRAY_ROWS; break; } else if (isObject(item)) { sourceFormat = SOURCE_FORMAT_OBJECT_ROWS; break; } } } ``` 后面我加上了判断 ```javascript .... var item = data[i]; // 有问题 if (item == null) { continue; } else if(isTypedArray(item)) { // 判断了是不是类型数组 sourceFormat = SOURCE_FORMAT_TYPED_ARRAY break; } else if (isArray(item)) { sourceFormat = SOURCE_FORMAT_ARRAY_ROWS; break; } else if (isObject(item)) { sourceFormat = SOURCE_FORMAT_OBJECT_ROWS; break; } ... ``` 修改完成之后,图表依旧无法显示.之后,我在**lib/data/List.js**下发现 **listProto.initData**中的 ``` this._initDataFromProvider(0, data.count()) ``` 这行好像有问题,**data.count()**的返回值是1, 这个错误的返回值导致后面计算storage时候出现了问题,在**listProto._initDataFromProvider** ```javascript prepareChunks(storage, dimInfo, chunkSize, originalChunkCount, end); // 这里storage是[NaN] ``` 我在**lib/data/helper/dataProvider.js**中找到了typedArray **count**方法的实现 ```javascript 'typedArray': { persistent: false, pure: true, count: function () { // 我的dataset.source是输入两个类型数组, 这里永远返回1 return this._data ? this._data.length / this._dimSize : 0; }, getItem: function (idx, out) { idx = idx - this._offset; out = out || []; var offset = this._dimSize * idx; for (var i = 0; i < this._dimSize; i ) { out[i] = this._data[offset i]; } return out; }, appendData: function (newData) { this._data = newData; }, // Clean self if data is already used. clean: function () { // PENDING this._offset = this.count(); this._data = null; } } ``` 我很想继续追踪解决这个问题,但是我不是很清楚这个cout跟**prepareChunks**具体是做什么的,水平有限,特来求助 <!-- This issue is generated by echarts-issue-helper. DO NOT REMOVE -->
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
