Remove Grid Lines From Chart Control C# - c#

I have an application with Chart control that dynamic updated with data via timer:
Series series;
MyObject obj...
series = new Series();
chart1.Series.Add(series);
//chart1.Legends.Add(new Legend("DifferentLegend"));
//chart1.Legends["DifferentLegend"].DockedToChartArea = "Default";
//chart1.Series["Series1"].Legend = "DifferentLegend";
//chart1.Series["Series1"].IsVisibleInLegend = true;
series.Color = Color.Blue;
series.ChartType = SeriesChartType.Line;
series.BorderWidth = 3;
chart1.Series.Add(series);
//chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.White;
//chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.White;
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisX.Maximum = 4;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisX.IsStartedFromZero = true;
chart1.ChartAreas[0].AxisX.IntervalOffsetType = DateTimeIntervalType.Number;
Timer tick:
private void chartTimer_Tick(object sender, EventArgs e)
{
series.Points.Add(obj.BitsPerSecond * 0.000001);
}
I want to change it style and remove the squares from the control:
How can I do that?

Try This:
chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisX.MinorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
chart1.ChartAreas[0].AxisY.MinorGrid.LineWidth = 0;
To disable X-Axis Labels from the Chart :
chart1.ChartAreas[0].AxisX.LabelStyle.Enabled = false;

This then?
mainChart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
mainChart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
mainChart.ChartAreas[0].AxisX.MinorGrid.Enabled = false;
mainChart.ChartAreas[0].AxisY.MinorGrid.Enabled = false;

Related

Chart Area with scrollbar

I would like to have on the six chartareas on the image 6 scrollbars i have genrate it but on the srollbar apears a button if i pressed the button the scrollbare hide but i do not want this button can anyone help me with this Problem please.
the unintentional Button1
private void makeChartsScrollable(Chart chart) {
chart.ChartAreas[3].AxisX.ScrollBar.Enabled = true;
// chart.ChartAreas[3].CursorX.IsUserEnabled = false;
// chart.ChartAreas[3].CursorX.IsUserSelectionEnabled = false;
// chart.ChartAreas[2].AxisX.ScaleView.Zoomable = false;
// chart.ChartAreas[2].AxisX.IsLabelAutoFit = true;
// chart.ChartAreas[2].AxisX.ScaleView.Position = 0;
// chart.ChartAreas[2].AxisX.ScaleView.Size = 23;
//chart.ChartAreas[3].AxisX.
chart.ChartAreas[3].AxisX.ScaleView.Zoom(0, 8);
chart.ChartAreas[3].AxisX.ScaleView.MinSize = 0;
chart.ChartAreas[3].AxisX.ScrollBar.IsPositionedInside = true;
chart.ChartAreas[3].AxisX.ScrollBar.Size = 23;
chart.ChartAreas[3].AxisX.ScrollBar.ButtonColor = Color.Silver;
chart.ChartAreas[3].AxisX.ScrollBar.LineColor = Color.Black;
/*
chart.ChartAreas[3].AxisX2.ScaleView.Zoomable = false;
chart.ChartAreas[3].AxisX2.ScrollBar.Enabled = true;
chart.ChartAreas[3].AxisX2.ScaleView.Position = 0;
chart.ChartAreas[3].AxisX2.IsLabelAutoFit = false;
chart.ChartAreas[3].AxisX2.ScaleView.Size = 23;
chart.ChartAreas[3].AxisX2.ScrollBar.ButtonColor = Color.Silver;
chart.ChartAreas[3].AxisX2.ScrollBar.LineColor = Color.Black;*/
}

WPF graph column graph

I am trying to set up a column graph with the time. Why is my graph not showing up on the main window?
I initialized the graph object like this :
private Chart graph = new Chart();
my chart functions are:
private void DrawTimeChart(string testName,double time)
{
Series sinSeries = new Series();
sinSeries.ChartType = SeriesChartType.Column;
sinSeries.Color = System.Drawing.Color.Blue;
sinSeries.BorderWidth = 2;
sinSeries.Points.AddXY(testName,time);
}
private void cnvChart_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
graph.Width = 250;
graph.Height = 250;
host.Child = graph;
// Add the chart to the canvas so it can be displayed.
this.cnvChart.Children.Add(host);
}
private void SetUpChart(Chart funcChart, int marginX, int marginY)
{
graph.Series.Clear();
graph.ChartAreas.Clear();
graph.ChartAreas.Add("Default" + new Random());
// Add a series with some data points.
funcChart.Width = 349;
funcChart.Height = 177;
funcChart.Location = new System.Drawing.Point(marginX, marginY);
funcChart.ChartAreas[0].AxisX.Title = "X";
funcChart.ChartAreas[0].AxisX.Interval = 1.0;
funcChart.ChartAreas[0].AxisX.Crossing = 0;
funcChart.ChartAreas[0].AxisX.LabelStyle.Format = "{0.0}";
funcChart.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
funcChart.ChartAreas[0].AxisY.Title = "Y";
funcChart.ChartAreas[0].AxisY.Interval = 1.0;
funcChart.ChartAreas[0].AxisY.Crossing = 0;
funcChart.ChartAreas[0].AxisY.LabelStyle.Format = "{0.0}";
funcChart.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
funcChart.ChartAreas[0].AxisX.Maximum = 6;
funcChart.ChartAreas[0].AxisX.Minimum = -6;
funcChart.ChartAreas[0].AxisY.Maximum = 7;
funcChart.ChartAreas[0].AxisY.Minimum = -7;
}
I'm calling the functions like this:
SetUpChart(graph,5,5);
DrawTimeChart("test1",time1);
in regards to XAML, that's how my canvas is written:
<Canvas x:Name="cnvChart" HorizontalAlignment="Right" Height="177"
Margin="0,242,392.333,0" VerticalAlignment="Top" Width="349"
Loaded="cnvChart_Loaded" RenderTransformOrigin="0.5,0.5"/>

Adding pictureBox to panel with codes

I have a panel in Visual Studio/windows form app.But I coulnd't add pictureBox on it with code.It is working if I work without panel however I need it.MyCodes:
PictureBox[] pipe = new PictureBox[3];
private void Form1_Load(object sender, EventArgs e)
{
CreatePipes(1);}
private void CreatetopPipes(int Number)
{
for (int i = 0; i <= Number; i++)
{
PictureBox temp = new PictureBox();
this.Controls.Add(temp);
temp.Width = 50;
temp.Height = 350;
temp.BorderStyle = BorderStyle.FixedSingle;
temp.BackColor = Color.Red;
temp.Top = 30;
temp.Left = 300;
topPipe[i] = temp;
topPipe[i].Visible = true;
}
}
You can use panelName.Controls.Add(temp), and i advise you to change a top of PictureBox in for loop to view all PictureBox, like this :
private void CreatetopPipes(int Number)
{
for (int i = 0; i <= Number; i++)
{
PictureBox temp = new PictureBox();
panelName.Controls.Add(temp);
temp.Width = 50;
temp.Height = 350;
temp.BorderStyle = BorderStyle.FixedSingle;
temp.BackColor = Color.Red;
temp.Top = temp.Height * panelName.Controls.Count;
temp.Left = 300;
topPipe[i] = temp;
topPipe[i].Visible = true;
}
}

How do I limit the data collection on a chart?

I have a C# program that reads in data from an Arduino Mega four times a second and displays the data in two charts, each chart has two sets of data. After a couple of hours of running the data starts to lag. I can watch the program grow in size over time. I believe the problem is the charts are showing snapshot of 1 minute on each chart but the program just keeps collecting data and creating the memory leak issue. Is there a way to limit the data collection to a minute or two and dump the old data?
This is my first C# program I have ever written and I'm an old fart (62) and suffer from CRS "Can't Remember Sh_t".
Any help would be greatly appreciated.
Bryan
Program data collection
// load the main form and sets up the charts
private void TelemetryForm_Load(object sender, EventArgs e)
{
intensityChart.ChartAreas.Add("area");
intensityChart.Legends.Add("INTENSITY");
intensityChart.Legends.Add("I SENSE");
intensityChart.Series.Add("INTENSITY");
intensityChart.Series.Add("I SENSE");
intensityChart.Legends["INTENSITY"].Position.Auto = false;
intensityChart.Legends["INTENSITY"].Position.Height = 10;
intensityChart.Legends["INTENSITY"].Position.Width = 50;
intensityChart.Legends["INTENSITY"].Position.X = 20;
intensityChart.Legends["INTENSITY"].Position.Y = 0;
intensityChart.Legends["I SENSE"].Position.Auto = false;
intensityChart.Legends["I SENSE"].Position.Height = 10;
intensityChart.Legends["I SENSE"].Position.Width = 50;
intensityChart.Legends["I SENSE"].Position.X = 20;
intensityChart.Legends["I SENSE"].Position.Y = 0;
toolCapChart.ChartAreas.Add("area2");
toolCapChart.Series.Add("CAPACITOR VOLTAGE");
toolCapChart.Series.Add("TOOL VOLTAGE");
toolCapChart.Legends.Add("CAPACITOR VOLTAGE");
toolCapChart.Legends.Add("TOOL VOLTAGE");
toolCapChart.Legends["TOOL VOLTAGE"].Position.Auto = false;
toolCapChart.Legends["TOOL VOLTAGE"].Position.Height = 10;
toolCapChart.Legends["TOOL VOLTAGE"].Position.Width = 50;
toolCapChart.Legends["TOOL VOLTAGE"].Position.X = 20;
toolCapChart.Legends["TOOL VOLTAGE"].Position.Y = 0;
toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Auto = false;
toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Height = 10;
toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Width = 50;
toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.X = 20;
toolCapChart.Legends["CAPACITOR VOLTAGE"].Position.Y = 0;
timer1.Enabled = true;
timer1.Start();
}
// adds the data to the charts
public void chartRead(Double timeofday)
{
Double x = timeofday;
Double z = 1 * timeofday;
Double y = 6 * timeofday;
int charttime = 240;
FontHeight = -1;
intensityChart.ChartAreas["area"].Position.Auto = false;
intensityChart.ChartAreas["area"].Position.Y = 8;
intensityChart.Series["INTENSITY"].Points.AddXY(DateTime.Now.ToLongTimeString(), mic_out);
intensityChart.Series["I SENSE"].Points.AddXY(DateTime.Now.ToLongTimeString(), i_sense);
intensityChart.Series["INTENSITY"].LegendText = "INTENSITY";
intensityChart.Series["I SENSE"].LegendText = "I SENSE";
intensityChart.Series["INTENSITY"].Color = Color.Blue;
intensityChart.Series["I SENSE"].Color = Color.Orange;
intensityChart.Series["INTENSITY"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
intensityChart.Series["I SENSE"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
intensityChart.Series["I SENSE"].YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;
intensityChart.ChartAreas["area"].AxisX.Minimum = intensityChart.ChartAreas["area"].AxisX.Maximum - charttime;
intensityChart.ChartAreas["area"].AxisX.Interval =charttime/6;
intensityChart.ChartAreas["area"].AxisY.Minimum = 0;
intensityChart.ChartAreas["area"].AxisY.Maximum = 100;
intensityChart.ChartAreas["area"].AxisY.Interval = 10;
intensityChart.ChartAreas["area"].AxisY.MajorTickMark.Enabled = false;
intensityChart.ChartAreas["area"].AxisY.MajorTickMark.Interval = 5;
intensityChart.ChartAreas["area"].AxisY2.MajorTickMark.Enabled = false;
intensityChart.ChartAreas["area"].AxisY2.MajorTickMark.Interval = 5;
intensityChart.ChartAreas["area"].AxisX.MinorTickMark.Interval = 5;
intensityChart.ChartAreas["area"].AxisX.MinorTickMark.Enabled = true;
intensityChart.ChartAreas["area"].AxisY.MinorTickMark.Interval = 5;
intensityChart.ChartAreas["area"].AxisY.MinorTickMark.Enabled = true;
intensityChart.ChartAreas["area"].AxisY2.Minimum = 0;
intensityChart.ChartAreas["area"].AxisY2.Maximum = isenseYscale;
intensityChart.ChartAreas["area"].AxisY2.Interval = isenseYscale/10;
intensityChart.ChartAreas["area"].AxisX2.MinorTickMark.Interval = 5;
intensityChart.ChartAreas["area"].AxisX2.MinorTickMark.Enabled = true;
intensityChart.ChartAreas["area"].AxisY2.MinorTickMark.Interval = 1;
intensityChart.ChartAreas["area"].AxisY2.MinorTickMark.Enabled = true;
intensityChart.ChartAreas["area"].AxisY.Title = "INTENSITY";
intensityChart.ChartAreas["area"].AxisY2.Title = "I SENSE";
toolCapChart.ChartAreas["area2"].Position.Auto = false;
toolCapChart.ChartAreas["area2"].Position.Y = 8;
toolCapChart.Series["TOOL VOLTAGE"].Color = Color.Red;
toolCapChart.Series["CAPACITOR VOLTAGE"].Color = Color.Green;
toolCapChart.Series["CAPACITOR VOLTAGE"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
toolCapChart.Series["TOOL VOLTAGE"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
toolCapChart.Series["TOOL VOLTAGE"].YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;
toolCapChart.Series["TOOL VOLTAGE"].LegendText = "TOOL VOLTAGE";
toolCapChart.Series["CAPACITOR VOLTAGE"].LegendText = "CAPACITOR VOLTAGE";
toolCapChart.Series["CAPACITOR VOLTAGE"].Points.AddXY(DateTime.Now.ToLongTimeString(), hv_sense);
toolCapChart.Series["TOOL VOLTAGE"].Points.AddXY(DateTime.Now.ToLongTimeString(), tool_vin);
toolCapChart.ChartAreas["area2"].AxisX.Minimum = toolCapChart.ChartAreas["area2"].AxisX.Maximum - charttime;
toolCapChart.ChartAreas["area2"].AxisY2.Minimum = 0;
toolCapChart.ChartAreas["area2"].AxisY2.Maximum = toolVoltageChart;
toolCapChart.ChartAreas["area2"].AxisY.Minimum = 0;
toolCapChart.ChartAreas["area2"].AxisY.Maximum =hvSenseChartYScale;
toolCapChart.ChartAreas["area2"].AxisY2.MinorTickMark.Interval = toolVoltageChart/25;
toolCapChart.ChartAreas["area2"].AxisY2.MinorTickMark.Enabled = true;
toolCapChart.ChartAreas["area2"].AxisY2.MajorTickMark.Interval = 100;
toolCapChart.ChartAreas["area2"].AxisY2.MajorTickMark.Enabled = false;
toolCapChart.ChartAreas["area2"].AxisX.Interval = charttime/6;
toolCapChart.ChartAreas["area2"].AxisX.MinorTickMark.Interval = 5;
toolCapChart.ChartAreas["area2"].AxisX.MinorTickMark.Enabled = true;
toolCapChart.ChartAreas["area2"].AxisY.MinorTickMark.Interval = hvSenseChartYScale/25;
toolCapChart.ChartAreas["area2"].AxisY.MinorTickMark.Enabled = true;
toolCapChart.ChartAreas["area2"].AxisY.MajorTickMark.Interval = 1000;
toolCapChart.ChartAreas["area2"].AxisY.MajorTickMark.Enabled = false;
toolCapChart.ChartAreas["area2"].AxisY2.Title = "TOOL VOLTAGE";
toolCapChart.ChartAreas["area2"].AxisY.Title = "CAPACITOR VOLTAGE";
capVoltageAngularGauge.Value = hv_sense;
pulseIntensityLinearGauge.Value = mic_ph_out;
pulseIntensityLinearGauge.Max = mic_ph_scaling;
After calling series.Points.AddXY(...) try calling series.Points.RemoveAt(0) if the series has more points than can be displayed. This effectively pops the oldest each time a new one comes in.
if(toolCapChart.Series["TOOL VOLTAGE"].Points.Count > maxSize)
toolCapChart.Series["TOOL VOLTAGE"].Points.RemoveAt(0);

setting axis minumum as negative number, but have bar extend down to origin instead of zero

I have 2 bar series in a tee chart. One is a percent value between 0 and 100 and uses the left axis. The other is a temperature, uses the right axis, and the range of possible values is between -40F and 160F.
I would like both bars to start at the bottom axis. I thought that the UseOrigin and Origin properties of the series would do this but apparently it doesn't work.
Below is my code:
chartTank = new TChart();
chartTank.Axes.Left.Grid.Visible = false;
chartTank.Axes.Right.Grid.Visible = false;
chartTank.Axes.Right.Maximum = 160.0;
chartTank.Axes.Right.Minimum = -40;
chartTank.Axes.Right.Increment = 40;
chartTank.Axes.Right.Automatic = false;
chartTank.Axes.Right.AutomaticMinimum = false;
chartTank.Axes.Right.AutomaticMaximum = false;
chartTank.Aspect.View3D = false;
chartTank.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
chartTank.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
chartTank.Axes.Left.Grid.Visible = false;
chartTank.Axes.Bottom.GridCentered = false;
chartTank.Axes.Bottom.Ticks.Visible = false;
chartTank.Axes.Left.Automatic = false;
chartTank.Axes.Left.Minimum = 0;
chartTank.Axes.Left.Maximum = 100;
chartTank.Axes.Right.Visible = true;
var barProduct = new Steema.TeeChart.Styles.Bar();
barProduct.MultiBar = MultiBars.Stacked;
barProduct.Color = Color.Green;
barProduct.Marks.Visible = false;
barProduct.Title = "% Vol";
barProduct.ShowInLegend = true;
chartTank.Series.Add(barProduct);
var barTemperature = new Steema.TeeChart.Styles.Bar();
barTemperature.MultiBar = MultiBars.None;
barTemperature.Color = Color.FromArgb(153, 74, 11);
barTemperature.Marks.Visible = false;
barTemperature.VertAxis = VerticalAxis.Right;
barTemperature.UseOrigin = true;
barTemperature.Origin = -40;
barTemperature.Title = "Temperature";
barTemperature.ShowInLegend = true;
chartTank.Series.Add(barTemperature);
Controls.Add(chartTank);
Here is the result:
I am using TeeChart 2014 4.1 for .NET running on windows CE 6.0
The following code:
private void InitializeChart()
{
tChart1.Axes.Right.Grid.Visible = false;
tChart1.Axes.Right.Maximum = 160.0;
tChart1.Axes.Right.Minimum = -40;
tChart1.Axes.Right.Increment = 40;
tChart1.Axes.Right.Automatic = false;
tChart1.Axes.Right.AutomaticMinimum = false;
tChart1.Axes.Right.AutomaticMaximum = false;
tChart1.Aspect.View3D = false;
tChart1.Panel.Bevel.Inner = Steema.TeeChart.Drawing.BevelStyles.None;
tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
tChart1.Axes.Left.Grid.Visible = false;
tChart1.Axes.Bottom.Grid.Centered = false;
tChart1.Axes.Bottom.Ticks.Visible = false;
tChart1.Axes.Left.Automatic = false;
tChart1.Axes.Left.Minimum = 0;
tChart1.Axes.Left.Maximum = 100;
tChart1.Axes.Right.Visible = true;
var barProduct = new Steema.TeeChart.Styles.Bar();
barProduct.MultiBar = MultiBars.Side;
barProduct.Color = Color.Green;
barProduct.Marks.Visible = false;
barProduct.Title = "% Vol";
barProduct.ShowInLegend = true;
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
barProduct.Add(rnd.Next(0, 100));
}
tChart1.Series.Add(barProduct);
var barTemperature = new Steema.TeeChart.Styles.Bar();
barTemperature.MultiBar = MultiBars.Side;
barTemperature.Color = Color.FromArgb(153, 74, 11);
barTemperature.Marks.Visible = false;
barTemperature.VertAxis = VerticalAxis.Right;
barTemperature.UseOrigin = true;
barTemperature.Origin = -40;
barTemperature.Title = "Temperature";
barTemperature.ShowInLegend = true;
for (int i = 0; i < 10; i++)
{
barTemperature.Add(rnd.Next(-40, 160));
}
tChart1.Series.Add(barTemperature);
tChart1.Panel.Gradient.Visible = false;
tChart1.Walls.Back.Gradient.Visible = false;
tChart1.Panel.Color = Color.White;
tChart1.Walls.Back.Color = Color.White;
}
gives me the following chart:
Do you get the same results at your end?

Categories

Resources