简体   繁体   English

在任何图表中更改弧线颜色和值

[英]change arc color and value in anychart

I am trying to create sunburst chart in d3.js. What I want is if the value is positive I should get green arc.我正在尝试在 d3.js 中创建旭日图。我想要的是,如果值为正,我应该得到绿色弧线。 and when the the value is negative the arc should be red.当值为负时,弧应该是红色的。 Another issue I am facing is whenever I enter negative value that arc/slice just hide.我面临的另一个问题是每当我输入负值时,arc/slice 就会隐藏。 I also want to show my that slice with negative value.我还想用负值显示我的切片。

    <style>
    html,
    body,
    #container {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        background: #562F34;
        background: #33573D;
    }
</style>

<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-core.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-sunburst.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.9.0/js/anychart-data-adapter.min.js"></script>

<div id="container"></div>

<script>
file2 = [
    {
        "name": "KES100",
        "fill": "#33573D",
        "children": [
            {
                "name": "TEXTILE",
                "id": "textileId",
                "children": [
                    {
                        "continent": "textileId",
                        "name": "COST",
                        "value": "10",
                        "points": "30"
                    },
                    {
                        "continent": "textileId",
                        "name": "COOT",
                        "value": "10",
                        "points": "30"
                    },
                    {
                        "continent": "textileId",
                        "name": "AHTM",
                        "value": "10",
                        "points": "30"
                    }
                ]
            },
            {
                "name": "OIL",
                "id": "oilId",
                "children": [
                    {
                        "continent": "oilId",
                        "name": "PSO",
                        "value": "20"
                    },
                    {
                        "continent": "oilId",
                        "name": "BYCO",
                        "value": "20"
                    },
                    {
                        "continent": "oilId",
                        "name": "MPCL",
                        "value": "10"
                    }
                ]
            }
        ]
    }
]
    anychart.onDocumentReady(function () {
        anychart.data.loadJsonFile('file2.json',
            function (data) {
                var color1 = [255, 0, 0];
                var color2 = [0, 0, 255];

                anychart.color.blend(color1, color2, 0.2);

                var chart = anychart.sunburst(data, "as-tree");

                chart.calculationMode("parent-independent");

                chart.labels().format('{%Name}\n{%Value}');
                console.log(chart.labels())

                chart.tooltip().format('{%Name}:{%Value}');

                chart.container("container");

                chart.draw();

            });
    });



</script>

The "value" should always be positive as it affects the size of the node directly. “值”应始终为正,因为它直接影响节点的大小。 You can provide negative values in the data and then preprocess it.您可以在数据中提供负值,然后对其进行预处理。 Copy the positive/negative value to another custom field of the item data, and leave the absolute value in the "value" field.将正负值复制到项目数据的另一个自定义字段中,并将绝对值保留在“值”字段中。 Then you can apply condition coloring by a callback function in fill() chart method.然后您可以通过 fill() 图表方法中的回调 function 应用条件着色。 For details, check the sample based on your snippet .有关详细信息,请根据您的代码段检查样本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM