0

我将使用此代码显示给定数量的图形,此类图形的数量每次都是可变的将 modifié.j '我尝试为图形数量创建一个循环,但我无法帮助

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]);
​
4

1 回答 1

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");

希望这会对你有所帮助。

于 2013-08-15T06:24:41.553 回答