简体   繁体   English

Morris.js 在 w3css 幻灯片中未正确呈现

[英]Morris.js not rendering correct in w3css slideshow

I am trying to make a slideshow of 2 Morris.js charts with w3css slideshow.我正在尝试使用 w3css 幻灯片制作 2 个 Morris.js 图表的幻灯片。
(I used this: https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_dots and replace the images with 2 Morris.js charts with hardcoded data) (我使用了这个: https ://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_dots 并用硬编码数据的 2 个 Morris.js 图表替换图像)
first chart is drawn correctly but the second one is somehow croped.第一个图表绘制正确,但第二个图表以某种方式被裁剪。
What I have tried is to store the Morris charts in local vars and redraw the charts when the slide changes, but still no luck.我尝试过的是将莫里斯图表存储在本地变量中,并在幻灯片更改时重新绘制图表,但仍然没有运气。
any idea what I'm doing wrong?知道我做错了什么吗?

<div class="w3-content" style="max-width:800px">
    <div class="mySlides" id="graph1" style="width:100%"></div>
    <div class="mySlides" id="graph2" style="width:100%"></div>
</div>

<div class="w3-center">
  <div class="w3-section">
    <button class="w3-button w3-light-grey" onclick="plusDivs(-1)">❮ Prev</button>
    <button class="w3-button w3-light-grey" onclick="plusDivs(1)">Next ❯</button>
  </div>
  <button class="w3-button demo" onclick="currentDiv(1)">1</button> 
  <button class="w3-button demo" onclick="currentDiv(2)">2</button> 
</div>

<script>

Morris.Line({
  element: 'graph1',
  data: week_data,
  xkey: 'period',
  ykeys: ['licensed'],
  labels: ['Licensed']
});
Morris.Line({
  element: 'graph2',
  data: week_data,
  xkey: 'period',
  ykeys: ['licensed'],
  labels: ['Licensed']
});
</script>

</body>
</html>

It seems that I cannot paste the entire html so, the rest of the code can be found in here:似乎我无法粘贴整个 html,所以可以在这里找到其余的代码:
https://jsfiddle.net/d5p16q2z/1/ https://jsfiddle.net/d5p16q2z/1/

You probably need to resize the width of the SVG element.您可能需要调整 SVG 元素的宽度。 When I have such problems, I do something like this:当我遇到此类问题时,我会这样做:

$('#graph1 svg').width($('div.mySlides').width());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM