以下代码在VB.net中创建一个简单的boxplot。但是,我无法弄清楚如何更改x轴标签。目前他们是1和2但我需要它们是文本值。我还希望删除所有数字标签:
Dim yVal As Double() = {55.62, 45.54, 73.45, 9.73, 88.42, 45.9, 63.6, 85.1, 67.2, 23.6}
Dim yVal2 As Double() = {35.62, 25.54, 43.45, 23.73, 43.42, 12.9, 23.6, 65.1, 54.2, 41.6}
Chart1.Series.Clear()
Chart1.Series.Add("BoxPlotSeries")
Chart1.Series.Add("1")
Chart1.Series("1").Points.DataBindY(yVal)
Chart1.Series.Add("2")
Chart1.Series("2").Points.DataBindY(yVal2)
Chart1.Series("1").Enabled = False
Chart1.Series("2").Enabled = False
Chart1.Series("BoxPlotSeries").ChartType = SeriesChartType.BoxPlot
Chart1.Series("BoxPlotSeries")("BoxPlotSeries") = "1;2"
Chart1.Series("BoxPlotSeries")("BoxPlotWhiskerPercentile") = "15"
Chart1.Series("BoxPlotSeries")("BoxPlotShowAverage") = "true"
Chart1.Series("BoxPlotSeries")("BoxPlotShowMedian") = "true"
Chart1.Series("BoxPlotSeries")("BoxPlotShowUnusualValues") = "true"
答案 0 :(得分:1)
您必须将自定义标签添加到新的ChartArea1,然后将BoxPlotSeries链接到ChartArea1,以便可以控制轴。实际上还有更多,我已经添加了什么使它工作。我还在Y轴值中包含2点小数精度(“N2”),您可以使用“= N0”将其更改为整数。我也会关闭垂直和水平网格,因为它们在数学图中看起来很可怕。将以下所有代码放在代码之后:
'Create new chart area called "ChartArea1", link BoxPlotSeries to it
Dim ChartArea1 As New ChartArea
ChartArea1.Name = "ChartArea1"
Chart1.ChartAreas.Add(ChartArea1)
Chart1.Series("BoxPlotSeries").ChartArea = "ChartArea1"
'Add the custom labels "One" and "Two" to the X-axis
Chart1.ChartAreas("ChartArea1").AxisX.CustomLabels.Add((1) * 2D, 0.0, "One")
Chart1.ChartAreas("ChartArea1").AxisX.CustomLabels.Add((2) * 2D, 0.0, "Two")
'X-Axis
Chart1.ChartAreas("ChartArea1").AxisX.MajorGrid.Enabled = False
Chart1.ChartAreas("ChartArea1").AxisX.IntervalAutoMode = False
Chart1.ChartAreas("ChartArea1").AxisX.MajorTickMark.LineWidth = 3
Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.Angle = -90
Chart1.ChartAreas("ChartArea1").AxisX.IsLabelAutoFit = True
Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.IsEndLabelVisible = True
Chart1.ChartAreas("ChartArea1").AxisX.IsMarginVisible = True
'Y-Axis
Chart1.ChartAreas("ChartArea1").AxisY.MajorGrid.Enabled = False
Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Format = "N2"
Chart1.ChartAreas("ChartArea1").AxisY.LabelStyle.Angle = 0
Chart1.ChartAreas("ChartArea1").AxisY.IntervalAutoMode = True
Chart1.ChartAreas("ChartArea1").AxisY.MajorTickMark.LineWidth = 3