Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have added emoji's in my dashboard based on the expression.

Based on the percentage it has to show smiley with color as green and red.

Here i have written one method in javascript

function setColors(args) {
        var textClientData = DashboardViewer.GetItemData("textBoxDashboardItem1");
        var value = textClientData.GetMeasureValue(textClientData.GetMeasures()[2].Id).GetValue();
        if (value=="J")
        var result = value.toString().fontcolor("Green");
        document.getElementsByClassName('cs10E8CA05').css('color','Green');
        //x.style.color = "Green";
        //var score = $('#cs10E8CA05').text().trim();
        //var color = 'red';
        //$('#cs10E8CA05').css('color', color);
};


If the value is J then it has to be in green color.
If the value is L then it has to be in red color.

I have checked the network tab in browser and it is lying under the span.

How to set color for the span by using javascript call to css.

Please suggest me.

What I have tried:

function setColors(args) {
        var textClientData = DashboardViewer.GetItemData("textBoxDashboardItem1");
        var value = textClientData.GetMeasureValue(textClientData.GetMeasures()[2].Id).GetValue();
        if (value=="J")
        var result = value.toString().fontcolor("Green");
        document.getElementsByClassName('cs10E8CA05').css('color','Green');
        //x.style.color = "Green";
        //var score = $('#cs10E8CA05').text().trim();
        //var color = 'red';
        //$('#cs10E8CA05').css('color', color);
};


This is HTML

<span class="cs10E8CA05">L</span>

<span class="cs10E8CA05">J</span>
Posted
Updated 30-Jun-17 16:36pm
v2

1 solution

try

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  
<body>
    <span class="cs10E8CA05">L</span> 
    <span class="cs10E8CA05">J</span>

    <script>
        var spans = document.getElementsByClassName('cs10E8CA05');
        for (var i = 0; i < spans.length; i++) {
            var span = spans[i];
            if (span.textContent == 'J')
                span.style.color = 'green';
            if (span.textContent == 'L')
                span.style.color = 'red';
        } 
    </script>
</body>
</html>
 
Share this answer
 
Comments
TarunKumarSusarapu 3-Jul-17 1:18am    
Hi Karthik,

Thank you for your information provided.

But here I have taken devexpress extension of dashboard for html.

@Html.DevExpress().DashboardViewer(settings => {
settings.Name = "DashboardViewer";
settings.Width = Unit.Percentage(100);
settings.Height = Unit.Percentage(200);
settings.CallbackRouteValues = new { Controller = "Home", Action = "DashboardViewerPartial" };
settings.ExportRouteValues = new { Controller = "Home", Action = "DashboardViewerPartialExport" };
settings.ClientSideEvents.ItemClick = "function(s, e) { getUnderlyingData(e); }";
settings.ClientSideEvents.ItemElementCustomColor = "function(s, e) { setColors(e); }";
//settings.ClientSideEvents.ItemVisualInteractivity = "function(s, e) { GetCalculatedFields(e); }";
}).BindToSource(Model).GetHtml()

In network tab it is showing span class for that emoji text.

Now my question where should i add the above code?

Or Can i change the color using javascript?
Karthik_Mahalingam 5-Jul-17 0:04am    
are you using jquery?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900