控制各个网格线的视觉样式 [英] Control visual styles of individual gridlines

查看:94
本文介绍了控制各个网格线的视觉样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AxisX上有一个带有大约25个标签的c# RangeBar chart.根据我的实时数据,其中一些标签在图表中具有可见的数据点.通常,在25个标签中,大约3/4没有任何数据点.启用了所有水平网格线,这使图表有些混乱.特别是对于在AxisY上更远的数据点,很难一眼就分辨出它们在AxisX上属于哪个标签.

I have a c# RangeBar chart with about 25 labels on the AxisX. Depending on my live data, some of these labels have visible data points in the chart. Typically about 3/4 of the 25 labels don't have any data points. All horizontal gridlines are enabled, which makes the chart a bit cluttered. Especially for data points that are further away on the AxisY, it's difficult to distinguish at a glance to what label on the AxisX they belong.

我的想法是通过给网格线赋予不同的颜色,不同的样式来区分具有可见数据点的AxisX标签,或者完全删除没有相应数据点的AxisX标签的网格线.这有可能吗?因为到目前为止,我发现的所有可控属性和文档都与整个图表的网格线样式有关.

My idea is to differentiate the AxisX labels that have visible data points either by giving their gridline a different color, a different style, or to completely remove gridlines of AxisX labels that have no corresponding data points. Is this even possible? Because all controllable properties and documentation I have found so far is regarding gridline styles of the entire chart.

Btw:不能仅显示具有数据点的AxisX标签. 预先感谢.

Btw: Only showing AxisX labels that have data points is not an option. Thanks in advance.

推荐答案

要减少混乱,可以使用axis.Interval属性.

To reduce clutter you could use the axis.Interval property.

每行行仍将具有相同样式,无论是主行还是副行.

But each line will still have the same style, either of major or of the minor lines.

您可以为所选点添加VerticalLineAnnotations或尝试StripLines.两者都可以自由设置样式.

You could add VerticalLineAnnotations for selected points or try StripLines. Both can be styled freely.

这是正常折线图的示例,其中线随机添加到几个点:

Here is an example of a normal line chart, with lines randomly added to a few points:

通过AnnotationsStriplines可以达到相同的结果.蓝线是StripLine,红线是Annotations.这是向DataPoint添加彩色线条的两个功能:

The same result can be achieved by either Annotations or Striplines. The blue lines are StripLine and the red ones Annotations. Here are two functions to add a colored line to a DataPoint:

void AddStripLine(Chart chart, ChartArea ca, DataPoint dp, Color col)
{
    Axis ax = ca.AxisX;
    StripLine sl = new StripLine();
    sl.BorderColor = col;
    sl.IntervalOffset = dp.XValue;
    sl.Interval = 0;
    sl.StripWidth  = 0;
    sl.BorderWidth  = 1;
    ax.StripLines.Add(sl);
}

如果仔细观察,您会发现唯一的视觉差异是前者在下方,后者在所有其他图表元素上方.

If you look very closely you'll see that the only visual difference is that the former are below, the latter above all other chart elements.

void AddAnnotation(Chart chart, ChartArea ca, DataPoint dp, Color col)
{
    Axis ay = ca.AxisY;
    VerticalLineAnnotation vl = new VerticalLineAnnotation();
    vl.LineColor = col;
    vl.AnchorDataPoint = dp;
    vl.IsInfinitive = true;
    vl.LineWidth = 1;
    vl.Height = ay.Maximum - ay.Minimum;
    vl.ClipToChartArea = ca.Name;
    chart.Annotations.Add(vl);
}

对于Bar图表,请使用HorizontalLineAnnotations并锚定到正确的轴...

For Bar charts use HorizontalLineAnnotations and anchor to the correct axis...

实际上,使用Annotatons是更自然的方法,因为每个对象都是一个单独的对象. StripLines也是,但是每隔重复.为了避免出现重复现象,每个人都需要具有合适的偏移量间隔,以便为每个人确定.但这两种方法都不难.

Using Annotatons is in fact the more natural way, since each is an individual object. StripLines are too, but are repeated at intervals . To avoid visible repetiton each needs to have suitable offsets and intervals to be determined for each. But it isn't hard to do either way.

还请注意,两种类型的线均固定到了它们的DataPoints上,并且会移动,例如调整图表大小时..

Also note that the both types of lines lines are anchored to their DataPoints and will move with them e.g. when chart is resized..

这篇关于控制各个网格线的视觉样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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