yannickpulver
yannickpulver

Reputation: 2275

Smaller margin on VB.NET Chart

Is there a way to customize the margin between the first bar chart and the Y-Axis?

I'm aware that there is the possibility to set IsMarginVisible to False:

.AxisX.IsMarginVisible = False

But I don't want to remove the margin completely, I just would like to adjust it a bit. In âddition, I would like to adjust the margin between the "ticks" and the label text. Here is an example:

Here is how the chart looks right now

Old

And how it should look like (space in front and after the "ticks") New

Do you have an idea how to solve this problem?

Upvotes: 10

Views: 1329

Answers (4)

David BS
David BS

Reputation: 1892

Why don't you add manually some "blank spaces" into each Y value, converting them to a string like "50,000 "?

Upvotes: 0

yannickpulver
yannickpulver

Reputation: 2275

Unfortunately, it looks like that there is no margin property in the way I would have liked one. But I stumbled upon this article today: http://support2.dundas.com/Default.aspx?article=869

My workaround was to set the MajorTickMark to the size of the ticks I wanted to have + the margin. Then I set the color to transparent.

Chart1.ChartAreas(0).AxisY.MajorTickMark.Size = size
Chart1.ChartAreas(0).AxisY.MajorTickMark.LineColor = Color.FromArgb(0, 0, 0, 0)

After that, I just added a HorizontalLineAnnotation for every row in the size and place I wanted.

Dim minValue As Double = Chart1.ChartAreas("ChartArea").AxisY.Minimum
Dim maxValue As Double = Chart1.ChartAreas("ChartArea").AxisY.Maximum
Dim iteration As Integer = CInt((Math.Abs(minValue) + Math.Abs(maxValue )) / interval)

For i As Integer = 0 To iteration
    Dim line As New HorizontalLineAnnotation()
    With line
        .AxisX = Chart1.ChartAreas("ChartArea").AxisX
        .AxisY = Chart1.ChartAreas("ChartArea").AxisY
        .AnchorX = 0
        .Y = i * interval - Math.Abs(minValue)
        .AnchorOffsetX = offset
        .Height = 0
        .LineWidth = 1
        .Width = (5 / Chart1.Width.Value * 1240)
        .LineColor = Color.FromArgb(128, 128, 128)
        End With
    Chart1.Annotations.Add(line)
Next

With this workaround, I got the result I wanted.

Upvotes: 2

Monica
Monica

Reputation: 15

try this:

chart1.ChartAreas("Default").AxisY.ScaleBreakStyle.Spacing = 2

Upvotes: 0

Doug Coats
Doug Coats

Reputation: 7117

 With Chart1.Series(0)

        .BackGradientStyle = GradientStyle.TopBottom
        .Color = Color.Magenta
        .BackSecondaryColor = Color.Purple
        .IsValueShownAsLabel = True
        .Points.DataBind(dtTest.DefaultView, "Month", "Bought", Nothing)
        *****The pixel point width******.CustomProperties = "DrawingStyle = Cylinder ,PixelPointWidth = 26"
    End With

Is this what you are looking for?

Upvotes: 0

Related Questions