AMCharts How to color bullets by value?
I am working with amcharts and I tried to mark the bullets in the chart with the values they have. So I created an array in javascript and passed the values from the database to it. Green is just value for testing.
var chartData = [
<?php
foreach($tmp as $row)
{
echo'{"Wahrscheinlichkeit":'.$row[3].',"Schaden":'.$row[4].',"value":1,"Beschreibung":"'.$row[2].'", "Color":"Green"},';
}
?>
];
Here's how I create a diagram:
chart = new AmCharts.AmXYChart();
chart.dataProvider = chartData;
Here I am drawing a diagram:
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);
At the bulletcolor point, I try to get the color from the array, but it doesn't work.
chart.write("chartdiv");
Waiting for advice and help from you
+3
source to share
1 answer
bulletColor cannot refer to fields in such data.
Use "lineColorField" instead:
http://docs.amcharts.com/3/javascriptcharts/AmGraph#lineColorField
i.e:.
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);
+2
source to share