如何根据颜色范围更改列表项的颜色

huangapple go评论81阅读模式
英文:

How to change the color of a list item based on a color range

问题

我正在开发一个美国的融合地图。它将包括各个州以及其他领土。

对于其他领土,我将它们显示为值列表,其中每个领土都有一个彩色方块旁边(基本上就是它的标志点)。

如何根据颜色范围更改列表项的颜色

现在我想要做的是改变标志点的颜色(例如,关岛是红色),以便与美国地图的其余部分相匹配,基于其数据。因此,关岛,而不是具有红色标志点,实际上应该是蓝色的,因为其平均温度更接近80华氏度。

如何做到这一点的最佳方式是什么?以下是代码链接 https://jsfiddle.net/qgLhk5bc/

如果您想重新创建地图以进行尝试,您将需要这些库

npm i fusioncharts react-fusioncharts fusionmaps @material-ui @mui

您可以创建一个基本的React应用程序,然后将代码从jsfiddle复制到'app.js'中。

npx create-react-app
英文:

I am developing a Fusion Map of the USA. It will have the States along with additional territories.

For the additional territories, I am showing them as a list of values, where each territory has a colored box next to it (it's basically its bullet point).

如何根据颜色范围更改列表项的颜色

What I want to do now is change the color of the bullet point (for example, Guam is red) to match the same color range as the rest of the USA Map, based on its data. So Guam, instead of having a red bullet point, should actually be blue, because its average temp is closer to 80F.

What is the best way to do this? Here is the code https://jsfiddle.net/qgLhk5bc/

If you want to re-create the map to try it, You will need these libraries

npm i fusioncharts react-fusioncharts fusionmaps @material-ui @mui

You can create a basic react app and copy the code from the jsfiddle into 'app.js'

npx create-react-app

答案1

得分: 1

使用渐变比例,您可以指定与特定数据点相关的颜色。这定义了跨数据范围的自动渐变比例。实体根据其在渐变比例上的数据值位置以唯一的颜色出现。

{
"chart": {
"caption": "全球人口密度",
"theme": "融合",
"showLabels": "1",
"formatNumberScale": "0"
},
"colorrange": {
"minvalue": "0",
"startlabel": "低",
"endlabel": "高",
"code": "#FF4411",
"gradient": "1",
"color": [{
"maxvalue": "25",
"code": "#FFDD44",
"displayValue": "中位数"
}, {
"maxvalue": "100",
"code": "#6baa01"
}]
},
"data": [{
"id": "NA",
"value": "22.1",
"showLabel": "1",
"displayValue": "中等"
},
{
"id": "SA",
"value": "22.0",
"showLabel": "1",
"displayValue": "中等"
},
{
"id": "AS",
"value": "95.0",
"showLabel": "1",
"displayValue": "密集"
},
{
"id": "EU",
"value": "72.5",
"showLabel": "1",
"displayValue": "密集"
},
{
"id": "AF",
"value": "33.7",
"showLabel": "1",
"displayValue": "中等"
},
{
"id": "AU",
"value": "3.2",
"showLabel": "1",
"displayValue": "稀疏"
}]
}

要了解更多关于此功能的信息,请参考 - https://www.fusioncharts.com/dev/map-guide/colouring-based-on-data-range

https://www.fusioncharts.com/dev/chart-guide/chart-configurations/legend

英文:

Using a gradient scale, you can specify colors associated with specific data points. This defines an automatic gradient scale across the data range. Entities appear in unique colors as per the data value position on the gradient scale.

{
        "chart": {
            "caption": "Global Population Density",
            "theme": "fusion",
            "showLabels": "1",
            "formatNumberScale": "0"
        },
        "colorrange": {
            "minvalue": "0",
            "startlabel": "Low",
            "endlabel": "High",
            "code": "#FF4411",
            "gradient": "1",
            "color": [{
                "maxvalue": "25",
                "code": "#FFDD44",
                "displayValue": "Median"
            }, {
                "maxvalue": "100",
                "code": "#6baa01"
            }]
        },
        "data": [{
            "id": "NA",
            "value": "22.1",
            "showLabel": "1",
            "displayValue": "Moderate"
        },
        {
            "id": "SA",
            "value": "22.0",
            "showLabel": "1",
            "displayValue": "Moderate"
        },
        {
            "id": "AS",
            "value": "95.0",
            "showLabel": "1",
            "displayValue": "Dense"
        },
        {
            "id": "EU",
            "value": "72.5",
            "showLabel": "1",
            "displayValue": "Dense"
        },
        {
            "id": "AF",
            "value": "33.7",
            "showLabel": "1",
            "displayValue": "Moderate"
        },
        {
            "id": "AU",
            "value": "3.2",
            "showLabel": "1",
            "displayValue": "Sparse"
        }]
    }

To know more about this feature refer - https://www.fusioncharts.com/dev/map-guide/colouring-based-on-data-range

https://www.fusioncharts.com/dev/chart-guide/chart-configurations/legend

答案2

得分: 0

请查看此处的图例配置选项: https://www.fusioncharts.com/dev/chart-guide/chart-configurations/legend.
有一个color属性。

英文:

Please see the legend configuration options here: https://www.fusioncharts.com/dev/chart-guide/chart-configurations/legend.
There is a color property.

huangapple
  • 本文由 发表于 2023年2月10日 06:58:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405319.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定