Reputation: 135
I'm using php to create a span which contains some data for a flot chart. I want to get this data using jquery by using
var someVar= $('span#someID').text();
it takes the data from this span, however the chart is not being drawn. I know the data is correct as if I copy it from the span and assign it to a var directly in javascript, the chart comes up straight away
here's a copy of the data (it's stored like this
<span id="someID">[["19.00","0.04833"],["18.45","0.04717"],["18.35","0.04833"],["18.20","0.04686"],["18.10","0.04718"],["18.00","0.04937"],["17.50","0.04674"],["17.35","0.04804"],["17.20","0.04810"],["17.10","0.04723"],["17.00","0.04989"],["16.45","0.05519"],["16.35","0.08635"],["16.20","0.04742"],["16.10","0.04712"],["16.00","0.04861"],["15.50","0.04607"],["15.40","0.04758"],["15.30","0.04662"],["15.20","0.04768"]]</span>
<script>
$("#flot-dashboard-chart").length && $.plot($("#flot-dashboard-chart"), [
someVar
],
</script>
Upvotes: 0
Views: 249
Reputation: 693
I don't know if your values have any representarion because I run some test with your code and it gives me almost a simple line.
The only thing you need to do is to parse the span
var flotArray = $.parseJSON($("#someID").text());
Here is a fiddle with an example of the flot with your data (the blue line)
Upvotes: 1