MS图表(.Net 3.5):图例/键中的线条粗细 [英] MS Chart (.Net 3.5): Line thickness in legend/key

查看:102
本文介绍了MS图表(.Net 3.5):图例/键中的线条粗细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于.Net 3.5的MS Chart组件,并且正在使用它来构建图元文件. (我们将其嵌入到RTF报告中.)为了解决WMF坐标精度不佳的问题,我的虚拟图表区域较大(6000×4000)像素.

我正在使用以下方法缩放所有内容:

I''m using the MS Chart component for .Net 3.5, and I''m using it to construct a metafile. (We''re embedding it in an RTF report.) In order to work around the issue with WMF coordinates being poor precision, my virtual chart area is large (6000×4000) pixels.

I am rescaling everything with the following method:

public void UpdateScaledElements()
{
    float scaleFactor = Chart.Height / 400f;
    foreach (Series s in Chart.Series)
    {
        s.Font = new Font(FONT_NAME, 8 * scaleFactor);
        s.BorderWidth = (int)(1.6 * scaleFactor);
        s.MarkerSize = (int)(6 * scaleFactor);
    }
    foreach (Legend l in Chart.Legends) {
        l.Font = new Font(FONT_NAME, 8 * scaleFactor);
    }
    foreach (Axis a in Chart.ChartAreas[0].Axes)
    {
        a.TitleFont = new Font(FONT_NAME, 10 * scaleFactor);
        a.LabelStyle.Font = new Font(FONT_NAME, 8 * scaleFactor);
        a.LineWidth = (int)(2 * scaleFactor);
    }
}



运行良好.但是,我不知道如何使图例/关键点中绘制的线的线宽扩大.我希望他们能像标记刻度和颜色一样从系列中获得成功.我已经搜索过,但是找不到解决方法.

我尝试过更改l.BorderWidth(实际上会更改键的边框,而不是其中的线条),在此方法中重建键,并使用CustomizeLegend事件在单个项目上设置BorderWidth.这些都没有改变默认行为,似乎是1个单位–打印时将是发际线,而不是像该系列那样漂亮的粗线.

我已经通过自己在PostPaint处理程序中画线来解决"此问题.这是一个hack,所以我仍然在市场上寻求一种优雅的解决方案.



It''s working pretty well. However, I can''t work out how to make the line thickness of the lines drawn in the legend/key to scale up. I expected them to come through from the series like the marker scale and colour do. I''ve searched but I can''t find a solution.

I have tried changing l.BorderWidth (it actually does change the border of the key, not lines within it), rebuilding the key in this method, and using the CustomizeLegend event to set BorderWidth on individual items. None of those changed the default behaviour, which seems to be 1 unit – which will be a hairline when this is printed, not a nice bold line like the series.

I have ''solved'' this by painting the line myself in a PostPaint handler. This is a hack so I''m still in the market for an elegant solution.

推荐答案

您是否可以将图像用作图例值(我想您想彩色的盒子或线条)?

还是可以尝试使用像这样的自定义图例项目,该项目来自MSCharts示例程序:

Can you possibly use an image for the legend value (I assume you want a colored box or line)?

Or could you try using a custom legend item like this, which is taken from the MSCharts sample program:

legendItem = new LegendItem();
legendItem.Name = "Marker Style Item";
legendItem.Style = LegendImageStyle.Marker;
legendItem.ShadowOffset = 1;
legendItem.Color = Color.Yellow;
legendItem.MarkerStyle = MarkerStyle.Cross;
legendItem.MarkerSize = 10;
legendItem.MarkerBorderColor = Color.Black;
chart1.Legends["Default"].CustomItems.Add(legendItem);


这篇关于MS图表(.Net 3.5):图例/键中的线条粗细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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