【问题标题】:jquery-selector - canvasjs vs. echartsjquery-selector - canvasjs vs. echarts
【发布时间】:2017-05-18 08:25:27
【问题描述】:

canvasjs 允许以简单的方式将图形导出为 pdf: http://jsfiddle.net/canvasjs/cm1qyk2L/

我正在尝试与echarts 相同,但我不知道如何正确采用上述 jsfiddle 中的第 21 行。什么是正确的 jquery 选择器?

    <div id="main" style="width: 750px;height:500px;"></div>
    <script type="text/javascript">
        // based on prepared DOM, initialize echarts instance
        var myChart = echarts.init(document.getElementById('main'));

        // specify chart configuration item and data
        var 

option = {
    color: ['#3398DB'],
    tooltip : {
        trigger: 'axis',
        axisPointer : {            
            type : 'shadow'        
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            data : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
            axisTick: {
                alignWithLabel: true
            }
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name:'Salami',
            type:'bar',
            barWidth: '60%',
            data:[10, 52, 200, 334, 390, 330, 220]
        }
    ]
};
        // use configuration item and data specified to show chart
        myChart.setOption(option);

//console.log(dataURL);

var canvas = $("#main .").get(0);
var dataURL = canvas.toDataURL();
//console.log(dataURL);

$("#exportButton").click(function(){
    var pdf = new jsPDF();
    pdf.addImage(dataURL, 'JPEG', 0, 0);
    pdf.save("download.pdf");
});

   </script>
<button id="exportButton" type="button">Export as PDF</button>

【问题讨论】:

    标签: jquery canvasjs echarts


    【解决方案1】:

    这是我的解决方案:

    var canvas = $("#main canvas").get(0);
    
    $(document).ready(function(){
        $("#exportButton").click(function(){
            var dataURL = canvas.toDataURL("image/jpeg", 1.0);
            var pdf = new jsPDF();
            pdf.addImage(dataURL, 'JPEG', 0, 0);
            pdf.save("download.pdf");
        });
    });
    

    https://plnkr.co/edit/Wv8JNWeYNxsLH798wnx8?p=preview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-18
      • 2017-06-09
      • 2016-02-21
      • 2018-03-04
      • 2011-08-30
      • 2012-02-02
      相关资源
      最近更新 更多