我需要自动绘制完整的图表。完整图表将取决于用户输入的节点数量。两个节点之间的权重是随机分配的。使用的方法效率低,因为要绘制九个节点的图形,用户必须在屏幕上点击九次。此外,为了在两个节点之间绘制边缘,用户必须最多在两个节点处右键单击以建立链接。我试图寻找一些在线的例子,但我似乎找不到任何东西。这就是我到目前为止所做的事情
CODE
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Label v = new Label();
v.Content = E;
Ellipse cir = new Ellipse();
cir.Width = 16.5;
cir.Height = 16;
circ.Stroke = Brushes.MediumAquamarine;
circ.StrokeThickness = 2;
CanvasMiddle.Children.Add(circ);
Point a = e.GetPosition(circ);
Canvas.SetLeft(circ, a.X-3);
Canvas.SetTop(circle, a.Y+1);
Vertex.Add(i, new Tuple<double, double>(a.X, a.Y));
CanvasMiddle.Children.Add(value);
Point coordinates = e.GetPosition(v);
Canvas.SetLeft(v, coordinates.X-5);
Canvas.SetTop(va, coordinates.Y-5);
f++;
i++;
}
//生成两个节点之间的边缘
private void Window_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
for (int i = 1; i <= Node.Count; i++)
{
E1 = Node[i].Item1 - 13; a2 = Node[i].Item1 + 13;
G1 = Node[i].Item2 - 13; b2 = Node[i].Item2 + 13;
if ((P >= E1 && P <= G1) && (Q >= E1 && Q <= G1))
{
ID1[j] = i;
j++;
if (j == 2)
{
Line li = new Line();
li.X1 = Vertex[ID1[0]].Item1 + 5;
li.Y1 = Vertex[ID1[0]].Item2 + 5;
li.X2 =(line.X2-13)+ (Vertex[ID1[1]].Item1 + 5);
li.Y2 =(line.Y2) + (Vertex[ID1[1]].Item2 + 5);
li.Stroke = Brushes.MediumAquamarine;
li.StrokeThickness = 2;
Point co1 = e.GetPosition(li);
Canvas.SetLeft(li, co1.X+2.78);
Canvas.SetTop(li, co1.Y+1.85);
CanvasMiddle.Children.Add(li);
j = 0;
}
图片: 这是手头特定图表的链接。