I have a project with multiple AxisY, with 3 series and and each series has its axisY associated. When I zoom, I have achieved that all the series have zoom but the scale of the axisYof the secondary axisY doesn't change, only that of the main series changes.
Original Chart:
Chart with zoom applied:
I have create the new axisY secondary with the code of microsoft (Project "Windows Forms Samples Environment for Microsoft Chart Control"):
public void CreateYAxis(Chart chart, ChartArea area, Series series, float axisOffset, float labelsSize)
{
// Create new chart area for original series
ChartArea areaSeries = chart.ChartAreas.Add("ChartArea_" + series.Name);
areaSeries.BackColor = Color.Transparent;
areaSeries.BorderColor = Color.Transparent;
areaSeries.Position.FromRectangleF(area.Position.ToRectangleF());
areaSeries.InnerPlotPosition.FromRectangleF(area.InnerPlotPosition.ToRectangleF());
areaSeries.AxisX.MajorGrid.Enabled = false;
areaSeries.AxisX.MajorTickMark.Enabled = false;
areaSeries.AxisX.LabelStyle.Enabled = false;
areaSeries.AxisY.MajorGrid.Enabled = false;
areaSeries.AxisY.MajorTickMark.Enabled = false;
areaSeries.AxisY.LabelStyle.Enabled = false;
areaSeries.AxisY.IsStartedFromZero = area.AxisY.IsStartedFromZero;
series.ChartArea = areaSeries.Name;
// Create new chart area for axis
ChartArea areaAxis = chart.ChartAreas.Add("AxisY_" + series.ChartArea);
areaAxis.BackColor = Color.Transparent;
areaAxis.BorderColor = Color.Transparent;
areaAxis.Position.FromRectangleF(chart.ChartAreas[series.ChartArea].Position.ToRectangleF());
areaAxis.InnerPlotPosition.FromRectangleF(chart.ChartAreas[series.ChartArea].InnerPlotPosition.ToRectangleF());
// Create a copy of specified series
Series seriesCopy = chart.Series.Add(series.Name + "_Copy");
seriesCopy.ChartType = series.ChartType;
foreach(DataPoint point in series.Points)
{
seriesCopy.Points.AddXY(point.XValue, point.YValues[0]);
}
// Hide copied series
seriesCopy.IsVisibleInLegend = false;
seriesCopy.Color = Color.Transparent;
seriesCopy.BorderColor = Color.Transparent;
seriesCopy.ChartArea = areaAxis.Name;
// Disable drid lines & tickmarks
areaAxis.AxisX.LineWidth = 0;
areaAxis.AxisX.MajorGrid.Enabled = false;
areaAxis.AxisX.MajorTickMark.Enabled = false;
areaAxis.AxisX.LabelStyle.Enabled = false;
areaAxis.AxisY.MajorGrid.Enabled = false;
areaAxis.AxisY.IsStartedFromZero = area.AxisY.IsStartedFromZero;
areaAxis.AxisY.LabelStyle.Font = area.AxisY.LabelStyle.Font;
// Adjust area position
areaAxis.Position.X -= axisOffset;
areaAxis.InnerPlotPosition.X += labelsSize;
}
UPDATE--------------------------------:
I have this news:
Now, the 3 axis update his scale but it comes out together, How to separate them?
The code is here:
chart1.ChartAreas[2].AlignmentOrientation = AreaAlignmentOrientations.All;
chart1.ChartAreas[2].AlignmentStyle = AreaAlignmentStyles.All;
chart1.ChartAreas[2].AlignWithChartArea = "ChartArea1";
chart1.ChartAreas[4].AlignmentOrientation = AreaAlignmentOrientations.All;
chart1.ChartAreas[4].AlignmentStyle = AreaAlignmentStyles.All;
chart1.ChartAreas[4].AlignWithChartArea = "ChartArea1";
I make a c#
Bnnn
chart program.
And, I use the MSChart.
I setup the Scrollbar information on ChartArea Collection.
When execute my program, the scrollbar is not visible... what's wrong with my ChartArea Collection.
And, I try to coding for setting scrollbar like this.
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
chart1.ChartAreas[0].AxisX.ScrollBar.Size = 10;
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
chart1.ChartAreas[0].AxisX.ScrollBar.Size = 10;
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
chart1.ChartAreas[0].AxisX.ScrollBar.BackColor = Color.LightGray;
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonColor = Color.Gray;
chart1.ChartAreas[0].AxisX.ScrollBar.LineColor = Color.Black;
chart1.ChartAreas[0].AxisX.Minimum = 0;
chart1.ChartAreas[0].AxisX.Maximum = 10;
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 100;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.Series["Series1"].Points.AddXY(0, 0);
chart1.Series["Series2"].Points.AddXY(0, 0);
chart1.Series["Series3"].Points.AddXY(0, 0);
Is it any wrong?.
You are setting some properties on the AxisX scroll bar twice (such as Size and Enabled), but you are not setting them for the AxisY.
I suspect that you did a cut and past and forgot to change some X to Y ....
Hello I am having a hard time understanding how to get my column chart to be centered over the X-Axis label. IN the chart pic below you will see that I have columns based on 1/2 increments. For my positive series the data starts on the left and ends at the x-axis label. On my negative series the data starts at the x-axis label and continues to the right. How do I get these columns centered over the x-axis label. I don't understand why one series is displayed one way and the other series is displayed a different way.
Screen shot here:
http://i.imgur.com/QuAXUxr.png
Code is below
chartAreaDistributionHalfHour.Name = "ChartAreaDistributionHalfHour";
chartAreaDistributionHalfHour.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartAreaDistributionHalfHour.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartAreaDistributionHalfHour.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartAreaDistributionHalfHour.AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartAreaDistributionHalfHour.AxisX.LabelAutoFitMaxFontSize = 7;
chartAreaDistributionHalfHour.AxisY.LabelAutoFitMaxFontSize = 7;
chartAreaDistributionHalfHour.AxisX.Title = "Distribution (Half-Hourly)";
chartAreaDistributionHalfHour.AxisY.Title = "Profit/Loss ($)";
chartAreaDistributionHalfHour.AxisY.IsMarginVisible = false;
seriesDistributionHalfHour.ChartArea = "ChartAreaDistributionHalfHour";
seriesDistributionHalfHour.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
seriesDistributionHalfHour.Color = System.Drawing.Color.Green;
seriesDistributionHalfHour.Enabled = true;
seriesDistributionHalfHour.Name = "distributionHalfHour";
seriesDistributionHalfHourNegative.ChartArea = "ChartAreaDistributionHalfHour";
seriesDistributionHalfHourNegative.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
seriesDistributionHalfHourNegative.Color = System.Drawing.Color.Red;
seriesDistributionHalfHourNegative.Enabled = true;
seriesDistributionHalfHourNegative.Name = "netLossDistributionHalfHour";
seriesDistributionHalfHourZeroLine.ChartArea = "ChartAreaDistributionHalfHour";
seriesDistributionHalfHourZeroLine.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
seriesDistributionHalfHourZeroLine.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
seriesDistributionHalfHourZeroLine.Color = System.Drawing.Color.Black;
seriesDistributionHalfHourZeroLine.Enabled = true;
seriesDistributionHalfHourZeroLine.Name = "netDistributionHalfHourZeroLine";
this.chartDistributionHalfHourGraph.Location = new System.Drawing.Point(17, 49);
this.chartDistributionHalfHourGraph.Name = "chartDistributionHalfHourGraph";
this.chartDistributionHalfHourGraph.BorderlineColor = System.Drawing.Color.Black;
this.chartDistributionHalfHourGraph.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
this.chartDistributionHalfHourGraph.Cursor = System.Windows.Forms.Cursors.Cross;
this.chartDistributionHalfHourGraph.Visible = false;
this.chartDistributionHalfHourGraph.Size = new System.Drawing.Size(1443, 694);
this.chartDistributionHalfHourGraph.TabIndex = 7;
this.chartDistributionHalfHourGraph.Text = "chart2";
this.chartDistributionHalfHourGraph.ChartAreas.Add(chartAreaDistributionHalfHour);
this.chartDistributionHalfHourGraph.Series.Add(seriesDistributionHalfHour);
this.chartDistributionHalfHourGraph.Series.Add(seriesDistributionHalfHourNegative);
this.chartDistributionHalfHourGraph.Series.Add(seriesDistributionHalfHourZeroLine);
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.
Hello guys i have a MSChart and i have some arrows on chart exactly where the series are overlapping i would like to know at least what are they and maybe how can i get them out.
The chart is generated with two methods:
private void DesignChart()
{
// Create Chart Area
ChartArea chartArea1 = new ChartArea();
// Add Chart Area to the Chart
chart1.ChartAreas.Add(chartArea1);
chart1.Legends.Add(new Legend());
// chart1.ChartAreas[0].AxisX.LabelStyle.Format={"00:00:00"};
chart1.Location = new Point(14, 494);
chart1.Size = new Size(982, 224);
this.Controls.Add(chart1);
((System.ComponentModel.ISupportInitialize)(chart1)).EndInit();
}
private void SetGraph(){
.........
for (int i = 0; i < chart1.Series.Count; i++)
{
chart1.Series[i].XValueMember = "Date";
chart1.Series[i].YValueMembers = "Value";
chart1.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Series[i].XValueType = ChartValueType.Time;
chart1.Series[i].ChartType = SeriesChartType.Line;
chart1.Series[i].MarkerStyle = MarkerStyle.Star10;
chart1.Series[i].MarkerSize = 8;
chart1.Series[i].MarkerColor = chart1.Series[0].BorderColor;
chart1.Series[i].BorderWidth = 3;
chart1.Series[i].IsValueShownAsLabel = true;
chart1.Series[i].ToolTip = "#VALY => #AXISLABEL";
}
chart1.ChartAreas[0].AxisX.IsMarginVisible = true;
}
Picture link Photo of the chart
Thanks
I believe it happens because of this line:
chart1.Series[i].IsValueShownAsLabel = true;
If the data points are close together/overlap, chart control uses the arrow to point to the reference point so you don't get confused -- or something like that. Try setting this line to false and see if the arrows disappear. Not sure there is any other way to override the arrow display.
Is it possible the 'arrows' are actually the result of this line?
chart1.Series[i].MarkerStyle = MarkerStyle.Star10;