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