情况: 我有一个函数将输入数据转储到HTML块元素中,例如:
function national(){
x=Number($('#nationalBudget').val());
a=x*2;
$('#one').text(a);}
然后它将输入打印到id =“one”的任何元素
<span id="one"></span>
这很好,但我想加入一个jQuery Bargraph。我正在使用的条形图由数组提供:
coolnessGraph = new Array(
[100000,'ROI w/ Local Spending'],
[200000,'ROI w/o Local Spending']
$("#ROIchart").jqBarGraph({
data: coolnessGraph, // array of data for your graph
title: false, // title of your graph, accept HTML
barSpace: 10, // this is default space between bars in pixels
width: 400, // default width of your graph
height: 200, //default height of your graph
color: '#F8981D', // if you don't send colors for your data this will be default bars color
colors: false, // array of colors that will be used for your bars and legends
lbl: '', // if there is no label in your array
sort: false, // sort your data before displaying graph, you can sort as 'asc' or 'desc'
position: 'bottom', // position of your bars, can be 'bottom' or 'top'. 'top' doesn't work for multi type
prefix: '', // text that will be shown before every label
postfix: '', // text that will be shown after every label
animate: true, // if you don't need animated appearance change to false
speed: 2, // speed of animation in seconds
legendWidth: 100, // width of your legend box
legend: false, // if you want legend change to true
legends: false, // array for legend. for simple graph type legend will be extracted from labels if you don't set this
type: false, // for multi array data default graph type is stacked, you can change to 'multi' for multi bar type
showValues: true, // you can use this for multi and stacked type and it will show values of every bar part
showValuesColor: '#fff' // color of font for values
});
问题: 我想用转储到我的HTML对象的输出替换数组中的硬数字(例如100000和200000)。我尝试了以下内容:
var TestVariable = <span id="one"></span>;
coolnessGraph = new Array(
[TestVariable,'ROI w/ Local Spending'],
几乎所有其他语法迭代我都能想到让这个过程有效。我也尝试在第一次计算运行后等待激活图形。 我的逻辑是否有错误?...语法?...任何帮助都将受到极大的赞赏。
答案 0 :(得分:1)
如果我正确阅读,您只需将$('#one').text()
或其变体传递到数组中。我错过了什么吗?