VB.Net Box Plot Creation

时间:2018-01-09 21:10:33

标签: vb.net boxplot

我正在努力了解 boxplots 如何工作 VB.Net 。以下工作,但它绘制 boxplot 以及条形图。我只想要盒子图。我已经发现你可以禁用违规系列将它们从图表中删除但这似乎是错误的方法......

当前情节

Current Plot

我的代码出了什么问题?同样,我想要的只是箱线图。

    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("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"

1 个答案:

答案 0 :(得分:2)

禁用这些系列

Chart1.Series("1").Enabled = False
Chart1.Series("2").Enabled = False

enter image description here

也许你不喜欢这个系列的custom properties如何运作。我也不是!但似乎无法通过字符串名称对它们进行索引(并将值设置为字符串,即使它们是布尔值或数字,如您所见)。以下是这些属性的complete list

我将对创建它们的范围之外的系列进行对象引用。然后,您可以根据需要稍后操作它们(即添加/更改数据),而无需使用字符串名称索引图表的Series集合。这可能会有所缓解

Private boxPlotSeries As Series
Private series1 As Series
Private series2 As Series

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    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()

    boxPlotSeries = New Series() With {
        .Name = "BoxPlotSeries",
        .ChartType = SeriesChartType.BoxPlot}

    boxPlotSeries("BoxPlotSeries") = "1;2"
    boxPlotSeries("BoxPlotWhiskerPercentile") = "15"
    boxPlotSeries("BoxPlotShowAverage") = "True"
    boxPlotSeries("BoxPlotShowMedian") = "True"
    boxPlotSeries("BoxPlotShowUnusualValues") = "True"

    series1 = New Series() With {
        .Name = "1",
        .Enabled = False}
    series1.Points.DataBindY(yVal)

    series2 = New Series() With {
        .Name = "2",
        .Enabled = False}
    series2.Points.DataBindY(yVal2)

    Chart1.Series.Add(boxPlotSeries)
    Chart1.Series.Add(series1)
    Chart1.Series.Add(series2)

End Sub