Home forums Using CanvasJS Changing colors

This topic contains 2 replies, has 2 voices, and was last updated by  dimas19801 1 month, 4 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12732

    dimas19801
    Member

    Json:
    [{"region":"SZ m5 00.10.00.49","status":"1"},{"region":"SZ SU 0.00.10.01","status":"1"}]

    code:

    <script type="text/javascript">
    $(document).ready(function(){
    function sec() {
    var dataPoints =[];
    $.getJSON("api_status.php",function(data) {
    for(var i=0; i<= data.length-1; i++) {
    dataPoints.push({label:data[i].region,y:parseInt(data[i].status)});
    }
    var chart = new CanvasJS.Chart("chartContainer", {
    theme: "theme2",
    zoomEnabled: true,
    panEnabled: true,
    title: {
    fontSize: 14,
    text: "TEXT"
    },
    axisY:{
     valueFormatString: " ",
     maximum: 1,
     gridThickness: 0,
         },
    axisX: {
    labelMaxWidth: 80,
    labelWrap: true, 
    	},
    legend: {
    itemMaxWidth: 150,
    itemWrap: true,
    maxWidth: 100
    },
    data: [
    {
    type: "column",
    color: "green",
    showInLegend: false,
    dataPoints: dataPoints
    }
    ]
    });
    chart.render();
    });
    }
    setInterval(sec, 10000)
    });
    </script>

    If JSON “status”: “2” (example { “region”: “SZ SU 0.00.10.01”, “status”: “2”}) as a color change on the other?

    #12734

    Vishwas R
    Keymaster

    Dimas,

    Yes its possible to set color at dataPoint level. Please check this jsfiddle.

    #12735

    dimas19801
    Member

    Thanks for the help! working

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.