【发布时间】:2015-07-11 06:24:52
【问题描述】:
我在 winforms 中创建了一个图表,并使用 winformhost 在 WPF 中托管它。当我在 wpf 中实现它时,我的图表下方有一个空格。如果我减小图表的大小,图表会变小。如何删除图表下方的空间?
这是我的代码。
XAML.cs
var chartArea = new ChartArea("EQGraph");
Chart chart1 = this.FindName("EQGraph") as Chart;
chart1.ChartAreas.Add("EQGraph");
chart1.Series.Add("Front Left");
chart1.ChartAreas[0].AxisX.Maximum = 20000;
chart1.ChartAreas[0].AxisX.Minimum = 10;
chart1.ChartAreas[0].AxisX.IsLogarithmic = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 1;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisY.Maximum = 20;
chart1.ChartAreas[0].AxisY.Minimum = -50;
chart1.ChartAreas[0].AxisY.Interval = 5;
chart1.ChartAreas[0].AxisX.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDotDot;
chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.DashDotDot;
chart1.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 10F, System.Drawing.FontStyle.Bold);
chart1.ChartAreas[0].AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 10F, System.Drawing.FontStyle.Bold);
chart1.ChartAreas[0].AxisX.Title = "Frequency(Hz)";
chart1.ChartAreas[0].AxisY.Title = "Gain";
int[] xValuesFrontLeft = { 10, 100, 1000, 5000, 4200, 8499 };
int[] yValuesFrontLeft = { 16, 10, -5, -10, 35, -40 };
chart1.Series["Front Left"].Points.DataBindXY(xValuesFrontLeft, yValuesFrontLeft);
chart1.Series["Front Left"].ChartType = SeriesChartType.Spline;
XAML
<DockPanel Grid.Column="3" Grid.Row="1" Grid.RowSpan="9" Background="#FFFBF9F9">
<WindowsFormsHost x:Name="host" Height="500">
<winformchart:Chart x:Name="EQGraph" Dock="Fill">
<winformchart:Chart.Series >
<winformchart:Series Name="series" ChartType="Line"/>
</winformchart:Chart.Series>
<winformchart:Chart.ChartAreas>
<winformchart:ChartArea/>
</winformchart:Chart.ChartAreas>
</winformchart:Chart>
</WindowsFormsHost>
</DockPanel>
【问题讨论】: