3
我想绘制图像到DataVisualization.Charting.Chart
的背景。由于ChartArea.BackImage
属性只接受图像的路径,因此无法将此值设置为运行时图像。绘制Winform图表的背景而不会覆盖网格
为此我把PrePaint Event
图表上绘制图表图形(I去除部分代码和替换为蓝色矩形图像):
private void chart1_PrePaint(object sender, System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs e)
{
double xMax = e.ChartGraphics.GetPositionFromAxis("ChartArea1", AxisName.X, chart1.ChartAreas[0].AxisX.Maximum);
double xMin = e.ChartGraphics.GetPositionFromAxis("ChartArea1", AxisName.X, chart1.ChartAreas[0].AxisX.Minimum);
double yMax = e.ChartGraphics.GetPositionFromAxis("ChartArea1", AxisName.Y, chart1.ChartAreas[0].AxisY.Minimum);
double yMin = e.ChartGraphics.GetPositionFromAxis("ChartArea1", AxisName.Y, chart1.ChartAreas[0].AxisY.Maximum);
double width = xMax-xMin;
double heigth = yMax- yMin;
RectangleF myRect = new RectangleF((float)xMin,(float)yMin,(float)width,(float)heigth);
myRect = e.ChartGraphics.GetAbsoluteRectangle(myRect);
e.ChartGraphics.Graphics.FillRectangle(new SolidBrush(Color.LightBlue), myRect);
}
的问题是,这图表网格被覆盖的方式(见左图)。但我希望网格可见(见左图)。有任何想法吗?
你可以节省你的内存图像文件在一个临时目录,并使用你所提到的'ChartArea.BackImage'财产... – adv12
我会尝试,但我有点担心的表现,因为我想经常更新背景 – RomCoo
是的,这将是一个问题。 – adv12