javascript - chart.js renders outside div and canvas -


my charts rendering correctly, overlapping on same spot , change between depending on mouseover (both graphs in same position though canvas , div elements not). here images show div , canvas locations:

canvas 1 canvas 2

i not familiar css used tutorial snippets temporary layout before begin change style , colours, need on positioning these elements correctly.

here html code:

<div id="awp" class="tabcontent">     <div class="dropdown">         <button onclick="dropmenu(1)" class="dropbtn">choose dates</button>         <div id="mydropdown1" class="dropdown-content">             <a id="2016" onclick="adddata(mychart, 'check' , 2)">last 3 months</a>             <a id="5m" onclick="removedata(mychart)">test 3</a>             <a id="testnew">bye bye</a>             <a id = "2015" onclick="addmoredata(mychart)">does</a>         </div>     </div>     <h3>recreated in chart.js first graphs</h3>  <div class="contain1"> <canvas id="results-graph" class="cyo" width="600" height="500"></canvas> </div>  <div class="contain2"> <canvas id="results-graph2" class="oem" width="600" height="500"></canvas> </div> 

here css:

.dropdown {     position: relative;     display: inline-block; }  .dropdown-content {     display: none;     position: absolute;     background-color: #f9f9f9;     min-width: 160px;     box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);     z-index: 1; }  .dropdown-content {     color: black;     padding: 12px 16px;     text-decoration: none;     display: block; }  .dropdown-content a:hover {background-color: #f1f1f1}  .show {display:block;}   .contain1 {     width: 600px;     height: 500px;     float: left;     overflow: auto; }  .contain2 {     width: 600px;     height: 500px;     float: right;     overflow: auto; }  .cyo {     display: block; width: 600px;     height: 500px; }  .oem {     display: block; width: 600px;     height: 500px; } 

here chart code:

<script> var data = [12, 19, 13, 5, 21, 13];  var ctx = document.getelementbyid("results-graph");   var mychart = new chart(ctx, {     type: 'bar',     data: {         labels: ["red", "red" , "yellow", "green", "purple", "orange"],         datasets: [ {             label: 'average watch sell price in usd',             data: data,             type: 'line',             yaxisid: 'b',             fill: false,             backgroundcolor: ['rgba(0,0,0,1)'],             bordercolor: ['rgba(0,0,0,1)']         },          {             label: 'amount of watches sold',             data: data,             yaxisid: 'a',             backgroundcolor: [                 'rgba(255, 99, 132, 1)',                 'rgba(54, 162, 235, 1)',                 'rgba(255, 206, 86, 1)',                 'rgba(75, 192, 192, 1)',                 'rgba(153, 102, 255, 1)',                 'rgba(255, 159, 64, 1)'             ],             bordercolor: [                 'rgba(255,99,132,1)',                 'rgba(54, 162, 235, 1)',                 'rgba(255, 206, 86, 1)',                 'rgba(75, 192, 192, 1)',                 'rgba(153, 102, 255, 1)',                 'rgba(255, 159, 64, 1)'             ],             borderwidth: 1         }          ]     },     options: {         responsive: true,         maintainaspectratio: false,         scales: {              yaxes: [{                 id: 'a',                 type: 'linear',                 position: 'left',                  ticks: {                      beginatzero:true                  },                  scalelabel:{                     display: true,                     labelstring: 'amount sold',                  }               }, {                 id: 'b',                 type: 'linear',                 position: 'right',                  ticks: {                     beginatzero:true                 },                 scalelabel:{                     display: true,                     labelstring: 'average price in usd',                  }             }]         }     } });   </script> <script> var data2 = [12, 19, 13, 5, 21, 13]; var ctx2 = document.getelementbyid("results-graph");  var mychart2 = new chart(ctx2, {     type: 'bar',     data: {         labels: ["red", "red" , "yellow", "green", "purple", "orange"],         datasets: [ {             label: 'average watch sell price in usd',             data: data2,             type: 'line',             yaxisid: 'b',             fill: false,             backgroundcolor: ['rgba(0,0,0,1)'],             bordercolor: ['rgba(0,0,0,1)']         },          {             label: 'amount of watches sold',             data: data2,             yaxisid: 'a',             backgroundcolor: [                 'rgba(255, 99, 132, 1)',                 'rgba(54, 162, 235, 1)',                 'rgba(255, 206, 86, 1)',                 'rgba(75, 192, 192, 1)',                 'rgba(153, 102, 255, 1)',                 'rgba(255, 159, 64, 1)'             ],             bordercolor: [                 'rgba(255,99,132,1)',                 'rgba(54, 162, 235, 1)',                 'rgba(255, 206, 86, 1)',                 'rgba(75, 192, 192, 1)',                 'rgba(153, 102, 255, 1)',                 'rgba(255, 159, 64, 1)'             ],             borderwidth: 1         }          ]     },     options: {         responsive: true,         maintainaspectratio: false,         scales: {              yaxes: [{                 id: 'a',                 type: 'linear',                 position: 'left',                  ticks: {                      beginatzero:true                  },                  scalelabel:{                     display: true,                     labelstring: 'amount sold',                  }               }, {                 id: 'b',                 type: 'linear',                 position: 'right',                  ticks: {                     beginatzero:true                 },                 scalelabel:{                     display: true,                     labelstring: 'average price in usd',                  }             }]         }     } });</script> 

you did not change why second graph did not generate.

var ctx2 = document.getelementbyid("results-graph2"); 

also can provide background , border this.

            backgroundcolor: ['rgba(0,0,0,1)'],             bordercolor: ['rgba(0,0,0,1)'] 

jsfiddle: here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -