0
我有一個WinForms應用程序,它包含一個名爲如何在Winforms中的圖表控件中修改X軸上的x值?
comparisonChart
圖表控件我已經訂閱的鼠標滾輪事件,並執行以下操作來實現對圖表控件變焦能力。
private void comparisonChartMouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta < 0)
{
this.comparisonChart.ChartAreas[0].AxisX.ScaleView.ZoomReset(0);
this.comparisonChart.ChartAreas[0].AxisY.ScaleView.ZoomReset(0);
}
else if (e.Delta > 0)
{
double xMin = this.comparisonChart.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
double xMax = this.comparisonChart.ChartAreas[0].AxisX.ScaleView.ViewMaximum;
double yMin = this.comparisonChart.ChartAreas[0].AxisY.ScaleView.ViewMinimum;
double yMax = this.comparisonChart.ChartAreas[0].AxisY.ScaleView.ViewMaximum;
double posXStart = this.comparisonChart.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) - (xMax - xMin)/4;
double posXFinish = this.comparisonChart.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X) + (xMax - xMin)/4;
double posYStart = this.comparisonChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) - (yMax - yMin)/4;
double posYFinish = this.comparisonChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Location.Y) + (yMax - yMin)/4;
this.comparisonChart.ChartAreas[0].AxisX.ScaleView.Zoom(posXStart, posXFinish);
this.comparisonChart.ChartAreas[0].AxisY.ScaleView.Zoom(posXStart, posXFinish);
}
}
當我放大圖表時,X軸值顯示十進制值。
要刪除小數值,我也做了以下操作。
comparisonChart.Series[0].XValueType = ChartValueType.Int32;
但同樣是示出當我放大十進制值。
是啊,這是我一直在尋找。謝謝 – Kaushik
@Kaushik - 很高興幫助:) – Junaith