问题描述
背景
我正尝试将dc图例添加到dc.js条形图中,如下所示:
state.chart.legend(new dc.HtmlLegend().container(legendElement).horizontal(true).highlightSelected(true))
创建的图表如下:
const plotBarChart = (data: TrendTimeseries[],width: number) => {
//@ts-ignore
state.chart = new dc.BarChart(`#${ state.id }`);
const barData = new Array<BarChartData>();
data.forEach((value) => {
if (value.Timeserie.length > 0 && value.Visible) {
barData.push({
Name: value.PlaceName,TruncateName: _.truncate(value.PlaceName,{
length: 35,separator: ' ',}),//@ts-ignore
Value: getDataByType(value.Timeserie[0]),Color: value.Color,Timestamp: value.Timeserie[0].timestamp,})
}
});
const ndx = crossfilter(barData);
const barDimension = ndx.dimension((d) => [d.TruncateName,d.Name,d.Timestamp]);
const barGroup = barDimension.group().reduceSum((d) => d.Value);
state.chart
.dimension(barDimension)
.group(barGroup)
.renderTitle(false)
.width(width)
.height(280)
.margins({
top: 40,right: 40,bottom: 120,left: 40,})
.x(d3.scaleBand())
.xUnits(dc.units.ordinal)
.brushOn(false)
.transitionDuration(0)
.barPadding(0.4)
.outerPadding(0.2)
//@ts-ignore
.ordering((d) => {
//@ts-ignore
return priority(d.key[0]);
})
//@ts-ignore
.colorAccessor((d) => d)
//@ts-ignore
.colors((d) => {
return getBarColor(d.key[0],barData);
});
问题
TypeError: Cannot read property '0' of undefined
问题
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)