AMCharts如何按值对子弹进行着色?

时间:2015-04-25 10:07:07

标签: javascript php amcharts

我正在使用amcharts,我试图通过它们拥有的值为图表中的项目符号着色。所以我在javascript中创建了一个数组,并将数据库中的值传递给它。绿色只是测试的价值。

   var chartData = [
      <?php
         foreach($tmp as $row)
           {
             echo'{"Wahrscheinlichkeit":'.$row[3].',"Schaden":'.$row[4].',"value":1,"Beschreibung":"'.$row[2].'", "Color":"Green"},'; 
           }
      ?>
   ];

我在这里创建图表:

 chart = new AmCharts.AmXYChart();
 chart.dataProvider = chartData;

我在这里绘制图表:

 var graph = new AmCharts.AmGraph();
            graph.valueField = "value"; // größe der Kugeln
            graph.xField = "Wahrscheinlichkeit";
            graph.yField = "Schaden";
            graph.maxBulletSize=20;
            graph.lineAlpha = 0;
            graph.bullet = "circle";
            graph.bulletColor= "[[Color]]";
            graph.balloonText = "Wahrscheinlichkeit:<b>[[x]]</b> Schaden:<b>[[y]]</b><br>Beschreibung:<b> [[Beschreibung]]</b>"
            chart.addGraph(graph);

点'#34; bulletcolor&#34;我尝试从阵列中获取颜色,但它不起作用。

chart.write("chartdiv");

期待获得提示和帮助

1 个答案:

答案 0 :(得分:2)

&#34; bulletColor&#34;不能像这样引用数据中的字段。

相反,请使用&#34; lineColorField&#34;:

http://docs.amcharts.com/3/javascriptcharts/AmGraph#lineColorField

即:

var graph = new AmCharts.AmGraph();
graph.valueField = "value"; // größe der Kugeln
graph.xField = "Wahrscheinlichkeit";
graph.yField = "Schaden";
graph.maxBulletSize=20;
graph.lineAlpha = 0;
graph.bullet = "circle";
graph.lineColorField = "Color";
graph.balloonText = "Wahrscheinlichkeit:<b>[[x]]</b> Schaden:<b>[[y]]</b><br>Beschreibung:<b> [[Beschreibung]]</b>"
chart.addGraph(graph);