我有一个甘特图(RangeBar),我用MS Chart控件制作;对于一些较短的系列,标签会显示在栏外;我宁愿设置它,以使标签留在酒吧内并被截断(省略号会很好)。有没有办法做到这一点?我一直在图表和系列的属性中徘徊多年,但没有成功。MS Chart控制系列标签定位
0
A
回答
3
我认为你需要设置的属性是BarLabelStyle
如。
chart.Series["mySeries"]["BarLabelStyle"] = "Center";
见本Dundas page解释这应该是对于MS图表控制相似或相同的自定义属性。
0
在我滚到底我自己使用这个(是的,它的混乱,它会得到收拾,当我有时间):
private static void Chart_PostPaint(object sender, ChartPaintEventArgs e)
{
Chart c = ((Chart)sender);
foreach (Series s in c.Series)
{
string sVt = s.GetCustomProperty("PixelPointWidth");
IGanttable ig = (IGanttable)s.Tag;
double dblPixelWidth = c.ChartAreas[0].AxisY.ValueToPixelPosition(s.Points[0].YValues[1]) - c.ChartAreas[0].AxisY.ValueToPixelPosition(s.Points[0].YValues[0]);
s.Label = ig.Text.AutoEllipsis(s.Font, Convert.ToInt32(dblPixelWidth)-dblSeriesPaddingGuess);
}
}
public static string AutoEllipsis(this String s, Font f, int intPixelWidth)
{
if (s.Length == 0 || intPixelWidth == 0) return "";
var result = Regex.Split(s, "\r\n|\r|\n");
List<string> l = new List<string>();
foreach(string str in result)
{
int vt = TextRenderer.MeasureText(str, f).Width;
if (vt < intPixelWidth)
{ l.Add(str); }
else
{
string strTemp = str;
int i = str.Length;
while (TextRenderer.MeasureText(strTemp + "…", f).Width > intPixelWidth)
{
strTemp = str.Substring(0, --i);
if (i == 0) break;
}
l.Add(strTemp + "…");
}
}
return String.Join("\r\n", l);
}
这似乎很乐意,只要它是Post_Paint
工作事件(如果您使用Paint
事件,它将停止显示工具提示)
相关问题
- 1. 长标签似乎隐藏着“...” - MS Chart饼图控件
- 2. MS Chart控制轴格式化
- 3. 本地化MS Chart控件
- 4. 图表控件:堆叠柱系列标签定位
- 5. MS图表系列作为标签
- 6. MS Chart绘制条形图
- 7. C#图表控制系列由自定义标签覆盖
- 8. MS图表控件:定位标签之间的网格线
- 9. Excel Chart系列像素位置
- 10. Google Bubble Chart标签
- 11. 如何使用ms图表控件自定义系列数据点标签
- 12. ColdFusion Chart x轴标签限制
- 13. Google Chart Chart包装过滤器标签
- 14. 如何在.NET中调整MS Chart的x轴标签的位置?
- 15. Sencha Ext JS 4 Chart:自定义xField(类别)标签位置
- 16. MS Chart XValueType
- 17. MS Chart的Response.redirect
- 18. MS Chart分组
- 19. Microsoft Chart绘制点坐标
- 20. 以对数形式显示刻度标签MS Chart(log-log)
- 21. 在MS Chart for .NET中关闭点标签
- 22. MS Chart:如何将轴标签放置在它的扩展中
- 23. MS Chart AxisX标签应该对齐不可交替
- 24. Google Chart HTML定位
- 25. 系列标签
- 26. 标签栏控制器位置
- 27. 位置控制和标签水平
- 28. Chart Toolkit上的标签WPF
- 29. Google Chart Tools - 重叠标签
- 30. MS Chart删除系列之间的空间
对不起,这不会改变任何东西对我来说:| – 2011-04-15 22:49:15
我确认这确实显示了在MSChart中以条为中心的标签。 – peterincumbria 2014-03-15 08:56:57