how to increase speed of tchart refresh()? - c#

I have 16 graphs[maximum ] with 4 fastlines in each graph. In each graph 3 fastlines represent min , max and ideal value. 4th fastline is actual values from the hardware. I have to run the test for 18,000 samples. So , first 3 fastlines are already drawn and when the switch is on and data comes in , 4th fastline is drawn. In order to draw the 4th line, I use the method Series4.Add(actualvalue, "" , color.red) .
here is the problem. each time the sample is drawn on 4th line. chart has to be refreshed in order to view the plotting of that sample. that also redraws the other 3 fastlines with 18,000 samples in each . so it redraws that many samples without use again and again. I need to draw only 4th fastline.
I can not use an array to fill the values up and then assign it as a source of fastline because I dont have any values beforehand. I tried series4.repaint() method and series4.refreshseries() method, but that doesnt repaint 4th series actually. we have to refresh the whole chart.
and therefore, it slows down the performance because of high number of samples in each fastline [18,000] and one graph with 4 fastlines and total 16 graphs like this.
I ve already done
Series4.AutoRepaint = false, Series4.DrawAllPoints = false;
Series4.XValues.Order = ValueListOrder.None , Series4.YValues.Order = ValueListOrder.None
Is there any way I can increase the performance ?
Thank you.

I have made a simple code, where I have added 4 charts with 4 FastLines with 18000 points for each fastline using a table to add a initialize values and after I update only the values of Series4. The performance is good for the number of values I am drawing:
public Form1()
{
InitializeComponent();
InitializeChart();
}
// Steema.TeeChart.Styles.FastLine Series1;
Timer timer1, timer2,timer3, timer4;
Random r;
DateTime dt;
DateTime[] Xvalues1;
double[] Yvalues1;
Steema.TeeChart.TChart tChart1, tChart2, tChart3,tChart4;
private void InitializeChart()
{
tChart1 = new TChart();
tChart2 = new TChart();
tChart3 = new TChart();
tChart4 = new TChart();
this.Controls.Add(tChart1);
this.Controls.Add(tChart2);
this.Controls.Add(tChart3);
this.Controls.Add(tChart4);
//Initialize Locations and size
this.Width = 908;
this.Height = 600;
//Location
tChart1.Left = 12;
tChart1.Top = 53;
tChart2.Left = 468;
tChart2.Top = 53;
tChart3.Left = 12;
tChart3.Top = 318;
tChart4.Left = 468;
tChart4.Top = 318;
//Size
tChart1.Width = 373;
tChart1.Height = 236;
tChart2.Width = 373;
tChart2.Height = 236;
tChart3.Width = 373;
tChart3.Height = 236;
tChart4.Width = 373;
tChart4.Height = 236;
tChart1.Aspect.View3D = false;
tChart2.Aspect.View3D = false;
tChart3.Aspect.View3D = false;
tChart4.Aspect.View3D = false;
tChart1.Legend.Visible = false;
tChart2.Legend.Visible = false;
tChart3.Legend.Visible = false;
tChart4.Legend.Visible = false;
tChart1.Panel.Gradient.Visible = false;
tChart2.Panel.Gradient.Visible = false;
tChart3.Panel.Gradient.Visible = false;
tChart4.Panel.Gradient.Visible = false;
tChart1.Axes.Bottom.AxisPen.Visible = false;
tChart2.Axes.Bottom.AxisPen.Visible = false;
tChart3.Axes.Bottom.AxisPen.Visible = false;
tChart4.Axes.Bottom.AxisPen.Visible = false;
tChart1.Axes.Left.AxisPen.Visible = false;
tChart2.Axes.Left.AxisPen.Visible = false;
tChart3.Axes.Left.AxisPen.Visible = false;
tChart4.Axes.Left.AxisPen.Visible = false;
//Series
tChart1.AutoRepaint = false;
tChart2.AutoRepaint = false;
tChart3.AutoRepaint = false;
tChart4.AutoRepaint = false;
for (int i = 0; i < 4; i++)
{
new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
new Steema.TeeChart.Styles.FastLine(tChart2.Chart);
new Steema.TeeChart.Styles.FastLine(tChart3.Chart);
new Steema.TeeChart.Styles.FastLine(tChart4.Chart);
tChart1[i].XValues.DateTime=true;
tChart2[i].XValues.DateTime = true;
tChart3[i].XValues.DateTime = true;
tChart4[i].XValues.DateTime = true;
InitialDataSeries(tChart1[i]);
InitialDataSeries(tChart2[i]);
InitialDataSeries(tChart3[i]);
InitialDataSeries(tChart4[i]);
}
//Axes labels
tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MM";
tChart1.Axes.Bottom.Labels.Angle = 90;
tChart2.Axes.Bottom.Labels.DateTimeFormat = "dd/MM";
tChart2.Axes.Bottom.Labels.Angle = 90;
tChart3.Axes.Bottom.Labels.DateTimeFormat = "dd/MM";
tChart3.Axes.Bottom.Labels.Angle = 90;
tChart4.Axes.Bottom.Labels.DateTimeFormat = "dd/MM";
tChart4.Axes.Bottom.Labels.Angle = 90;
tChart1.AutoRepaint = true;
tChart2.AutoRepaint = true;
tChart3.AutoRepaint = true;
tChart4.AutoRepaint = true;
tChart1.Refresh();
tChart2.Refresh();
tChart3.Refresh();
tChart4.Refresh();
//Timer
timer1 = new Timer();
timer1.Start();
timer1.Interval = 100;
timer1.Tick += new EventHandler(timer1_Tick);
}
void timer1_Tick(object sender, EventArgs e)
{
//See the chart data updated.
tChart1[0].Visible = false;
tChart1[1].Visible = false;
tChart1[2].Visible = false;
PopulateSeries(tChart1[3]);
PopulateSeries(tChart2[3]);
PopulateSeries(tChart3[3]);
PopulateSeries(tChart4[3]);
}
private void PopulateSeries(Steema.TeeChart.Styles.Series Series1)
{
r = new Random();
dt = DateTime.Now;
tChart1.AutoRepaint = false;
tChart2.AutoRepaint = false;
tChart3.AutoRepaint = false;
tChart4.AutoRepaint = false;
// show only 50 points - delete the rest
while (Series1.Count > 10000)
{
Series1.Delete(0);
}
if (Series1.Count > 10000)
{
Series1.Delete(0);
}
else
{
for (int t = 0; t < 100; t++)
{
Series1.Add(dt, r.Next(1000));
dt = dt.AddSeconds(15);
}
}
tChart1.AutoRepaint = true;
tChart2.AutoRepaint = true;
tChart3.AutoRepaint = true;
tChart4.AutoRepaint = true;
tChart1.Refresh();
tChart2.Refresh();
tChart3.Refresh();
tChart4.Refresh();
}
private void InitialDataSeries(Steema.TeeChart.Styles.Series Series1)
{
//Arrays
dt = DateTime.Now;
r = new Random();
Xvalues1 = new DateTime[18000];
Yvalues1 = new double[18000];
(Series1 as Steema.TeeChart.Styles.FastLine).DrawAllPoints = false;
for (int j = 0; j < 18000; j++)
{
Xvalues1[j] = dt;
dt = dt.AddSeconds(15);
Yvalues1[j] = r.Next(1000);
}
Series1.Add(Xvalues1, Yvalues1);
}
Could you tell us if it help you? On the other hand, if my code doesn't help you I recommend you use TeeChartDirect2D, this is ideal for the high speed data throughput required by DSP realtime applications. See the White paper, Boosting graphics-rendering performance in Windows Forms, for a closer look.
Thanks,

Related

MS Chart - updating X axis tick values at run time in line chart

My requirement is in my line graph( which is developed with c# MS Chart), I
always need to display 10 points(samples) at a time. The xaxis has interval value 1.
Initially the Xaxis tick values are (1,2,3,4,5,6,7,8,9,10), After 1 second of time interval, I
have to plot 10 points(samples) starts from 2nd point(i.e. I have to skip 1st
point).Now I need to update the xaxis tick values also , it should be starts from
2,now the xaxis tick values should be like 2,3,4,5,6,7,8,9,10,11). Likewise
After every second the starting value of x axis
tick needs to be increased by 1.
How to update Xaxis tick value in the chart dynamically ?
I am using below code
private void Form1_Load(object sender, EventArgs e)
{
loadCsvFile("C:\\mydata.csv");
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.timer1 = new System.Windows.Forms.Timer(this.components);
chart = new System.Windows.Forms.DataVisualization.Charting.Chart();
chart.Location = new System.Drawing.Point(1, 1);
chart.Size = new System.Drawing.Size(700, 700);
// Add a chartarea called "draw", add axes to it and color the area black
chart.ChartAreas.Add("draw");
numofSamples = 10;
chart.ChartAreas["draw"].AxisX.Minimum = 1;
chart.ChartAreas["draw"].AxisX.Maximum = 10;
chart.ChartAreas["draw"].AxisX.Interval = 1;
chart.ChartAreas["draw"].AxisX.Title = "X Axis";
chart.ChartAreas["draw"].AxisX.MajorGrid.LineColor = System.Drawing.Color.Black;
chart.ChartAreas["draw"].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
chart.ChartAreas["draw"].AxisY.Minimum = 0;
chart.ChartAreas["draw"].AxisY.Maximum = 1000;
chart.ChartAreas["draw"].AxisY.Interval = 250;
chart.ChartAreas["draw"].AxisY.Title = "Y Axis";
chart.ChartAreas["draw"].AxisY.MajorGrid.LineColor = Color.Black;
chart.ChartAreas["draw"].AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
chart.ChartAreas["draw"].BackColor = Color.White;
// Create a new function series
chart.Series.Add("Tags");
// Set the type to line
chart.Series["Tags"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
// Color the line of the graph light green and give it a thickness of 3
chart.Series["Tags"].Color = Color.LightGreen;
chart.Series["Tags"].BorderWidth = 3;
chart.Series["Tags"].MarkerStyle = MarkerStyle.Circle;
chart.Series["Tags"].MarkerSize = 10;
chart.Legends.Add("MyLegend");
chart.Legends["MyLegend"].BorderColor = Color.Tomato; // I like tomato juice!
Controls.Add(this.chart);
// hook up timer event
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
timer1.Start();
}
public void loadCsvFile(string filePath)
{
var reader = new StreamReader(File.OpenRead(filePath));
while (!reader.EndOfStream)
{
List<string> listA = new List<string>();
string line = reader.ReadLine();
mList.Add(line );
}
}
int i = 0;
int n = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (n > 20)
n = 0;
int j=0;
chart.Series["Tags"].Points.Clear();
for (i=n; i < mList.Count; i++)
{
string l =mList[i];
chart.Series["Tags"].Points.AddY(l);
j++;
if (j == 10)
break;
}
n++;
chart.Update();
}
List<List<string>> mList = new List<List<string>>();

Create new instance uses much memory

I use Nevron Chart in my program. following code is in a click button event:
this.nChartControl1 = new NChartControl();
// add data to chart ...
after each click program allocates a lot of memory and even GC.Collect() doesn't clean the memory, and if I use one instance of Nevron Chart and every time clean the data and then add new data every thing is OK.
what's the problem?
Update 1: here is the function
private void button_Click(object sender, RoutedEventArgs e)
{
//if (nChartControl1 == null)
{
this.nChartControl1 = new NChartControl();
}
// clear data
nChartControl1.Charts.Clear();
nChartControl1.Panels.Clear();
GC.Collect();
// empty the grid then add NevronChart
this.grid.Children.Clear();
this.grid.Children.Add(nChartControl1);
nChartControl1.BackgroundStyle.FrameStyle.Visible = false;
// set a chart title
NLabel title = nChartControl1.Labels.AddHeader("2D Line Chart");
// setup chart
NCartesianChart chart = new NCartesianChart();
nChartControl1.Panels.Add(chart);
chart.DockMode = PanelDockMode.Fill;
chart.Margins = new NMarginsL(2, 0, 2, 2);
chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
chart.LightModel.EnableLighting = false;
chart.Axis(StandardAxis.Depth).Visible = false;
chart.Wall(ChartWallType.Floor).Visible = false;
chart.Wall(ChartWallType.Left).Visible = false;
chart.BoundsMode = BoundsMode.Stretch;
chart.Height = 40;
chart.RangeSelections.Add(new NRangeSelection());
chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;
chart.Axis(StandardAxis.PrimaryY).ScrollBar.Visible = true;
// setup the line series
NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);
//line.Values.FillRandom(new Random(), 10);
SetRandomData(line);
line.DataLabelStyle.Visible = false;
line.Legend.Mode = SeriesLegendMode.DataPoints;
line.ShadowStyle.Type = ShadowType.GaussianBlur;
line.ShadowStyle.Offset = new NPointL(new NLength(3, NGraphicsUnit.Pixel), new NLength(3, NGraphicsUnit.Pixel));
line.ShadowStyle.FadeLength = new NLength(5, NGraphicsUnit.Pixel);
line.ShadowStyle.Color = System.Drawing.Color.FromArgb(55, 0, 0, 0);
line.LineSegmentShape = LineSegmentShape.Line;
nChartControl1.Controller.Tools.Add(new NSelectorTool());
nChartControl1.Controller.Tools.Add(new NAxisScrollTool());
nChartControl1.Controller.Tools.Add(new NDataZoomTool());
NDataPanTool dpt = new NDataPanTool();
nChartControl1.Controller.Tools.Add(dpt);
nChartControl1.Legends.Clear();
nChartControl1.Refresh();
}
I just tested the control using the following code:
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 100000; i++)
{
using (NChartControl chartControl = new NChartControl())
{
// set a chart title
NLabel title = chartControl.Labels.AddHeader("2D Line Chart");
// setup chart
NCartesianChart chart = new NCartesianChart();
chartControl.Panels.Add(chart);
chart.DockMode = PanelDockMode.Fill;
chart.Margins = new NMarginsL(2, 0, 2, 2);
chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal);
chart.LightModel.EnableLighting = false;
chart.Axis(StandardAxis.Depth).Visible = false;
chart.Wall(ChartWallType.Floor).Visible = false;
chart.Wall(ChartWallType.Left).Visible = false;
chart.BoundsMode = BoundsMode.Stretch;
chart.Height = 40;
chart.RangeSelections.Add(new NRangeSelection());
chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;
chart.Axis(StandardAxis.PrimaryY).ScrollBar.Visible = true;
// setup the line series
NLineSeries line = (NLineSeries)chart.Series.Add(SeriesType.Line);
//line.Values.FillRandom(new Random(), 10);
line.DataLabelStyle.Visible = false;
line.Legend.Mode = SeriesLegendMode.DataPoints;
line.ShadowStyle.Type = ShadowType.GaussianBlur;
line.ShadowStyle.Offset = new NPointL(new NLength(3, NGraphicsUnit.Pixel), new NLength(3, NGraphicsUnit.Pixel));
line.ShadowStyle.FadeLength = new NLength(5, NGraphicsUnit.Pixel);
line.ShadowStyle.Color = System.Drawing.Color.FromArgb(55, 0, 0, 0);
line.LineSegmentShape = LineSegmentShape.Line;
chartControl.Controller.Tools.Add(new NSelectorTool());
chartControl.Controller.Tools.Add(new NAxisScrollTool());
chartControl.Controller.Tools.Add(new NDataZoomTool());
NDataPanTool dpt = new NDataPanTool();
chartControl.Controller.Tools.Add(dpt);
chartControl.Legends.Clear();
chartControl.Refresh();
}
}
}
And there was no memory leak in the control. So the answer is that you need to call dispose or use a using statement.

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.

ZedGraph - How to change X-axis from points to time?

i have a working DLL where i have one function to add arrays to a list and another function that shows all list-arrays in a ZED-Graph-diagram. All arrays have the same size.
Currently the x-axis is shown in points from 0 to 1024.
Question is: What do i have to change to display the x-axis in time?
I have the value "Intervall" (time between two points) that i can pass into the function.
Thanks for the help.
Here is what i have so far:
public void AddGraph(double[] Values, string LegendName)
{
int i = 0;
PointPairList list = new PointPairList();
for (i = 0; i < Values.Length; i++)
{
list.Add(i, Values[i]);
}
if (i > MaxXAxis)
MaxXAxis = i;
SList.Add(list);
SListColor.Add(Color.Black);
SListName.Add(LegendName);
}
public void ShowDiagram(string Title, string XAxisName, string YAxisName, int Timeout_ms)
{
ZedGraph.ZedGraphControl zgc = new ZedGraphControl();
GraphPane myPane = zgc.GraphPane;
LineItem myCurve = null;
// Set the titles and axis labels
myPane.Title.Text = Title;
myPane.XAxis.Title.Text = XAxisName;
myPane.YAxis.Title.Text = YAxisName;
for (int i = 0; i < SList.Count(); i++)
{
myCurve = myPane.AddCurve(SListName[i], SList[i], SListColor[i], SymbolType.None);
myCurve.Line.Width = 2;
}
// Add gridlines to the plot, and make them gray
myPane.XAxis.MinorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
myPane.XAxis.MinorGrid.Color = Color.LightGray;
myPane.YAxis.MinorGrid.Color = Color.LightGray;
myPane.XAxis.MinorGrid.DashOff = 0;
myPane.YAxis.MinorGrid.DashOff = 0;
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.XAxis.MajorGrid.Color = Color.Gray;
myPane.YAxis.MajorGrid.Color = Color.Gray;
myPane.XAxis.MajorGrid.DashOff = 0;
myPane.YAxis.MajorGrid.DashOff = 0;
// Move Legend to buttom
myPane.Legend.Position = LegendPos.Bottom;
zgc.AxisChange();
myPane.XAxis.Scale.Max = MaxXAxis;
zgc.Location = new Point(0, 0);
zgc.Size = new Size(panel_diagramm.ClientRectangle.Width, panel_diagramm.ClientRectangle.Height);
panel_diagramm.Controls.Add(zgc);
}
This is my first time posting so I apologize for not putting it in a better format.
The following allows you to setup your x-axis to display time:
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Title.Text = "Time (HH:MM:SS)";
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.XAxis.Scale.MajorUnit = DateUnit.Minute;
myPane.XAxis.Scale.MinorUnit = DateUnit.Minute;
myPane.XAxis.Scale.Min = DateTime.Now.Subtract(new TimeSpan(0, 0, 10, 0, 0).ToOADate();
myPane.XAxis.Scale.Max = DateTime.Now.ToOADate();

Why do my X-Axes labels disappear when I zoom using MS Chart Controls?

I'm using MS Chart Controls. The line chart is a normal time based chart. The problem is when I click the chart and select some time it zooms in, the scrollbar appears, and the x-axes labels disappears. How can I prevent this from happening? If I cannot fix it automatically, is there code I can add to a button that will fix the labels?
private void Chart0Configuration()
{
chart1.ChartAreas[0].Visible = false;
chart1.ChartAreas[0].AlignmentOrientation = AreaAlignmentOrientations.Vertical;
chart1.ChartAreas[0].AlignmentStyle = AreaAlignmentStyles.All;
chart1.ChartAreas[0].Position.Auto = false;
chart1.ChartAreas[0].Position.X = 2;
chart1.ChartAreas[0].Position.Y = 10;
chart1.ChartAreas[0].Position.Width = 98;
//chart1.ChartAreas[0].Position.Height = *****variable
//chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false;
//chart1.ChartAreas[0].AxisY.MinorTickMark.Enabled = false;
//chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
//chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = true;
//chart1.ChartAreas[0].AxisX.MinorTickMark.Enabled = true;
//chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
//chart1.ChartAreas[0].AxisX.MajorTickMark.Interval = 10;
chart1.ChartAreas[0].AxisX.Interval = 0;
chart1.ChartAreas[0].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
chart1.ChartAreas[0].AxisX.LabelStyle.Enabled = true;
//chart1.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm:ss";
chart1.ChartAreas[0].AxisY.LabelStyle.IsEndLabelVisible = true;
chart1.ChartAreas[0].InnerPlotPosition.Auto = false;
chart1.ChartAreas[0].InnerPlotPosition.X = 3;
chart1.ChartAreas[0].InnerPlotPosition.Y = 10;
chart1.ChartAreas[0].InnerPlotPosition.Width = 88;
chart1.ChartAreas[0].InnerPlotPosition.Height = 80;
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
//chart1.ChartAreas[0].CursorX.AutoScroll = true;
chart1.ChartAreas[0].CursorX.Position = 0;
chart1.ChartAreas[0].CursorX.Interval = 0;
chart1.ChartAreas[0].AxisX.ScrollBar.Size = 5;
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
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.ScaleView.Zoomable = true;
}
I inadvertently found the answer when looking at the intervals. They stay visible now that I've add the following line of code.
chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days;

Categories