绘制几个图形javascript

时间:2012-11-21 16:01:11

标签: javascript amcharts

我会用这段代码来显示给定数量的图形,这样的图形数量每次都会变化modifié.j'我尝试为图形数量做一个循环但是我不能来帮助我/ p>

http://jsfiddle.net/amcharts/j9gUu/

我的考试

    for (int i=1; i<4;i++)
   {
       var valueAxis[i] = new AmCharts.ValueAxis();
    valueAxis[i].axisColor = "#FF6600";
    valueAxis[i].axisThickness = 2;
    valueAxis[i].gridAlpha = 0;
    chart.addValueAxis(valueAxis[i]);
​

1 个答案:

答案 0 :(得分:0)

您可以操作服务器中的数据并将其分配给我已硬编码的变量。使用此功能,您可以绘制多个折线图。

chart = new AmCharts.AmSerialChart();
chart.categoryField = "date";// whatever your horizontal axis's value
chart.startDuration = 1;

// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.labelRotation = 45;
categoryAxis.autoGridCount = true;
categoryAxis.startOnAxis = true;

// Value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.gridAlpha = 0.07;
valueAxis.autoGridCount = true;
valueAxis.title = "Some Title on Vertical Axis";
chart.addValueAxis(valueAxis);

    //following values hardcoded. you can assign any values you want.

var j=0;
var chartData = [[{"date":"2013 Mar","company1":0,"company2":0},{"date":"2013 Apr","company1":0,"company2":271},{"date":"2013 May","company1":0,"company2":271},{"date":"2013 Jun","company1":0,"company2":284},{"date":"2013 Jul","company1":509.9,"company2":1568}];
var no_of_companies = 2;//put your value
var color_array = your color array;//should be an array
chart.dataProvider = chartData;

for(j=0;j<no_of_companies;j++){
  var graph = new AmCharts.AmGraph();
  graph.valueField = "company"+(j+1);
  graph.balloonText = "[[category]]: [[value]]";
  graph.type = "line";
  graph.lineColor = color_array[j];
  graph.lineThickness = 2;
  chart.addGraph(graph);
}       
var chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorAlpha = 0;
chartCursor.cursorPosition = "mouse";
chart.addChartCursor(chartCursor);
chart.write("chartdiv");
希望这会对你有所帮助。