Last active
April 24, 2020 03:34
-
-
Save creadone/197b184f027d09d1d62997409cf9f23e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
overview.props.$chart.getModel().getSeriesByName('uniqUsers')[0].getData().getVisual('color') | |
// Adaptive labels | |
// https://github.com/apache/incubator-echarts/issues/8841#issuecomment-516034572 | |
echarts.registerLayout(ecModel => { | |
ecModel.eachSeries(seriesComponent => { | |
const data = seriesComponent.getData(); | |
data.each(idx => { | |
const layout = data.getItemLayout(idx); | |
if (layout) { | |
const dataItem = data.getRawDataItem(idx); | |
const seriesName = seriesComponent.name; | |
const label = `${seriesName} | ${dataItem.value}`; | |
const seriesLabelModel = seriesComponent.getModel("label"); | |
const itemLabelModel = data.getItemModel(idx).getModel("label"); | |
itemLabelModel.mergeOption({ | |
...seriesLabelModel.option, | |
...itemLabelModel.option | |
}); | |
const labelRect = itemLabelModel.getTextRect(label); | |
const labelFits = | |
layout.width >= labelRect.height && | |
Math.abs(layout.height) >= labelRect.width; | |
itemLabelModel.mergeOption({ show: labelFits }); | |
} | |
}); | |
}); | |
}); | |
const chart = echarts.init(container); | |
chart.setOption(option, true); | |
window.addEventListener("resize", debounce(() => chart.resize()), 200); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment