Home forums Using CanvasJS What if, all y : data is 0 ?

This topic contains 7 replies, has 2 voices, and was last updated by  Sanjoy 11 months, 2 weeks ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #17881

    nik.sol
    Member

    If i input 0 for all value of y: in datapoint pie-chart, chart doesn’t show-up/render.

    Is it possible to display a message like : “No Data found!” for a particular canvas chart.

    #17882

    nik.sol
    Member

    Example :
    <script type=”text/javascript”>
    window.onload = function () {
    var chart = new CanvasJS.Chart(“chartContainer”,
    {
    theme: “theme2”,
    title:{
    text: “Gaming Consoles Sold in 2012”
    },
    data: [
    {
    type: “pie”,
    showInLegend: true,
    toolTipContent: “{y} – #percent %”,
    yValueFormatString: “#,##0,,.## Million”,
    legendText: “{indexLabel}”,
    dataPoints: [
    { y: 0, indexLabel: “PlayStation 3” },
    { y: 0, indexLabel: “Wii” },
    { y: 0, indexLabel: “Xbox 360” },
    { y: 0, indexLabel: “Nintendo DS”},
    { y: 0, indexLabel: “PSP” },
    { y: 0, indexLabel: “Nintendo 3DS”},
    { y: 0, indexLabel: “PS Vita”}
    ]
    }
    ]
    });
    chart.render();
    }
    </script>

    #17889

    Sanjoy
    Participant

    @nik-sol,

    Please take a look into this jsfiddle.


    Sanjoy Debnath
    Team CanvasJS

    #17890

    nik.sol
    Member

    @sanjoy,

    Great .! Thanks for the info.

    nik.sol

    #18583

    nik.sol
    Member

    @sanjoy,

    One more help in similar case,
    We need to hide legends in this situation as well.

    nik.sol

    #18584

    nik.sol
    Member

    @sanjoy,

    I did this to achieve my functionality..

    function showDefaultText(chart, text){
    	 var dataPoints = chart.options.data[0].dataPoints;
       var isEmpty = !(dataPoints && dataPoints.length > 0);
       
       if(!isEmpty){
       	for(var i = 0; i < dataPoints.length; i++){
          isEmpty = !dataPoints[i].y;
          dataPoints[i].indexLabel = '';
        	if(!isEmpty)
            break;
        }
       }
      
       if(!chart.options.subtitles)
       	chart.options.subtitles = [];
       if(isEmpty)
       	chart.options.subtitles.push({
         text : text,
         verticalAlign : 'center',
       });
       else
       	chart.options.subtitles = [];
     }

    Let me know if there is better way of doing it.

    nik.sol

    #18586

    nik.sol
    Member

    Did some more changes..

    Using this :

    if(isEmpty){
      <strong> for(var i = 0; i < dataPoints.length; i++){
          dataPoints[i].indexLabel = '';
       }</strong>
       chart.options.subtitles.push({
         text : text,
         verticalAlign : 'center',
       });
    }

    Instead of :

    if(!isEmpty){
       	for(var i = 0; i < dataPoints.length; i++){
          isEmpty = !dataPoints[i].y;
         <del datetime="2018-01-03T09:35:27+00:00"> dataPoints[i].indexLabel = '';</del>
        	if(!isEmpty)
            break;
        }
       }

    nik.sol

    #18595

    Sanjoy
    Participant

    nik.sol,

    One more help in similar case,
    We need to hide legends in this situation as well.

    You can achieve this by toggling showInLegend property. Please take a look at this updated jsfiddle.


    Sanjoy Debnath
    Team CanvasJS

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

You must be logged in to reply to this topic.