簡體   English   中英

如何在 LightningChart JS 中的同一張圖表上使用不同樣式的標簽

[英]How do I have differently styled labels on the same chart in LightningChart JS

我有一個餅圖,想在每個切片上使用不同顏色的標簽,以便文本更具可讀性。 這是一個稍微修改過的代碼,它創建了一個簡單的餅圖,里面有標簽,取自這里的交互式演示:

const lcjs = require('@arction/lcjs')

const {
    lightningChart,
    PieChartTypes,
    UIElementBuilders,
    LegendBoxBuilders,
    UIDraggingModes,
    SliceLabelFormatters,
    UIOrigins,
    emptyFill,
    emptyLine,
    Themes
} = lcjs

const donut = lightningChart().Pie({
    theme: Themes.darkGold, 
    type: PieChartTypes.LabelsInsideSlices
})
    .setTitle('Inter Hotels - hotel visitors in June 2016')
    .setPadding({ top: 40 })
    .setAnimationsEnabled(true)
    .setMultipleSliceExplosion(false)

const data = {
    country: ['US', 'Canada', 'Greece', 'UK', 'Finland', 'Denmark'],
    values: [15000, 20030, 8237, 16790, 9842, 4300]
}
const processedData = []

for (let i = 0; i < data.values.length; i++) {
    processedData.push({ name: `${data.country[i]}`, value: data.values[i] })
}

processedData.map((item) => donut.addSlice(item.name, item.value))
donut.setLabelFormatter(SliceLabelFormatters.NamePlusValue)
donut.addLegendBox(LegendBoxBuilders.HorizontalLegendBox)
    .setAutoDispose({
        type: 'max-width',
        maxWidth: 0.80,
    })
    .add(donut)

有沒有辦法單獨修改每個切片 label 的填充顏色,類似於setLabelFormatter的工作方式?

如果不是,我有什么選擇? 我考慮過使用addUIElement(UIElementBuilders.TextBox)創建自定義 UI 文本框元素,但我不知道如何在切片上 position 它們,因為我找不到任何獲取切片 position 或任何類型的測量值的方法(此外,我無法將它直接附加到PieSlice )。

好吧,答案是(可能)不是。 LightningChart JS API 沒有提供任何修改圖表 label styles 這種特殊類型圖表的方法。 我通過隱藏圖表標簽並在圖表頂部添加自定義文本框來解決它。 這還需要在調整大小和切片值更改時實施自定義定位方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM