javascript - 如何在组条形图中隐藏一个特定组的条形?
问题描述
使用 LightningchartJS,我创建了一个分组条形图。我根据类别创建了系列,并根据国家对它们进行了分组。使用图例框,我可以根据它们的系列隐藏条形。有没有办法根据他们的群体隐藏他们?
const addGroups = (names) => {
for (const name of names)
groups.push({
name,
tick: axisX.addCustomTick()
.setGridStrokeLength(0)
.setTextFormatter((_) => name)
.setMarker((marker) => marker
.setBackground((background) => background
.setFillStyle(emptyFill)
.setStrokeStyle(emptyLine)
)
)
})
}
const addCategory = (entry) => {
// Each category has its own series.
const series = createSeriesForCategory(entry)
.setName(entry.name)
.setDefaultStyle(figure => figure.setFillStyle(entry.fill))
entry.figures = entry.data.map((value) => series.add({ x: 0, y: 0, width: 0, height: 0 }))
legendBox.add(series, 'Legend')
categories.push(entry)
redraw()
}
const createSeriesForCategory = (category) => {
const series = chart.addRectangleSeries()
// Change how marker displays its information.
series.setResultTableFormatter((builder, series, figure) => {
// Find cached entry for the figure.
let entry = {
name: category.name,
value: category.data[category.figures.indexOf(figure)]
}
// Parse result table content from values of 'entry'.
return builder
.addRow('Department:', entry.name)
.addRow('# of employees:', String(entry.value))
})
// Apply cursor logic using series.onHover method
series.onHover((_, point) => {
if (point) {
const figure = point.figure
const dimensions = figure.getDimensionsPositionAndSize()
// Show band.
band
.setDimensions({
x: dimensions.x - figureGap * .5,
y: figure.scale.y.getInnerStart(),
width: dimensions.width + figureGap,
height: figure.scale.y.getInnerInterval()
})
.restore()
} else
band.dispose()
})
return series
}
const categories = ['Engineers', 'Sales', 'Marketing']
chart.addGroups(['Finland', 'Germany', 'UK'])
解决方案
LegendBox 确实有一个“组”的内部概念,但它只提供按组“标签”对条目进行分组,以及显示组“标签”。组标签不可交互,所以我不认为它可用于这种目的。
根据此类应用程序的流行程度,满足此需求的一些附加功能可能是合理的。
同时,使用 UILayoutBuilders 完全自制的 LegendBox 将是另一种选择。
推荐阅读
- c# - 在 SSIS 2012 中的脚本组件中访问对象变量
- visual-studio-code - 如何在我的 *.svelte 文件中配置自动格式化?
- swift - 当 BUILD_LIBRARY_FOR_DISTRIBUTION 设置为 Yes 时,Swift 框架无法构建
- c++ - 为什么这些静态函数不按预期从另一个线程返回?
- vuejs2 - Vuejs 从孙子级发射到基本父级
- r - 测试数字是否在R中的字符串中
- google-apps-script - 自动 CSV 导入错误:选项卡已存在
- c# - 单独文件中的 XML 文档注释
- javascript - 如何让 getUsermedia 在 Instagram 上工作?
- sql - json_build_object() 中的 case 表达式