//--------------------------------
//----- DO CHART BASIC SETUP -----
//--------------------------------
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = (new System.Windows.Forms.DataVisualization.Charting.ChartArea());
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = (new System.Windows.Forms.DataVisualization.Charting.Legend());
chartArea1.AxisX.TitleFont = new System.Drawing.Font("Arial", 9);
chartArea1.AxisY.TitleFont = new System.Drawing.Font("Arial", 9);
chartArea1.AxisY2.TitleFont = new System.Drawing.Font("Arial", 9);
//----- SETUP X AXIS (TIME) -----
chartArea1.AxisX.Title = "Secs";
chartArea1.AxisX.Minimum = 0;
chartArea1.AxisX.Maximum = (ApMain.GRAPHS_BUFFER_LOG_EVERY_SECS * ApMain.GRAPHS_BUFFER_LENGTH);
chartArea1.AxisX.Interval = 60; //Axis marker every #
chartArea1.AxisX.LabelStyle.Interval = 300; //Label the axis every #
chartArea1.AxisX.MajorGrid.Interval = 60; //Grid line every #
chartArea1.AxisX.MinorGrid.Interval = ApMain.GRAPHS_BUFFER_LOG_EVERY_SECS;
//chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
//chartArea1.AxisX.MinorGrid.LineColor = System.Drawing.Color.DarkGray;
//----- SETUP Y (RIGHT) AXIS (TEMPERATURE) -----
chartArea1.AxisY.Title = "Temperature (C)";
chartArea1.AxisY.TextOrientation = System.Windows.Forms.DataVisualization.Charting.TextOrientation.Rotated270;
chartArea1.AxisY.Minimum = 0;
chartArea1.AxisY.Maximum = 100;
chartArea1.AxisY.Interval = 10; //Axis marker every #
chartArea1.AxisY.LabelStyle.Interval = 10; //Label the axis every #
chartArea1.AxisY.MajorGrid.Interval = 5; //Grid line every #
chartArea1.AxisY.MinorGrid.Interval = 1;
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
chartArea1.AxisY.MinorGrid.LineColor = System.Drawing.Color.DarkGray;
//----- SETUP Y2 (LEFT) AXIS (POWER) -----
chartArea1.AxisY2.Title = "Power (W)";
chartArea1.AxisY2.TextOrientation = System.Windows.Forms.DataVisualization.Charting.TextOrientation.Rotated270;
chartArea1.AxisY2.Minimum = 0;
chartArea1.AxisY2.Maximum = 2500;
chartArea1.AxisY2.Interval = 100; //Axis marker every #
chartArea1.AxisY2.LabelStyle.Interval = 100; //Label the axis every #
chartArea1.AxisY2.MajorGrid.Interval = 100; //Grid line every #
chartArea1.AxisY2.MinorGrid.Interval = 10;
chartArea1.AxisY2.MajorGrid.Enabled = false; //Hide the grid lines across the chart area
//chartArea1.AxisY2.MajorGrid.LineColor = System.Drawing.Color.DarkGray;
//chartArea1.AxisY2.MinorGrid.LineColor = System.Drawing.Color.DarkGray;
//-----------------------------------
//----- RECREATE THE CHART AREA -----
//-----------------------------------
Chart1.ChartAreas.RemoveAt(0);
chartArea1.Name = "ChartArea1";
Chart1.ChartAreas.Add(chartArea1);
Chart1.Legends.RemoveAt(0);
legend1.Name = "Legend1";
Chart1.Legends.Add(legend1);
//Chart1.Text = L"chart1";
while (Chart1.Series.Count > 0)
Chart1.Series.RemoveAt(0);
//Draw 3 temperature lines
int LineCount;
for (LineCount = 0; LineCount < 3; LineCount++) //Lets draw multiple lines
{
//----- ADD SERIES -----
int Count;
int[] ValuesX = new int[1000];
double[] ValuesY = new double[1000];
for (Count = 0; Count < 1000; Count++)
{
ValuesX[Count] = Count;
ValuesY[Count] = (Count / 10) + (LineCount * 10) + 0.5;
}
System.Windows.Forms.DataVisualization.Charting.Series ChartSeries1 = (new System.Windows.Forms.DataVisualization.Charting.Series());
ChartSeries1.ChartArea = "ChartArea1";
ChartSeries1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
ChartSeries1.YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Primary; //<Select primary Axis Y
ChartSeries1.Legend = "Legend1";
ChartSeries1.Name = "Temperature " + LineCount;
ChartSeries1.Points.DataBindXY(ValuesX, ValuesY);
this.Chart1.Series.Add(ChartSeries1);
}
//Draw 1 power line (could also have multiple of these if we wanted)
int Count2;
int[] ValuesX2 = new int[1000];
double[] ValuesY2 = new double[1000];
for (Count2 = 0; Count2 < 1000; Count2++)
{
ValuesX2[Count2] = Count2;
ValuesY2[Count2] = Count2 * 2;
}
System.Windows.Forms.DataVisualization.Charting.Series ChartSeries2 = (new System.Windows.Forms.DataVisualization.Charting.Series());
ChartSeries2.ChartArea = "ChartArea1";
ChartSeries2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
ChartSeries2.YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary; //<Select secondary Axis Y2
ChartSeries2.Legend = "Legend1";
ChartSeries2.Name = "Power";
ChartSeries2.Points.DataBindXY(ValuesX2, ValuesY2);
this.Chart1.Series.Add(ChartSeries2);
Chart1.Visible = true;
return;
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.