Visual Studio 2019 winforms custom control designer problem - c#

I have a Visual Studio 2019 / Windows Forms problem.
I'm getting - "A chart element with the name 'ChartArea1' already exists in the 'ChartAreaCollection'."
So - what am I trying to do...
I have created a custom control derived from System.Windows.Forms.DataVisualization.Charting.Chart.
I call it XChart.
I want to have a custom chart with predefined properties/areas/axis/colors/legends/series
that will show up in the Toolbox when designing new forms.
Everything works except for one thing, and that is NOT just for this control,
it seems to be a general designer problem that probably has been around forever.
As fast as I change ANYTHING in my form all the control properties get written down
into MyForm.InitializeComponent(), which in turn makes all this below appear twice for the same chart - giving the error.
The properties values don't stay in the custom control, they get copied all of them to the form, even though I
haven't changed one of them.
It can't even be properly done with a TextBox.
Let's say I create a custom control called XTextBox inherited from TextBox.
The XTextBox.BackColor is default set to - let's say - Red.
I then use this XTextBox in a number of places in my app.
After a while I want to change my default BackColor to Yellow.
So I change the XTextBox.BackColor to Yellow in my custom control and nothing happens
because it still says Red in all my forms.
Any good ideas?
This is ruffly what my XChart.InitializeComponent() (and MyForm.InitializeComponent()) looks like:
System.Windows.Forms.DataVisualization.Charting.ChartArea area = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series serie0 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.Series serie1 = new System.Windows.Forms.DataVisualization.Charting.Series();
System.Windows.Forms.DataVisualization.Charting.Title title = new System.Windows.Forms.DataVisualization.Charting.Title();
//
// XChart
//
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28)))));
area.AxisX.LabelStyle.ForeColor = System.Drawing.Color.SeaShell;
area.AxisX.LabelStyle.Format = "0.000";
area.AxisX.LineColor = System.Drawing.Color.DarkGray;
area.AxisX.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
area.AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
area.AxisX.MajorTickMark.LineColor = System.Drawing.Color.DarkGray;
area.AxisX.MajorTickMark.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
area.AxisX.MinorTickMark.Enabled = true;
area.AxisX.ScrollBar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28)))));
area.AxisX.ScrollBar.ButtonColor = System.Drawing.Color.Gray;
area.AxisX.ScrollBar.ButtonStyle = System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonStyles.None;
area.AxisX.ScrollBar.IsPositionedInside = false;
area.AxisX.ScrollBar.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28)))));
area.AxisX.ScrollBar.Size = 16D;
area.AxisX2.ScrollBar.BackColor = System.Drawing.Color.White;
area.AxisX2.ScrollBar.ButtonColor = System.Drawing.Color.Silver;
area.AxisX2.ScrollBar.ButtonStyle = System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonStyles.None;
area.AxisY.LabelStyle.ForeColor = System.Drawing.Color.SeaShell;
area.AxisY.LabelStyle.Format = "0.000";
area.AxisY.LineColor = System.Drawing.Color.DarkGray;
area.AxisY.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
area.AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
area.AxisY.MajorTickMark.LineColor = System.Drawing.Color.DarkGray;
area.AxisY.MajorTickMark.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot;
area.AxisY.MinorTickMark.Enabled = true;
area.AxisY.ScrollBar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28)))));
area.AxisY.ScrollBar.ButtonColor = System.Drawing.Color.Gray;
area.AxisY.ScrollBar.ButtonStyle = System.Windows.Forms.DataVisualization.Charting.ScrollBarButtonStyles.None;
area.AxisY.ScrollBar.IsPositionedInside = false;
area.AxisY.ScrollBar.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28)))));
area.AxisY.ScrollBar.Size = 16D;
area.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(28)))), ((int)(((byte)(28)))));
area.Name = "ChartArea1";
area.Position.Auto = false;
area.Position.Height = 97F;
area.Position.Width = 90F;
area.Position.Y = 3F;
this.ChartAreas.Add(area);
legend.BackColor = System.Drawing.Color.Transparent;
legend.ForeColor = System.Drawing.Color.SeaShell;
legend.Name = "Legend1";
legend.TitleForeColor = System.Drawing.Color.Empty;
this.Legends.Add(legend);
this.Location = new System.Drawing.Point(25, 149);
this.Name = "chart1";
serie0.ChartArea = "ChartArea1";
serie0.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
serie0.Legend = "Legend1";
serie0.Name = "0";
serie1.ChartArea = "ChartArea1";
serie1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
serie1.Legend = "Legend1";
serie1.Name = "1";
this.Series.Add(serie0);
this.Series.Add(serie1);
this.Size = new System.Drawing.Size(300, 200);
this.TabIndex = 3;
this.Text = "chart1";
title.ForeColor = System.Drawing.Color.SeaShell;
title.Name = "Title1";
title.Position.Auto = false;
title.Position.Height = 2.59811F;
title.Position.Width = 94F;
title.Position.Y = 1F;
title.Text = "Titles[0]";
this.Titles.Add(title);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OnMouseUp);

This is a normal situation. You can solve it by rebuilding the project. After you rebuild it and drag a new one onto the Form, it will be "Yellow".

There's an article on MSDN that shows a ways to customize auto-generated code. Among other things it suggests using DesignerSerializationVisiblityAttribute, DefaultValueAttribute and ShouldSerialize<Property Name> method to suppress/force code generation.
Another way to customize the generated code is implementation of a custom CodeDomSerializer on the control. Check this article for details

Related

Devexpress Checkbutton Blueline border - how to remove

I am currently working on a devexpress project and I am using the checkbutton tool. I have it doing everything I want except for a very annoying sick looking blueline that shows up on appearance.hover and appearance.pressed.
If anything at all I would expect a color that goes with the theme but a constant blueline no matter what skin is selected is annoying and feels like an old html design.
I have tried setting the bordercolor and all but still.
Below is my code of what I have tried by far from form.Designer.cs;
this.cBtnFilter.AllowFocus = false;
this.cBtnFilter.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cBtnFilter.AppearanceDisabled.Options.UseBackColor = true;
this.cBtnFilter.AppearanceHovered.BorderColor = System.Drawing.Color.White;
this.cBtnFilter.AppearanceHovered.Options.UseBackColor = true;
this.cBtnFilter.AppearanceHovered.Options.UseBorderColor = true;
this.cBtnFilter.AppearancePressed.BorderColor = System.Drawing.Color.White;
this.cBtnFilter.AppearancePressed.Options.UseBackColor = true;
this.cBtnFilter.AppearancePressed.Options.UseBorderColor = true;
this.cBtnFilter.ImageOptions.AllowGlyphSkinning = DevExpress.Utils.DefaultBoolean.False;
this.cBtnFilter.ImageOptions.Location = DevExpress.XtraEditors.ImageLocation.MiddleCenter;
this.cBtnFilter.ImageOptions.SvgImage = global::form.Properties.Resources.icon_filter;
this.cBtnFilter.ImageOptions.SvgImageSize = new System.Drawing.Size(40, 40);
this.cBtnFilter.Location = new System.Drawing.Point(355, 40);
this.cBtnFilter.LookAndFeel.SkinName = "The Bezier";
this.cBtnFilter.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.UltraFlat;
this.cBtnFilter.LookAndFeel.UseDefaultLookAndFeel = false;
this.cBtnFilter.Name = "cBtnFilter";
this.cBtnFilter.PaintStyle = DevExpress.XtraEditors.Controls.PaintStyles.Light;
this.cBtnFilter.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
this.cBtnFilter.Size = new System.Drawing.Size(50, 50);
toolTipTitleItem4.Text = "Show active Only";
superToolTip4.Items.Add(toolTipTitleItem4);
this.cBtnFilter.SuperTip = superToolTip4;
this.cBtnFilter.TabIndex = 39;
this.cBtnFilter.Click += new System.EventHandler(this.Filter_Click);
The attached image is an example of when it is selected and when it is hovered respectively.
At the least if I could completely remove the blue line or change it to the theme color. It would be great.
Am using Devexpress Version 20.2.4
how I solved this is by using the simple button instead and making it act like a toggle button.
this method handles the toggle for me
public Boolean buttonState = false;
private void ToggleButton()
{
if (buttonState)
{
simpleButton.Appearance.BackColor = Color.Red;
buttonState = false;
}
else
{
simpleButton.Appearance.BackColor = Color.White;
buttonState = true;
}
}
this is the button
private void simpleButton_Click(object sender, EventArgs e)
{
ToggleButton();
}
here is the button in Designer.cs
this.simpleButton1.AllowFocus = false;
this.simpleButton1.AppearanceHovered.BackColor = System.Drawing.Color.Teal;
this.simpleButton1.AppearanceHovered.Options.UseBackColor = true;
this.simpleButton1.Location = new System.Drawing.Point(524, 214);
this.simpleButton1.LookAndFeel.SkinName = "The Bezier";
this.simpleButton1.LookAndFeel.UseDefaultLookAndFeel = false;
this.simpleButton1.Name = "simpleButton1";
this.simpleButton1.ShowFocusRectangle = DevExpress.Utils.DefaultBoolean.False;
this.simpleButton1.Size = new System.Drawing.Size(157, 150);
this.simpleButton1.TabIndex = 2;
this.simpleButton1.Text = "simpleButton";
this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click);
Its quite straightforward. In case anyone has a better way or has need for this, knock yourself(ves) out.
Hopefully in the future, Devexpress will not force blue borders on us.

LiveCharts: Show chart title in windows form [duplicate]

I'm using LiveCharts in WinForms. Reason why I'm not using WPF is because I don't want to rewrite the GUI in WPF, so I'm trying to see if I can make LiveCharts work in WinForms.
I'm saving the LiveCharts control as an image to a PDF, so the title needs to be on the chart itself.
I cannot find any functionality for adding a title on the chart. What I have tried is the following:
VisualElement title = new VisualElement();
title.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
title.VerticalAlignment = System.Windows.VerticalAlignment.Top;
title.X = 0.5;
title.Y = maxYVal;
TextBlock titleText = new TextBlock();
titleText.Text = chartName;
var newTitleFont = HelperFunctions.NewTypeFaceFromFont(titleFont);
titleText.FontFamily = newTitleFont.FontFamily;
titleText.FontStyle = newTitleFont.Style;
titleText.FontSize = titleFont.Size;
title.UIElement = titleText;
cartChart.VisualElements.Add(title);
The above code only adds a label on the chart itself (within the y axis range). The title needs to be independent (above the y axis). Any idea?
This seems to do the trick:
public static TableLayoutPanel AddTitleToChart(Control chart,string title, System.Drawing.Font titleFont)
{
Label label = new Label();
label.AutoSize = true;
label.Dock = System.Windows.Forms.DockStyle.Fill;
label.Font = titleFont;
label.Location = new System.Drawing.Point(3, 0);
label.Name = "label1";
label.Size = new System.Drawing.Size(1063, 55);
label.TabIndex = 0;
label.Text = title;
label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
label.BackColor = chart.BackColor;
chart.Dock = System.Windows.Forms.DockStyle.Fill;
TableLayoutPanel tableLayoutPanel = new TableLayoutPanel();
tableLayoutPanel.AutoSize = true;
tableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
tableLayoutPanel.BackColor = System.Drawing.Color.White;
tableLayoutPanel.ColumnCount = 1;
tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 1069F));
tableLayoutPanel.Controls.Add(label, 0, 0);
tableLayoutPanel.Controls.Add(chart, 0, 1);
tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
tableLayoutPanel.Location = new System.Drawing.Point(0, 0);
tableLayoutPanel.Name = "tableLayoutPanel1";
tableLayoutPanel.RowCount = 2;
tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle());
tableLayoutPanel.Size = new System.Drawing.Size(1069, 662);
tableLayoutPanel.TabIndex = 2;
return (tableLayoutPanel);
}

C# Windows Forms Chart is weird

I made a C# windows forms and my chart is very strange. My chart has a lot of white borders and the text for Master and Slave is very tiny and pixelated.
Why the Axis is so far away from the borders? How can I fix this?
// chart1
//
chartArea2.AxisX.MajorGrid.Enabled = false;
chartArea2.AxisX.MajorTickMark.Enabled = false;
chartArea2.AxisY.MajorGrid.Enabled = false;
chartArea2.AxisY.MajorTickMark.Enabled = false;
chartArea2.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea2);
legend2.Name = "Legend1";
this.chart1.Legends.Add(legend2);
this.chart1.Location = new System.Drawing.Point(543, 49);
this.chart1.Name = "chart1";
series3.ChartArea = "ChartArea1";
series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
series3.Legend = "Legend1";
series3.MarkerBorderColor = System.Drawing.Color.Black;
series3.MarkerImage = "C:\\Users\\Tiago\\Desktop\\CODIGO_TESE_FINAL_BACKUP1408_BOM\\C# - AR.Drone SDK\\AR.Dron" +
"e\\icone_drone_2_50x50.png";
series3.MarkerImageTransparentColor = System.Drawing.Color.Red;
series3.Name = "Master";
series4.ChartArea = "ChartArea1";
series4.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
series4.Legend = "Legend1";
series4.MarkerImage = "C:\\Users\\Tiago\\Desktop\\CODIGO_TESE_FINAL_BACKUP1408_BOM\\C# - AR.Drone SDK\\AR.Dron" +
"e\\icone_drone_2_50x50.png";
series4.Name = "Slave";
this.chart1.Series.Add(series3);
this.chart1.Series.Add(series4);
this.chart1.Size = new System.Drawing.Size(1159, 359);
this.chart1.TabIndex = 7;
this.chart1.Text = "chart1";
this.chart1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseDown);
this.chart1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseMove);
this.chart1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chart1_MouseUp);
You can set the border spaces and the Fonts all in the designer.
Pick the ChartArea and modify the Position. Note that it is not in pixels but in percentages of the Chart.ClientSize!! So for your largish chart the 3% defualt is a little too much..
The Legend's Font is changed here:

how to enable auto scaling property in chart control using c#

In my application im having a chart control that is working fine. For every 1 second updating the x-Axis values and y-axis values in the chart. I want to enable auto scaling for the chart control programmatically for y axis. Please refer my code below,
chart1.Series.Clear();
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
series1.Name = "Series1";
series1.MarkerStyle = MarkerStyle.Circle;
series1.MarkerColor = Color.BlueViolet;
series1.MarkerSize = 10;
series1.Color = System.Drawing.Color.Green;
series1.IsXValueIndexed = true;
series1.YAxisType = AxisType.Primary;
series1.ChartType = SeriesChartType.Line;
this.chart1.Series.Add(series1);
How to enable auto scaling programmatically.
chart1.Series.Clear();
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].RecalculateAxesScale();
series1.Name = "Series1";
series1.MarkerStyle = MarkerStyle.Circle;
series1.MarkerColor = Color.BlueViolet;
series1.MarkerSize = 10;
series1.Color = System.Drawing.Color.Green;
//series1.IsVisibleInLegend = false;
series1.IsXValueIndexed = true;
//series1.XValueType = ChartValueType.Time;
series1.YAxisType = AxisType.Primary;
series1.ChartType = SeriesChartType.Line;
this.chart1.Series.Add(series1);
Working fine
chart.ChartAreas[0].AxisY.Maximum = Double.NaN;
But some people have trouble with the above one,
so try this if that doesn't work
chart.ChartAreas[0].RecalculateAxesScale();

How to make line chart start from 0 X-Axis

I create a line chart, but I want to display the chart begin from 0 in X-axis.
How can I do this.
I try some method but still did not get what I want.
Chart1.ChartAreas[0].AxisX.Interval = 0;
Chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
Chart1.ChartAreas[0].AxisX.Minimum = 0;
Chart1.ChartAreas[0].AxisX.Crossing = 0;
This is what I do now
This is what I want
And one more, how can I set major and minor unit in the chart..?
my code here
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Font axisFont = new System.Drawing.Font("Arial", 8, System.Drawing.FontStyle.Bold);
System.Drawing.Font titleFont = new System.Drawing.Font("Arial", 10, System.Drawing.FontStyle.Bold);
Chart1.Width = 600;
Chart1.Height = 400;
Chart1.BorderlineColor = System.Drawing.Color.Black;
Chart1.BorderlineWidth = 1;
Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
double[] min = { 60.9, 0, 28.81, 7.27 };
double[] ave = { 60.9, 0, 28.81, 7.27 };
double[] max = { 5167.72, 1.27, 4176.16, 2566.59 };
Chart1.Series["Series1"].ChartArea = "ChartArea1";
Chart1.Series["Series2"].ChartArea = "ChartArea1";
Chart1.Series["Series3"].ChartArea = "ChartArea1";
Chart1.Series["Series1"].Points.AddXY("Step 1-2", max[0]);
Chart1.Series["Series2"].Points.AddXY("Step 1-2", ave[0]);
Chart1.Series["Series3"].Points.AddXY("Step 1-2", min[0]);
Chart1.Series["Series1"].Points.AddXY("Step 2-3", max[1]);
Chart1.Series["Series2"].Points.AddXY("Step 2-3", ave[1]);
Chart1.Series["Series3"].Points.AddXY("Step 2-3", min[1]);
Chart1.Series["Series1"].Points.AddXY("Step 3-4", max[2]);
Chart1.Series["Series2"].Points.AddXY("Step 3-4", ave[2]);
Chart1.Series["Series3"].Points.AddXY("Step 3-4", min[2]);
Chart1.Series["Series1"].Points.AddXY("Step 4-5", max[3]);
Chart1.Series["Series2"].Points.AddXY("Step 4-5", ave[3]);
Chart1.Series["Series3"].Points.AddXY("Step 4-5", min[3]);
String hour1 = "hh";
Chart1.Titles.Add("Cycle Time : "+hour1);
Chart1.Titles[0].Font = titleFont;
Chart1.Series["Series1"].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Triangle;
Chart1.Series["Series2"].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Square;
Chart1.Series["Series3"].MarkerStyle = System.Web.UI.DataVisualization.Charting.MarkerStyle.Diamond;
Chart1.Series["Series1"].MarkerSize = 15;
Chart1.Series["Series2"].MarkerSize = 15;
Chart1.Series["Series3"].MarkerSize = 15;
Chart1.Legends.Add("Legend1");
Chart1.Series["Series1"].LegendText = "Max";
Chart1.Series["Series2"].LegendText = "Ave";
Chart1.Series["Series3"].LegendText = "Min";
Chart1.Series["Series1"].Legend = "Legend1";
Chart1.Series["Series2"].Legend = "Legend1";
Chart1.Series["Series3"].Legend = "Legend1";
Chart1.Series["Series1"].IsVisibleInLegend = true;
Chart1.Series["Series2"].IsVisibleInLegend = true;
Chart1.Series["Series3"].IsVisibleInLegend = true;
//This part I try to make the graph start from 0 in X-axis but not work
//Chart1.ChartAreas[0].AxisX.Interval = 0;
//Chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
//Chart1.ChartAreas[0].AxisX.Minimum = 0;
//Chart1.ChartAreas[0].AxisX.Crossing = 0;
//Chart1.ChartAreas[0].AxisX.Minimum = 0;
//Chart1.ChartAreas[0].Position.Auto = false;
Chart1.ChartAreas[0].AxisX.TitleFont = axisFont;
Chart1.ChartAreas[0].AxisY.TitleFont = axisFont;
Chart1.ChartAreas[0].AxisX.Title = "Step";
Chart1.ChartAreas[0].AxisY.Title = "Time (" + hour1 + ")";
Chart1.ChartAreas[0].BackColor = System.Drawing.Color.AliceBlue;
Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = System.Drawing.ColorTranslator.FromHtml("#D5E8F5");
}
I had a similar issue, and found that the solution was to set the IsMarginVisible flag to false:
chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
Hope this helps.
The Chart control decides by his own where to start the Axes, and more importantly where to end them, because it could create problems in displaying the points.
Say that you have a point in (-1,0), if you decided to start the X-Axis from 0 what should the chart control do? Display the series starting from unknown? Erase the point?
In your chart every point has 2 values, a string value for the X-Axis and a double for the Y-Axis.
The strings are stored in the chart in alphabetical order, and it also checks whether some are equals or not (so you don't have 3 *Step 1-3*s).
It also give the strings a position value, starting obviously from 0.
But what is the 0 position value string?
Answer: there is no 0 position value string possible.
In fact, if you try something like
Chart1.Series["Series1"].Points.AddXY(string.Empty, 1.0);
Chart1.Series["Series2"].Points.AddXY(string.Empty, 2.0);
Chart1.Series["Series3"].Points.AddXY(string.Empty, 3.0);
The chart control will automatically add a label for the empty string called 1, showing the position value.
The only way for setting major and minor unit in the chart is by adding or removing data from the chart.
Another workaround could be this:
Chart1.Series["SeriesMin"].Points.AddXY(0, max[0]);
Chart1.Series["SeriesAve"].Points.AddXY(0, ave[0]);
Chart1.Series["SeriesMax"].Points.AddXY(0, min[0]);
Chart1.Series["SeriesMin"].Points[0].AxisLabel = "Step 1-2";
Chart1.Series["SeriesAve"].Points[0].AxisLabel = "Step 1-2";
Chart1.Series["SeriesMax"].Points[0].AxisLabel = "Step 1-2";
Then you could add all your so far not working code
Chart1.ChartAreas[0].AxisX.Interval = 0;
Chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
Chart1.ChartAreas[0].AxisX.Minimum = 0;
Chart1.ChartAreas[0].AxisX.Crossing = 0;
Chart1.ChartAreas[0].AxisX.Minimum = 0;
//Chart1.ChartAreas[0].Position.Auto = false; //EXCEPT THIS ONE!!
Worked like a charm, exceedingly boring if you had to add more data not from a db.

Categories