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;
Related
I want to set default zoom only on Axis X but when I use this code my chart looks like:
My first value is way ahead.
This is the code:
var ca = chart1.ChartAreas["ChartArea1"];
ca.CursorX.IsUserEnabled = true;
ca.CursorX.IsUserSelectionEnabled = true;
ca.CursorX.AutoScroll = true;
chart1.Series["Temp"].XValueType = ChartValueType.DateTime;
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.IntervalOffset = 1;
chart1.ChartAreas[0].CursorX.Interval = 0;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Zoom(chart1.Series[0].Points.Count - 10, chart1.Series[0].Points.Count);
chart1.Series["Temp"].MarkerSize = 10;
chart1.Series["Temp"].IsValueShownAsLabel = true;
So I want to set default zoom on chart only on AxisX when I use mouse to zoom twice the chart looks good. Like that:
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 am currently developing a candlestick chart with mschart in visual C#.
I have now created two charts and created the charts as follows
Question 1. View the Candlestick Chart at the top. I would like to apply the tail color of each rod as red or blue.
Question 2. View the bar chart at the bottom. I would like to apply Red or Blue color to this chart. I want to apply the same color to the top of the Candlestick chart. How can I do it ?
[source]
DataTable table_ChartData = new DataTable();
table_ChartData.Columns.Add("Id");
table_ChartData.Columns.Add("Open");
table_ChartData.Columns.Add("Close");
table_ChartData.Columns.Add("High");
table_ChartData.Columns.Add("Low");
table_ChartData.Columns.Add("Day");
dataGridView1.DataSource = table_ChartData;
chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineWidth = 1;
chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineWidth = 1;
chart1.ChartAreas["ChartArea1"].AxisY.Maximum = max;
chart1.ChartAreas["ChartArea1"].AxisY.Minimum = min;
chart1.ChartAreas["ChartArea1"].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.WordWrap;
chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = true;
chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = true;
chart1.Series["Candle"].XValueMember = "Day";
chart1.Series["Candle"].YValueMembers = "High,Low,Open,Close,Volume";
chart1.Series["Candle"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Date;
chart1.Series["Candle"].CustomProperties = "PriceDownColor=Blue,PriceUpColor=Red";
chart1.Series["Candle"]["OpenCloseStyle"] = "Triangle";
chart1.Series["Candle"]["ShowOpenClose"] = "Both";
chart1.DataSource = table_ChartData;
chart1.DataBind();
////////////////////////////////////////////////////////////
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineWidth = 1;
chart2.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineWidth = 1;
chart2.ChartAreas["ChartArea1"].AxisY.Maximum = v_max + (v_max / 10);
chart2.ChartAreas["ChartArea1"].AxisY.Minimum = v_min / 2;
chart2.ChartAreas["ChartArea1"].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.WordWrap;
chart2.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = true;
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = true;
chart2.Series["Bar"].XValueMember = "Day";
chart2.Series["Bar"].YValueMembers = "Volume";
chart2.Series["Bar"].XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Date;
chart2.Series["Bar"].YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
chart2.DataSource = table_ChartData;
chart2.DataBind();
In a Candlestick Chart there are CustomProperties to automatiaclly set the colors of the boxes, depending on the trend:
someSeries.SetCustomProperty("PriceUpColor", "Green");
someSeries.SetCustomProperty("PriceDownColor", "Red");
Unfortunately there is no way to set the colors of the lines that connect the high- and low-values.
But, unless you have messed with other Custom attributes and if the x-values are meaningful, you can easily draw those lines, and by drawing the top and the bottom part separately you can also use different colors.
Here is an example:
private void chart6_PostPaint(object sender, ChartPaintEventArgs e)
{
ChartArea ca = chart6.ChartAreas[0];
Series s = chart6.Series[0];
Pen hiPen = Pens.Green;
Pen loPen = Pens.Red;
if (e.ChartElement == s)
foreach (DataPoint dp in s.Points)
{
float x = (float)ca.AxisX.ValueToPixelPosition(dp.XValue);
float y_hi = (float)ca.AxisY.ValueToPixelPosition(dp.YValues[0]);
float y_low = (float)ca.AxisY.ValueToPixelPosition(dp.YValues[1]);
float y_open = (float)ca.AxisY.ValueToPixelPosition(dp.YValues[2]);
float y_close = (float)ca.AxisY.ValueToPixelPosition(dp.YValues[3]);
e.ChartGraphics.Graphics.DrawLine(hiPen, x, y_low, x, Math.Min(y_close, y_open));
e.ChartGraphics.Graphics.DrawLine(loPen, x, y_hi, x, Math.Max(y_close, y_open));
}
}
To set Colors for the 2nd Chart's points you need to loop over the points as there Colors cannot be set in binding.
The code is simple:
void SetColors(Series candles, Series columns)
{
for (int i = 0; i < candles.Points.Count; i++)
{
DataPoint dp = candles.Points[i];
columns.Points[i].Color =
dp.YValues[2] > dp.YValues[3] ? Color.Red : Color.Green;
}
}
Call it after binding!
Result:
Note that to avoid seeing the original lines shine through we set the BorderWidth to 0:
someSeries.BorderWidth = 0;
Simple way:
priceSerie.Points[index].Color = Color.Blue;
// priceSerie.Points[index].BorderColor = Color.Magenta;
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.
I define 2 Series (I am using Telerik) that represent my Network Traffic rate (MBit/sec and Packet/sec):
AreaSeries series;
AreaSeries series2;
series = new AreaSeries();
radChartView1.Series.Add(series);
series.BorderColor = Color.SteelBlue;
series.BackColor = Color.FromArgb(20, Color.SkyBlue);
series.BorderWidth = 1;
series.HorizontalAxis.ShowLabels = false;
series.VerticalAxis.ShowLabels = false;
series2 = new AreaSeries();
radChartView1.Series.Add(series2);
series2.BorderColor = Color.Gray;
series2.BackColor = Color.FromArgb(20, Color.Gray);
series2.BorderWidth = 1;
series2.HorizontalAxis.ShowLabels = false;
series2.VerticalAxis.ShowLabels = false;
My chart received the real time data via Timer:
private void timerStatistics_Tick(object sender, EventArgs e)
{
try
{
if (series.DataPoints.Count > 40)
series.DataPoints.RemoveAt(0);
series.DataPoints.Add(new Telerik.Charting.CategoricalDataPoint(AdapterStatistics.BitsPerSecond * 0.000001));
if (series2.DataPoints.Count > 40)
series2.DataPoints.RemoveAt(0);
series2.DataPoints.Add(new Telerik.Charting.CategoricalDataPoint(AdapterStatistics.PacketsPerSecond));
}
catch (Exception)
{ }
}
And my problem is that because my 2 values are very different i only can see one of my Series (usually Packet/sec) because for example MBit/sec get the value 1.4 and Packet/sec get the value 200 so from my chart i can see the biggest value, the lowest value is so small that it cannot be seen (see my screenshot inside the red rectangle a very small blue line... ):
How to fix it?
Not sure how it applies to Telerik controls, but in the regular chart control, you can have 2 x-axes and 2 y-axes, and assign different series to use different axes. Thus, you could do something like:
series.YAxisType = AxisType.Primary;
series2.YAxisType = AxisType.Secondary;
Axis yaxis1 = chart.ChartAreas[0].AxisY;
Axis yaxis2 = chart.ChartAreas[0].AxisY2;
yaxis1.Maximum = 1e6;
yaxis2.Maximum = 1e3;
Looks like it's very similar using Telerik controls, taken straight from the Telerik website (http://www.telerik.com/help/winforms/chartview-axes-multiple-axes.html):
LinearAxis verticalAxis1 = new LinearAxis();
verticalAxis1.AxisType = AxisType.Second;
LinearAxis verticalAxis2 = new LinearAxis();
verticalAxis2.AxisType = AxisType.Second;
verticalAxis2.HorizontalLocation = AxisHorizontalLocation.Right;
series.HorizontalAxis = horizontalAxis;
series.VerticalAxis = verticalAxis1;
series2.HorizontalAxis = horizontalAxis;
series2.VerticalAxis = verticalAxis2;