在图表中显示圆,并以图表单位C#半径 [英] Display circle in chart with radius in chart units C#

查看:189
本文介绍了在图表中显示圆,并以图表单位C#半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:我已经尝试过诸如气泡点和弄乱标记大小之类的事情,但是都不能以实际的网格单位设置半径。气泡图=%和marker = points(忽略网格)

Summary: I've tried things like bubble points and messing around with marker size but neither can be set a radius in actual grid units. Bubble chart=% and marker=points(ignores grid)

如何在图表中添加半径为网格的圆?!

How can I add a circle to my chart with a radius in grid units?!

-----旧-----
我在气泡图中查看了如何更改气泡大小,显然第二个Y值应该控制大小...除了绝对没有作用。

----- Old ----- I've looked up how to change the size of a bubble in the bubble chart and apparently the second Y value should control the size... except it does absolutely nothing.

我不能使用标记大小作为变通方法,因为大小必须以正确的单位而不是像素为单位。

I can not use marker size as a work around because the size needs to be in correct units and not pixels.

唯一能够改变大小的是最小和最大大小值……但是我不能用它精确地控制大小(更不用说了会很傻)。

The only thing that managed to change the size was the Min and Max size values... but I can't accurately control the size with that (not to mention that would be quite silly).

没有代码,因为它没有特殊的代码或设置,应该易于复制。

No code as this Has no special codes or settings and should be easy to replicate.

编辑:
刚刚意识到气泡大小基于其他气泡大小而不是网格。这是一个大问题,因为我需要一个以网格为单位的半径的圆。同样,它需要一个人。

Just realized that bubble sizes are based on other bubble sizes and not the grid. This is a big problem because I need a circle that has a radius in grid units. Also it needs to be alone.

推荐答案


我需要一个半径为网格的圆

I need a circle that has a radius in grid units

MSChart中有3个坐标系:

There are 3 coordinate system in MSChart:


  • 数据

  • 某个区域的百分比,最值得注意的是 ChartArea InnerPlotPosition

  • 像素(图表控件的 ClientArea

  • The data values
  • Percentages of some area, most notably the ChartArea and the InnerPlotPosition
  • Pixels of the Chart control's ClientArea

我假设用网格单位表示数据值,该值也用于显示网格线和刻度线。

I assume by grid units you mean the data values, which are also used to display grid lines and ticks.

要创建圆形或其​​他形状,您可以添加 PolygonAnnotation GraphicsPath 包含一个椭圆,或者只是一个 EllipseAnnotation

To create a circle or other shapes you can either add a PolygonAnnotation with a GraphicsPath that contains an ellipse, or simply an EllipseAnnotation.

或者您可以圆圈。绘制方法如下:

Or you can draw the circle. Here is how to draw:

private void chart_PrePaint(object sender, ChartPaintEventArgs e)
{
    ChartArea ca = chart.ChartAreas[0];
    Axis ax = ca.AxisX;
    Axis ay = ca.AxisY;
    Series s = chart.Series[0];

    DataPoint dpCenter = s.Points[22];

    dpCenter.MarkerStyle = MarkerStyle.Circle;

    double xVal = dpCenter.XValue;
    double yVal = dpCenter.YValues[0];

    double rad = 2;  // <<<<<= radius in values

    float xRad = (float)(ax.ValueToPixelPosition(0) - ax.ValueToPixelPosition(rad));
    float yRad = (float)(ay.ValueToPixelPosition(0) - ay.ValueToPixelPosition(rad));

    float xc = (float)ax.ValueToPixelPosition(xVal);
    float yc = (float)ay.ValueToPixelPosition(yVal);

    Rectangle r = Rectangle.Round(new RectangleF(xc - xRad, yc - yRad, 
        xRad * 2, yRad * 2));

    e.ChartGraphics.Graphics.DrawEllipse(Pens.Red, r );
}

大小以数据值单位给出。要绘制形状,我们需要转换为像素;为此,有轴功能。

The size is given in data value units. To draw the shape we need toconvert to pixels; for this there are axis functions.

请注意,这不是一个完美的圆,因为轴的比例不同。当然,人们可以很容易地选择两个值的最大值或最小值。

Note that it isn't a perfect circle because the axes don't have the same scales. One could easily pick the max or min of both values, of course.

我在特定点周围绘制圆。

I draw the circle around a specific point. Position and size will move and scale with the chart itself.

要绘制另一个位置,只需计算一下它即可。就像我已经做的那样从值中提取。

To draw at another position simply calculate it e.g. from the values just like I already do..

这篇关于在图表中显示圆,并以图表单位C#半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆