填充颜​​色的虚线箭头

问题描述

我使用 konvajs 使用虚线创建了 Konva.Arrow 形状。但是,箭头未填充颜色。我怎样才能让箭头有颜色?

这是我用来制作箭头的代码的基础。

lineConfig['dash'] = [12,8];
lineConfig['points'] = [pos.x,pos.y];
arrowLine = new Konva.Arrow(lineConfig);

解决方法

尝试将 fill 属性也添加到您的箭头中,例如 fill: 'black'。我试图在没有该属性的情况下绘制箭头,但得到的结果与您描述的相同。

这是工作示例:

<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/konva@7.2.5/konva.min.js"></script>
    <meta charset="utf-8" />
    <title>Konva Arrow Demo</title>
    <style>
      body {
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #f0f0f0;
      }
    </style>
  </head>
  <body>
    <div id="container"></div>
    <script>
      var width = window.innerWidth;
      var height = window.innerHeight;

      var stage = new Konva.Stage({
        container: "container",width: width,height: height
      });

      var layer = new Konva.Layer();

      var arrow = new Konva.Arrow({
        x: stage.width() / 4,y: stage.height() / 4,points: [0,10,100],pointerLength: 20,dash: [12,8],pointerWidth: 20,// Comment the following line to get your issue
        fill: "black",stroke: "black",strokeWidth: 4
      });

      // add the shape to the layer
      layer.add(arrow);

      // add the layer to the stage
      stage.add(layer);
    </script>
  </body>
</html>