我正在使用d3 v5.9.2
,dc v3.0.12
来绘制折线图,但x轴上的刻度似乎有问题。由于提供的数据是时间轴图,因此必须在x轴上标出日期,在y轴上标出值。
const line = lineChart(divRef);
const crossfilterDimension = dx.dimension(dimension);
const firstRecord = crossfilterDimension.bottom(1)[0];
const lastRecord = crossfilterDimension.top(1)[0];
line
.dimension(crossfilterDimension)
.x(
scaleTime().domain([
firstRecord[Object.keys(firstRecord)[0]],
lastRecord[Object.keys(lastRecord)[0]]
])
)
.xUnits(timeYear)
.xAxisLabel(xAxis.label)
.yAxisLabel(yAxis.label)
.renderDataPoints({ radius: 2, fillOpacity: 0.8, strokeOpacity: 0.0 })
.group(
count
? crossfilterDimension.group().reduceCount()
: crossfilterDimension.group().reduceSum(group)
);
line
.yAxis()
.ticks(yAxis.ticks)
.tickFormat(yAxis.tickFormat);
return line;