私はコンポーネントメソッドではD3の折れ線グラフを作成しようとしています:d3はJSの反応 - 「ドキュメント」on「にはcreateElementNS」の実行に失敗しました:提供修飾名が無効な文字が含まれています「」
import React, {Component} from "react";
import {observer, inject} from "mobx-react";
import {line, select} from "d3"
@inject("store")
@observer
class PriceChart extends Component {
constructor(props) {
super(props)
this.createLineChart = this.createLineChart.bind(this)
}
componentDidMount() {
this.createLineChart()
}
componentDidUpdate() {
this.createLineChart()
}
createLineChart() {
const data = [
{
price: 100
}, {
price: 200
}
]
const node = this.node
const priceLine = line().x((d) => 1).y((d) => d.price)
select(node).append(priceLine(data))
}
render() {
return <svg ref={node => this.node = node} width={800} height={800}></svg>
}
}
export default PriceChart;
しかし、私は次のエラーが発生しています:
Failed to execute 'createElementNS' on 'Document': The qualified name provided ('M1,100L1,200') contains the invalid character ','..
ここから値M1、L1はどこから来ますか? d3がエラーの原因となっているデータに値を追加しているようですか?
タイムスタンプは、あなたがGR私は私の入力で周りのビットを再生してみました – Pineda
@Pinedaしている理由である、あなたにD3チャートを使用するには、有効な番号と見なされていないように思えます - すべての価格を固定数に変更し、すべてのタイムスタンプをUnixタイムスタンプに変更した後、x関数を常に1に変更しましたが、私はいつもこのエラーのいくつかのバリエーションを取得します - 無効な文字 '、'を含みます.. –
@ Pinedaは問題をもっと簡単な例に編集したが、それでも問題を示している –