tonyliang_id 2017-03-31 03:54 采纳率: 54.8%
浏览 2269
已采纳

如何让canvasjs的生成的chart在现有前端框架漂亮显示?

现象:现有前端框架插入canvasjs的生成的chart后,显示效果不好

code:

    <div class="col-sm-12">
        <div class="widget-box">
            <div class="widget-header widget-header-flat widget-header-small">                                                                                                  
            </div>

            <div class="widget-body">
                <div class="widget-main" id="widgetMain">       

                      <!-- canvasjs的生成的chart所处位置 -->                                                                                                
                    <div id="chartContainer"></div>                                                                                                                                                                                                                                                                                                     
                </div><!-- /.widget-main -->
            </div><!-- /.widget-body -->
        </div><!-- /.widget-box -->

显示效果:见图片
图片说明
canvasjs:画各种统计图形的JS
canvasjs官网:http://canvasjs.com/javascript-charts/
canvasjs:官网提供的例子(canvasjs的生成的chart直接放在html的body里面)

 <!DOCTYPE HTML>
<html>
<head>
    <script type="text/javascript">
    window.onload = function() {
        var chart = new CanvasJS.Chart("chartContainer", {
            title: {
                text: "Line Chart"
            },
            axisX: {
                interval: 10
            },
            data: [{
                type: "line",
                dataPoints: [
                  { x: 10, y: 45 },
                  { x: 20, y: 14 },
                  { x: 30, y: 20 },
                  { x: 40, y: 60 },
                  { x: 50, y: 50 },
                  { x: 60, y: 80 },
                  { x: 70, y: 40 },
                  { x: 80, y: 60 },
                  { x: 90, y: 10 },
                  { x: 100, y: 50 },
                  { x: 110, y: 40 },
                  { x: 120, y: 14 },
                  { x: 130, y: 70 },
                  { x: 140, y: 40 },
                  { x: 150, y: 90 },
                ]
            }]
        });
        chart.render();
    }
    </script>
    <script src="../../canvasjs.min.js"></script>
    <title>CanvasJS Example</title>
</head>

<body>
    <div id="chartContainer" style="height: 400px; width: 100%;"></div>
</body>

</html>
  • 写回答

2条回答 默认 最新

  • Go 旅城通票 2017-03-31 04:14
    关注
      <div id="chartContainer"></div>   添加高度,你的没有高度,里面的对象应该是float或者absolute定位了导致容器外框没有括起图标
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题