Javascript array

Asked

Viewed 48 times

-1

People would like to know how to search an image instead of color in this javascript array below Instead:

<script>
  array var arrDados = [{title: "Dados 1", value: 1, **color**: "#fe4400"}]
</script>

I wanted to change to search image, only that the form below is not correct:

<script>
    var arrDados = [ {title: "Dados 1", value: 1, background-image: "www.site.com.br/imagem/figura.png"}]
</script>

Where is color drawing pick up an image. Thank you for your help

  • Where is the image?

  • I want instead of color, the array to pull an image from the server. For example, var arrDados = [ {title: "Data 1", value: 1, background-image: "www.site.com.br/image/figure.png" }. Only that way the image is not searched. What would be the right way?

  • <script >var arrDados = [ {title: "Data 1", value: 1, background-image: "www.site.com.br/image/figure.png" }]</script >

  • It is good to edit the question and put the information.

  • 1

    I don’t understand exactly anything. Reread your question and see if it’s logical. Tell us more, especially where you’re getting the information.

  • I just want to know how to change color to image in this script: <script >var arrdados = [ {title: "Data 1", value: 1, color: "#fe4400" }, {title: "Data 2", value: 1, color: "#de4400" }, {title: "Data 3", value: 1, color: "#be4400" }, {title: "Data 4", value: 1, color: "#ce4400" } ]; Alert (title','+value',' +color</script> because using background-image instead of color does not work. I’ve tried backgroundImage and it doesn’t work either.

  • Look I have a pieChart that returns in color. Only I want to insert image instead of color in pizza. For example, 55% is Corinthians and 45% is Palmeiras. Instead of colors, comes the shirt of the clubs in the pizza

  • Take a look at this model and see if you understand: https://codepen.io/maikonmatheus/pen/LVwPQV

  • 3

    I think this only accepts color, seems to be a svg.

Show 4 more comments

1 answer

0

If you want to add background-images in a vector that has colors, can do as follows:

$.each(arrDados, function (i, o) {

    switch (o.color) {
        case '#fe4400':
            o['background-image'] = 'http://www.meusite.com.br/img/figura-do-fe4400.jpg';
            break;
        case '#de4400':
            o['background-image'] = 'http://www.meusite.com.br/img/figura-do-de4400.jpg';
            break;
        case ...
                                   ....
            break; 
    }
    o.color = undefined;

});

And if your question refers to the Fiddle you made available here, it probably does not accept images, because it is rasterized image.

  • Ok. I thank everyone here who attended me. If you have an alternative to the example I sent on the link, I am grateful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.