Converting Chart.js canvas chart to image using .toDataUrl() results in blank image

前端 未结 7 1992
失恋的感觉
失恋的感觉 2020-11-30 23:57

I am using Chart.js. I am trying to convert the chart to an image by getting a base 64 string. The tutorial (http://www.chartjs.org/docs/) devotes an entire 1 line on the to

7条回答
  •  無奈伤痛
    2020-12-01 00:01

    Chart.JS API has changed since this was posted and older examples did not seem to be working for me. here is an updated fiddle that works on the newer versions

    HTML:

    
        
        
    
    

    JS:

    function done(){
      alert("haha");
      var url=myLine.toBase64Image();
      document.getElementById("url").src=url;
    }
    
    var options = {
      bezierCurve : false,
      animation: {
        onComplete: done
      }
    };
    
    var myLine = new 
       Chart(document.getElementById("canvas").getContext("2d"),
         {
            data:lineChartData,
            type:"line",
            options:options
          }
        );
    

    http://jsfiddle.net/KSgV7/585/

提交回复
热议问题