基于对象属性

时间:2017-03-21 19:43:41

标签: jquery fusioncharts

我正在尝试入侵FusionCharts对象,以独立于基本的“paletteColors”对象控制每个数据元素的颜色。

我需要对其进行修改,以便例如标签为“New”的所有项目都获得相同的颜色(例如红色)。标签为“完成”的所有项目都会获得特定颜色(例如灰色)。

所以,我可以有多个图表,每个图表都有不同的数据(一个图表可能有“新”和“完整”数据标签,另一个图表可能有“资金”和“错误”标签)但颜色值将是不同的对于跨多个图表的每个数据点。

$.each(jsonDataPoints, function (index, obj) {
            var hoverText = obj.label + " (" + obj.value + ")";
            obj.toolText = hoverText; //This sets the text to display when a pie chart is hovered.
            obj.displayValue = hoverText; //This sets the chart labels.

                if (obj.label = "New") { 
                    obj.color = "#ff0000";
                }
                else if(obj.label = "Complete") { 
                    obj.color = "#cccccc"; 
                }
                else if(obj.label = "Funding") { 
                    obj.color = "#888888"; 
                }

                else{
                    obj.color = "#000000";
                }
        });


var pieChart = new FusionCharts({
            type: 'pie2D',
            renderAt: containerId,
            registerWithJS: '1',
            dataFormat: 'json',
            dataSource: {
                "chart": {
                    "enableRotation": "0",
                    "animation": "1",
                    "showToolTip": "1",
                    "showPercentInTooltip": "0",
                    "showBorder": "0",
                    "showLegend": "0",
                    "decimals": "1",
                    "formatNumber": "1",
                    "formatNumberScale": "0",
                    "inthousandSeparator": ",",
                    "indecimalSeparator": ".",
                    "enableSmartLabels": "1",
                    "height": "100%",
                    "width": "100%",
                    "bgColor": "#FFFFFF",
                    //"paletteColors": "E58403,60CA9E,8F5097,569C3F,2D6CA2,5B6770,8F6A2A,5F407A,872B4B,572C5F,244C5A",
                    "chartBottomMargin": "5",
                    "chartTopMargin": "5",
                    "showPlotBorder": "1",
                    "plotBorderColor": "#FFFFFF",
                    "plotBorderThickness": "1",
                    "startingAngle": "90"
                },
                "data": jsonDataPoints
            }
        });
        pieChart.render();

换句话说,我不希望“Funding”具有与“New”相同的图表颜色。我希望“Funding”始终是相同的颜色,无论它出现在哪个图表中(我有一个带有3-4个图表的仪表板)

我是否在正确的轨道上使用下面的代码?显然我错过了一些东西,因为它不起作用(所有值都是红色,与“新”标签相同。新的应该是红色的,但每个后续数据点都应该有我自己的if / else代码中指定的唯一颜色下面的分支)

0 个答案:

没有答案
相关问题