How to disable Chart axis autosize - c#

I need to stop autosizing (or autoscaling) of Y Axis in c# chart and set it manually.
Any advice? Thanks

You can set the minimum and maximum of the Y axis like so:
chart.ChartAreas[0].AxisY.Minimum = 0;
chart.ChartAreas[0].AxisY.Maximum = 10;

Related

Use a DateTime axis for an Oxyplot HeatMap

I want to use a datetimeaxis for the Y-axis of an Oxyplot heatmapseries (in winforms). The API allows me to add the axis to the PlotModel, but does not do much good since the y-value is mapped off of the integral column index of a matrix of doubles - the y values come out to around Jan. 1900.
How can I use times for the y data on the heat map?
The workaround to make this happen is not too difficult. When setting up the chart, create 2 axes: one for the time, and another for the integral index of the HeatMapSeries input.
DateTimeAxis dateTimeAxis;
HeatMapSeries series;
....
//set up the time axis for y
dateTimeAxis = new DateTimeAxis();
dateTimeAxis.Position = AxisPosition.Left;
dateTimeAxis.Key = "dateTimeAxis";
plotModel.Axes.Add(dateTimeAxis);
//set up a shadow axis for the HeatMapSeries
var linearAxis = new LinearAxis();
linearAxis.Position = AxisPosition.Left;
linearAxis.Key = "linearAxis";
plotModel.Axes.Add(linearAxis);
series.YAxisKey = linearAxis.Key;
Next, the assigned y-axis will have to be hidden - but we can't access the YAxis property until the plot has been updated:
//hide the linear axis
plotModel.Updated += (sender, e) =>
{
series.YAxis.IsAxisVisible = false;
};
Finally, when setting the heat map data, simply create the desired mapping from the matrix index to time. Then adjust the y-scale. For example:
public void UpdateData(double[,] data)
{
series.Data = data;
//adjust date/time axis
int numOfMinutes = data.GetLength(1);
dateTimeAxis.Minimum = DateTimeAxis.ToDouble(DateTime.Now);
dateTimeAxis.Maximum DateTimeAxis.ToDouble(DateTime.Now.AddMinutes(numOfMinutes));
}
I have not yet seen a way to do this directly in OxyPlot

C# Windows form Chart fixed axis?

I am very new in all this of programming and I am beginning with C#
now I have an application which should show some points in a chart, but i would like to fix the x and y axis in a way that the graph area always has as minimum 50 and maximum 50, but the graphic area doesn't auto-fit the graph, I don't know if I explain it well, I mean I want the points for x and y axis always display from 0 to 50. does some one know how to set this?
you can easily set limits like this:
chart1.ChartAreas[0].AxisX.Maximum = 50;
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 50;
chart1.ChartAreas[0].AxisY.Minimum = 0;

c# chart change max and min values on the x axis

Can someone tell me how to change the min and max values on the x axis on a C# chart? I want to go from 0 to 13, but it goes from -1 to 14 right now.
If you are using System.Windows.Forms.DataVizualisation.Charting you can set the Axis range by manipulating the chart's ChartAreas property. So something like
myChart.ChartAreas[0].AxisX.Maximum = 13;
myChart.ChartAreas[0].AxisX.Minimum = 0;
This will work better :
myChart.ChartAreas[0].AxisX.IsMarginVisible = false;
You might try myChart.ChartAreas[0].AxisX.RoundAxisValues(). It is on by default for the Y axis and I find it generally works better for the X Axis as well.
New Chart().SetYAxis("GPA",0,4);
If You using The chart Class
you could set the Y or X axis using the SetYAxis Method
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = 10;
chart1.ChartAreas[0].AxisY.Minimum = -5;
chart1.ChartAreas[0].AxisY.Maximum = 5;

How to displace the origin of the Y axis on a polar Mschart?

Im working on a polar chart with mschart, and I need to make this "hole" on the middle of the chart. I mean, i need the "0" of the Y axis not to be on the center. I saw this plot somewhere on stackoverflow. It´s exactly what i need, how can I do that?
In order to create a radar plot that look like the provided example
// disable grid a long X
chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false;
// set Y axis
chart1.ChartAreas[0].AxisY.Minimum = -20; // creates the 'hole' by setting min Y
chart1.ChartAreas[0].AxisY.MajorGrid.IntervalOffset = 20; // so the major grid does not fill the 'hole'
chart1.ChartAreas[0].AxisY.MajorGrid.Interval = 5;
chart1.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash;

Formatting main chart's axis in C#

I'm trying to make chart in C# which should be readable easily. I managed to draw sin() graph, but it's not really readable, as X and Y axis don't stand out, I feel like it's the middle of nowhere. I tried to set line width using following code:
area.AxisX.LineWidth = 3;
But it only made line in the bottom of chart fatter, not main axis (Y = 0) like I need.
Anyone know how I would accomplish that? Is Y axis (X = 0) same? If no, could you please specify how to bold it too?
I think what you are looking for is the MajorGridLines:
area.AxisY.MajorGrid.LineWidth = 3
Or maybe this:
area.AxisX.LineWidth = 3;
area.AxisX.Crossing = 0;
area.AxisY.LineWidth = 3;
area.AxisY.Crossing = 0;
Crossing will put the axis at the value you set it to.

Categories