需要逻辑根据点数、间隔和图表区域确定标记大小

发布于 2024-12-11 13:23:19 字数 375 浏览 0 评论 0原文

我正在绘制 xy 点图。我需要根据图表区域、总 xy 点计数以及 X 轴和 Y 轴上点之间的最小间隔来选择标记大小,以便点不会相互重叠。

目前我正在这样做:

int marginWidth = chart1.Size.Width;
int marginHeight = chart1.Size.Height;

chart1.Series[0].MarkerSize = (((marginWidth * marginHeight) / (marginWidth + marginHeight)) /18)

18 只是大约 100 个 xy 点的校准值。但显然,当点数增加时,需要减小标记大小以获得更好的可见性。

谁能指导我这个逻辑?

I am plotting xy point chart. I need to select the marker size so that the points do not overlap each other based on chart area, total xy point count and minimum interval between points on X and Y axis.

Currently I am doing like this:

int marginWidth = chart1.Size.Width;
int marginHeight = chart1.Size.Height;

chart1.Series[0].MarkerSize = (((marginWidth * marginHeight) / (marginWidth + marginHeight)) /18)

18 is just a calibrated value for about 100 xy points. But obviously, when point count increases markersize needs to be decreased for better visibility.

Can anyone guide me a logic for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等往事风中吹 2024-12-18 13:23:19

我看到一个“简单”的解决方案:根据您的数据设置标记大小。因此,您应该输入 Chart1.Series[0].Count 或类似的内容,而不是“18”=)

I see an "easy" solution : set the marker size depending of your data. So instead of "18" you should put chart1.Series[0].Count or something like this =)

梦醒时光 2024-12-18 13:23:19

试试这个(计算两个标记之间的距离)
标记大小 = 距离

//chart object PrePaint event...     
private void chart1_PrePaint(object sender, ChartPaintEventArgs e)
    {

        //get the PixelPosition of first Marker
        double X1 = chart1.ChartAreas[0].AxisX.ValueToPixelPosition(1); //X 
        double Y1 = chart1.ChartAreas[0].AxisY.ValueToPixelPosition(1); //Y
        //get the PixelPosition of second Marker(X-Axis)
        double X2 = chart1.ChartAreas[0].AxisX.ValueToPixelPosition(2); //X
        double Y2 = chart1.ChartAreas[0].AxisY.ValueToPixelPosition(1); //Y
        //get the PixelPosition of second Marker(Y-Axis)
        double X3 = chart1.ChartAreas[0].AxisX.ValueToPixelPosition(1); //X
        double Y3 = chart1.ChartAreas[0].AxisY.ValueToPixelPosition(2); //Y
        //Calculate the Distance by Pythagoras (c² = a² + b²)
        //=> a² = (X1 - X2)² && b² = (Y1-Y2)²
        //Sorry is in german but the video explain
        //http://matheguru.com/lineare-algebra/224-abstand-zwischen-zwei-punkten.html
        double disctanceX = Math.Sqrt(Math.Pow(X1 - X2, 2) + Math.Pow(Y1 - Y2, 2));
        double disctanceY = Math.Sqrt(Math.Pow(X1 - X3, 2) + Math.Pow(Y1 - Y3, 2));

        //limit the marker at smaller value
        if (disctanceX < disctanceY)
        {
                                          //cut the decimals other routines are possible
            chart1.Series[0].MarkerSize = (int) Math.Ceiling(disctanceX);
        }
        else
        {
            chart1.Series[0].MarkerSize = (int) Math.Ceiling(disctanceY);
        }
    }

Try This (Calculate the Distance between two Markers)
Markersize = Distance

//chart object PrePaint event...     
private void chart1_PrePaint(object sender, ChartPaintEventArgs e)
    {

        //get the PixelPosition of first Marker
        double X1 = chart1.ChartAreas[0].AxisX.ValueToPixelPosition(1); //X 
        double Y1 = chart1.ChartAreas[0].AxisY.ValueToPixelPosition(1); //Y
        //get the PixelPosition of second Marker(X-Axis)
        double X2 = chart1.ChartAreas[0].AxisX.ValueToPixelPosition(2); //X
        double Y2 = chart1.ChartAreas[0].AxisY.ValueToPixelPosition(1); //Y
        //get the PixelPosition of second Marker(Y-Axis)
        double X3 = chart1.ChartAreas[0].AxisX.ValueToPixelPosition(1); //X
        double Y3 = chart1.ChartAreas[0].AxisY.ValueToPixelPosition(2); //Y
        //Calculate the Distance by Pythagoras (c² = a² + b²)
        //=> a² = (X1 - X2)² && b² = (Y1-Y2)²
        //Sorry is in german but the video explain
        //http://matheguru.com/lineare-algebra/224-abstand-zwischen-zwei-punkten.html
        double disctanceX = Math.Sqrt(Math.Pow(X1 - X2, 2) + Math.Pow(Y1 - Y2, 2));
        double disctanceY = Math.Sqrt(Math.Pow(X1 - X3, 2) + Math.Pow(Y1 - Y3, 2));

        //limit the marker at smaller value
        if (disctanceX < disctanceY)
        {
                                          //cut the decimals other routines are possible
            chart1.Series[0].MarkerSize = (int) Math.Ceiling(disctanceX);
        }
        else
        {
            chart1.Series[0].MarkerSize = (int) Math.Ceiling(disctanceY);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文