【问题标题】:VB.Net Box Plot Series LabelsVB.Net 箱线图系列标签
【发布时间】:2018-03-21 22:17:30
【问题描述】:

以下代码在 VB.net 中创建了一个简单的箱线图。但是,我无法弄清楚如何更改 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"

【问题讨论】:

    标签: vb.net


    【解决方案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
    

    【讨论】:

    • 谢谢!这是一篇从未得到答复的旧帖子 - 非常感谢。
    • 谢谢!我观察到的一件事是我必须注释掉这一行:Chart1.ChartAreas("ChartArea1").AxisX.IsLabelAutoFit = True 以使用以下命令将角度旋转到 -90:Chart1.ChartAreas("ChartArea1").AxisX.LabelStyle.Angle = -90
    猜你喜欢
    • 2014-06-21
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    • 2017-03-21
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多