D3.js d3格式,删除逗号作为分隔符
在d3图形中,我们默认使用逗号作为千位分隔符,我希望删除它们,并将x轴刻度显示为“2000 000”而不是“2000000” 这就是我尝试过的:D3.js d3格式,删除逗号作为分隔符,d3.js,D3.js,在d3图形中,我们默认使用逗号作为千位分隔符,我希望删除它们,并将x轴刻度显示为“2000 000”而不是“2000000” 这就是我尝试过的: private scaleX: ScaleLinear<number, number>; private xAxisComponent: any; // Define an x Axis const axisNumberFormat: FormatLocaleDefinition = { '
private scaleX: ScaleLinear<number, number>;
private xAxisComponent: any;
// Define an x Axis
const axisNumberFormat: FormatLocaleDefinition = {
'decimal': '.',
'thousands': ' ',
'grouping': [3],
'currency': ['', ''],
};
const axisFormatLocale: FormatLocaleObject = this.d3.formatDefaultLocale(axisNumberFormat);
this.xAxisComponent = this.d3.axisBottom(this.scaleX).tickFormat(axisFormatLocale);
private scaleX:ScaleLinear;
私有组件:任何;
//定义x轴
常量axisNumberFormat:FormatLocaleDefinition={
“十进制”:”,
“千”:“,
“分组”:[3],
“货币”:['',],
};
const axisFormatLocale:FormatLocaleObject=this.d3.formatDefaultLocale(axisNumberFormat);
this.xAxisComponent=this.d3.axisBottom(this.scaleX).tickFormat(axisFormatLocale);
但是,最后一行的赋值不起作用,它说“FormatLocaleObject类型的参数不能赋值给null类型的参数”。有什么提示吗?或者我这样做是错误的,是否有其他方法将格式字符串组合起来发送到
tickFormat()
方法?如果将.format(“”)添加到axisFormatLocale中,最后一行将起作用:
this.xAxisComponent = this.d3.axisBottom(this.scaleX).tickFormat(axisFormatLocale.format(''));
如果这是Typescript/Angular/React/which,请添加相应的标签。