没有内置的方法可以做到这一点.
一种解决方法是打开3-d,但这将彻底改变图表的外观.
另一种是所有者绘制图表.
这对于列和条类型来说并不容易,因为列的大小不会暴露.
另请注意,重叠列确实难以阅读,尤其是 什么时候你也有Labels.
以下是所有者绘制柱形图的示例.它有几个简化:
所有点Series都有相同的点数并且是对齐的,所有y值都是正数,没有其他装饰.它们都可能被克服,但可能需要一些额外的努力.
private void chart1_PostPaint(object sender, ChartPaintEventArgs e)
{
if (!checkBox2.Checked) return;
int sMax = chart1.Series.Count;
ChartArea ca = chart1.ChartAreas[0];
Axis ax = ca.AxisX;
Axis ay = ca.AxisY;
float py0 = (float)ay.ValueToPixelPosition(ay.Minimum);
Rectangle ipr = Rectangle.Round(InnerPlotPositionClientRectangle(chart1, ca));
int pMax = chart1.Series[0].Points.Count;
float shift = (overlap * sMax) / 2f;
float deltaX = 1f * ipr.Width / (pMax+1);
float colWidth = 1f * deltaX / sMax;
for (int j = 0; j < chart1.Series.Count; j++)
for (int i = 0; i < chart1.Series[j].Points.Count; i++)
{
DataPoint dp = chart1.Series[j].Points[i];
float px = (float)ax.ValueToPixelPosition(dp.XValue);
float py = (float)ay.ValueToPixelPosition(dp.YValues[0]);
using (SolidBrush brush = new SolidBrush(chart1.Series[j].Color))
e.ChartGraphics.Graphics.FillRectangle(brush,
px + j * colWidth - deltaX / 2 - overlap * j + shift, py,
colWidth, py0 - py );
}
}
Run Code Online (Sandbox Code Playgroud)
它使用了一个InnerPlotPositionClientRectangle你可以在这里找到的功能
结果如下:
请注意,要访问系列颜色,您需要将它们应用于图表:
chart1.ApplyPaletteColors();
Run Code Online (Sandbox Code Playgroud)
列宽设置如下:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
for (int j = 0; j < chart1.Series.Count; j++)
chart1.Series[j]["PointWidth"] = numericUpDown1.Value.ToString();
}
Run Code Online (Sandbox Code Playgroud)
在"0"处,列消失.
| 归档时间: |
|
| 查看次数: |
1094 次 |
| 最近记录: |