I have a chart that I am using in my C# .NET Windows Forms Application. It looks like this:
If you notice along the X-axis, at points (0,0) and (9, 0) that there is no data being fed into my chart's dataset. This is not a coincidence: I only feed data to this chart that will have "Production Hour" from 1-8.
How can I get rid of the 0 and 9 along the x-axis? I don't want a "blank column" of data added to each "side" (beginning/end) of my chart. It seems it is the default behavior of a Chart
in .NET Windows Forms Applications to add an extra point along the x-axis on both ends of the dataset (start/end). Perhaps there is an easy way to toggle that feature off?
In other words, I would like the "start point" of my chart to be 1 (on the x axis) and I would like the "end point" of chart to be 8 (also on the x axis).
This is a normal chart you would drag/drop onto the UI if you are using Windows Forms Application.
CodePudding user response:
I was able to answer my question using the answer from user digEmAll for this post: Remove blanks at ends of DataVisualization chart x axis
This is the code itself that fixed my problem:
this.chart1.ChartAreas[0].AxisX.Minimum = 1; // if your minimum X = 1
this.chart1.ChartAreas[0].AxisX.Maximum = 8; // if your maximum X = 8
I'm unsure if there is a way to set this in properties of a chart (I'd rather set this there). But for now, I placed this code on a button click event (the button queries data and loads it into my chart). Thus, whenever data is present in my chart, the min and max will be set to the correct values.