我有一个从CSV读取的堆积面积图。但是它不能正确渲染x轴和图形。
我尝试更改x轴值,但没有帮助。
下面的是示例CSV文件。
当前,该视图显示y轴值,右侧显示药物名称,但未显示实际堆积图或日期x轴值。
到目前为止,返回x(d.data.date)=返回NaN。
非常感谢您的帮助!
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-108-293ce740be95> in <module>()
1 import json
2
----> 3 classes = natural_language_classifier.classify_collection('7818d2s519-nlc-1311', [{data_df_1.to_json()}]).get_result()
4
5 print(json.dumps(classes, indent=2))
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/watson_developer_cloud/natural_language_classifier_v1.py in classify_collection(self, classifier_id, collection, **kwargs)
152 if collection is None:
153 raise ValueError('collection must be provided')
--> 154 collection = [self._convert_model(x, ClassifyInput) for x in collection]
155
156 headers = {}
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/watson_developer_cloud/natural_language_classifier_v1.py in <listcomp>(.0)
152 if collection is None:
153 raise ValueError('collection must be provided')
--> 154 collection = [self._convert_model(x, ClassifyInput) for x in collection]
155
156 headers = {}
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/watson_developer_cloud/watson_service.py in _convert_model(val, classname)
462 if isinstance(val, str):
463 val = json_import.loads(val)
--> 464 val = classname._from_dict(dict(val))
465 if hasattr(val, "_to_dict"):
466 return val._to_dict()
ValueError: dictionary update sequence element #0 has length 1736; 2 is required
date,drug,market_share
2016-01-01,insulin lispro,.01
2016-01-01,alogliptin,0.001323754341
2016-01-01,sitagliptin,.01
2016-01-01,canagliflozin,0.02842158621
2016-01-01,glimepiride,0.05668845799
2016-01-01,repaglinide,0.0005768749342
2016-01-01,insulin glargine,.01
2016-01-01,metformin,0.4972895171
2016-01-01,mifepristone,.02
2016-01-01,exenatide,.02
2016-01-01,bromocriptine,0.0002109506723
2016-01-01,pioglitazone,0.02324500184
2016-01-01,metformin hydrochloride,0.392074889
2016-02-01,saxagliptin,.02
2016-02-01,pioglitazone,0.02247815103
2016-02-01,exenatide,0.03
2016-02-01,repaglinide,0.0006204220565
2016-02-01,metformin hydrochloride,0.394153624
2016-02-01,sitagliptin,.08
2016-02-01,insulin lispro,.05
2016-02-01,canagliflozin,0.02907988245
2016-02-01,metformin,0.4933502396
2016-02-01,insulin glargine,.02
2016-02-01,bromocriptine,0.0002076549233
2016-02-01,mifepristone,.02
2016-02-01,alogliptin,0.001364306972
2016-02-01,glimepiride,0.05857620484
2016-03-01,canagliflozin,0.02908102306
2016-03-01,bromocriptine,0.000195238081
2016-03-01,metformin,0.4966376769
2016-03-01,alogliptin,0.00133532899
2016-03-01,insulin glargine,.03
2016-03-01,sitagliptin,.04
答案 0 :(得分:1)
您正确地解析了日期字符串。但是,在此功能中...
Object.keys(stackedByDate).forEach(function (key) {
hash = {}
hash['date'] = key;//<----- HERE
Object.keys(stackedByDate[key]).forEach(function (innerKey) {
hash[innerKey] = stackedByDate[key][innerKey]
});
newData.push(hash);
});
...您正在将日期对象再次转换回字符串。
最快的解决方案是:
hash['date'] = new Date(key);