Jovica
Jovica

Reputation: 444

How to position/expand axis X starting point so that it aligns with axis Y lowest point

When new chart is created, default is that the first and last point are not aligned with Y axis but they are somewhere in the middle of the X axis.

enter image description here

I can not figure out how to put "2010" all the way to the left and "TTM" all the way to the right. Almost half the chartarea space is lost like this.

In Excel it is "position X axis between tick marks" option, but I don't know how to do that in vb.net.

Thanks

Upvotes: 1

Views: 1798

Answers (1)

Karl Stephen
Karl Stephen

Reputation: 1140

Mmmh I see : you're using :

  • either a System.Windows.Forms.DataVisualization.Charting.Chart
  • or a System.Web.UI.DataVisualization.Charting.Chart

That's what I asked by "Which component create your chart ?"

One of the reasons I ended creating my own way of rendering charts from A to Z is the issue like yours.

Anyway, your problem is the "add axis then modify min/max syndrome". I don't use your component a lot, so I don't really have the fix to the issue. What I know is :

  • When you create a Charting.Chart component (or add one to your project)
  • then you add X and Y axis

^^ those ones are somewhat locked :( - Didn't checked how to modify them after...
What I've done as a workaround long ago is :

  • create programatically the X and Y axes without adding them to the ChartArea.
  • define X min and max values
  • then when I'm done, set the chartArea X and Y axis accordingly

    ' Imports System.Windows.Forms.DataVisualization.Charting
    
    ' ...
    
    xAxis = New Axis() ' <- dont tie the axis to the chartArea
    
    ' now, either define the MarginVisible Property to False :
    xAxis.IsMarginVisible = False
    ' either specify the min/max (and eventually the Crossing Property)
    xAxis.Minimum = xValues(0)
    xAxis.Maximum = xValues(xValues.Length - 1)
    xAxis.Crossing = xValues(0) ' optional
    
    chart1Area.AxisX = xAxis
    chart1Area.AxisY = New Axis() ' everything auto on Y side.
    
    ' ...
    

By the way, my xValues is an array of numeric values. Since you put your Years as String, I don't know how it would work. Maybe by using some sort of numeric conversion trick.. :/

So far, I'm not used to Charting.Chart, so I hope someone else will help you better. Since I asked you to clarify some things in comments above, this is what I could share so far. If I remember another workaround (somehow forget about Charts long ago) I'll edit this post.

Good luck.

Upvotes: 2

Related Questions