1

I have these array in javascript that is going to be the input data for a graph using highcharts

data = [20, 29, 25, 30, 21, 17, 20, 19, 18];

and what I need is to be able to concatenate certain strings to get in the end these

data = [{ color: '#55B647', y: 20 }, 29, 25, 30, 21, 17, 20, { color: '#F15B49', y: 19 }, 18];

I was trying to acces the array and assing the new value like these

data[0]= "{ color: '#55B647', y:" + data[0] + "}";

But is not working, how can I do it? What's wrong with my code?

1
  • Depends on the requirements of Highcharts. Is it expecting a JSON string or an object literal? Commented Aug 24, 2012 at 17:53

1 Answer 1

5

This should be right:

data[0] = { color: '#55B647', y: data[0] };


Rememeber that an object in JS is declared like:

var object = { key1: value1, key2: value2};
1
  • 1
    The issue was your use of strings. This is the correct answer. Commented Aug 24, 2012 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.