0

I have a textearea with a value of an array with several values and colors to draw in a polar area chart:

<textarea style="display:none" id="span_canva_<?= $vino['id'] ?>" >
    <?= $vino['vino_wineid'] ?>
</textarea>
{value: '20', color: '#4D5360'},
{value: '25', color: '#24b34b'},
{value: '14', color: '#7b3adc'},
{value: '68', color: '#8eb580'},
{value: '69', color: '#b58093'},
{value: '61', color: '#44454f'},
{value: '38', color: '#f65a7b'},
{value: '35', color: '#4e5d3e'},
{value: '41', color: '#cd2c7c'},
{value: '39', color: '#F7464A'},
{value: '33', color: '#46BFBD'},
{value: '62', color: '#8eb580'},
{value: '45', color: '#44454f'},
{value: '36', color: '#f7b10b'},
{value: '41', color: '#92a6ba'},
{value: '25', color: '#f65a7b'},
{value: '45', color: '#4e5d3e'},
{value: '35', color: '#F7464A'},
{value: '45', color: '#46BFBD'},
{value: '10', color: '#FDB45C'},
{value: '50', color: '#949FB1'},
{value: '40', color: '#4D5360'},
{value: '40', color: '#24b34b'}

Then I need to get the .text() of the textarea and draw into a canvas (Chart.js). As you can see the format is right, just need to close the .text() into []. So I did it:

var id_match = jQuery(this).attr('id');    
var vino_wineid = "[" + jQuery("#span_" + id_match).text() + "]";
contendor_chart_popup = new Chart(chart_popup).PolarArea(vino_wineid);

All seems perfect but nothing to draw for the canvas, that because the object type still incorrect.

dakab
  • 5,379
  • 9
  • 43
  • 67
GDedieu
  • 87
  • 1
  • 12

1 Answers1

0
var vino_wineid = eval("[" + jQuery("#span_" + id_match).text() + "]");

The eval() was the missing function to the type object to fill the graphic. Sorry to bother but i think is good to share =)

GDedieu
  • 87
  • 1
  • 12
  • Here's something to read regarding [eval](http://stackoverflow.com/questions/86513/why-is-using-the-javascript-eval-function-a-bad-idea). – Soubhik Mondal Jun 07 '16 at 02:37