var chart = null;
var bgWidth = 535;//宽
var bgHeight = 300;//高
var datas = [51,85,46,75,15];//数值
var titles = ["苹果","梨子","葡萄","芒果","荔枝"];//标题
var bigTitle = "水果调查";
var maxData = 0;
var perData = 0;
var colors = ["#FF9999","#99FFFF","#99FF99","#FFFF99","#FF9933","#FFCCFF"];
var colors2 = ["#FD8686","#72E7E7","#52DB52","#DFDF01","#F28315","#F589F5"];

function drawContent(){
	var s = new Series();
	s.Title = "票数";
	s.Color = "#FF8040";
	for(var i = 0;i < datas.length;i++){
	
		s.addData(titles[i],datas[i],datas[i]);
	}
	chart.addSeries(s);
	
	chart.AxisY.Title = "票数";
}


function getColor(num){
	var total = colors.length;
	while(num >= total) num = num-total;
	return colors[num];
}

function getColor2(num){
	var total = colors2.length;
	while(num >= total) num = num-total;
	return colors2[num];
}

function drawAxis(){
	//求最大值
	for(var i = 0;i < datas.length;i++){
		maxData = Math.max(datas[i],maxData);
	}
	//计算标尺
	var lines = 0;
	lines = maxData;
	while(lines > 11){
		perData += 5;
		lines = maxData/perData;
	}
	//上面没有处理
	if(maxData<=10){
		perData = 1;
	}
      chart.Text.Font.Size = 20;
      chart.Text.Font.Style = fstBold;
      chart.Width = bgWidth;
      chart.Height = bgHeight;
      chart.Shadow = true;
      chart.Text.Text = bigTitle;
      chart.AxisX.showPoint=50;     // Max points on X-axis
      chart.valueInterval = perData;     // Value interval for Y-axis
      chart.YAxisFromZero = true;   // Whether Y-axis value should start from zero
      chart.horizontalGrid = true;  // Whether horizontal grids should be displayed
      chart.initialise();
}

function show2DBar(datas,titles,bigTitle,theId,bgWidth,bgHeight){
	chart = new VerticalBarChart();
	this.datas = datas;
	this.titles = titles;
	this.bigTitle = bigTitle;
	this.bgWidth = bgWidth;
	this.bgHeight = bgHeight;
    chart.Container = document.getElementById(theId);
	drawAxis();
	drawContent();
    chart.draw();
}

