MS Chart connecting all datapoints without lines crossing [closed]

一世执手 提交于 2019-12-14 03:31:27

问题


I have datapoints in a MS chart and I would like to connect all these datapoints with lines, where none of the lines cross each other. Each datapoint will be connected to 2 other datapoints.

The plot should look like a closed loop, it is very important that there will be no lines that cross on top of another.

Is there an easy way to achieve this?


回答1:


OK, I misspoke: It actually is not that hard, that is unless one wants more restrictions than what you gave. Here is a radar-beam method that ought to work:

  • Let's start with a list of points
  • From it we create a List<Tuple<PointF, float, float>>
  • Then we find the minimum and maximum x and y values and from these the center point c
  • Next we fill each Tuple's two floats by calculating the angle and the distance between each point and the center c
  • Finally we order by angle and then by distance
  • Now we can traverse the list and create DataPoints from it we add to our Series.
  • To close the loop we add the first DataPoint again at the end.

This connects without any crossings but I believe some results will look uglier than what a hand-crafted solution would be. In fact most examples will look like an explosion ;-)

OTOH: Isn't is remarkable how those lines add a visible structure to the chaos?

Here is an example with 100 random points.



来源:https://stackoverflow.com/questions/45909054/ms-chart-connecting-all-datapoints-without-lines-crossing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!