3D graph in ASP.NET MVC - c#

I want to see the series more clearly (side by side). How can I achieve it?
Chart1.Series["Legend"].Points.DataBindXY(xAxis, yAxis);
Chart1.Series["Legend1"].Points.DataBindXY(xAxis, yAxis);
Chart1.Series["Legend"].ChartType = SeriesChartType.Column;
Chart1.Series["Legend1"].ChartType = SeriesChartType.Column;
Chart1.Series["Legend"].IsValueShownAsLabel = false;
Chart1.Series["Legend"].Color = Color.FromArgb(198, 99, 99);
// Chart1.Series["Legend"].ChartType = ;
Chart1.Series["Legend"].BorderWidth = 2;
Chart1.ChartAreas["studentChartArea"].Area3DStyle.Enable3D = true;
Chart1.ChartAreas["studentChartArea"].Area3DStyle.LightStyle = System.Web.UI.DataVisualization.Charting.LightStyle.Realistic;
Chart1.ChartAreas["studentChartArea"].Area3DStyle.PointGapDepth = 50;
Chart1.ChartAreas["studentChartArea"].Area3DStyle.WallWidth = 10;

Related

How Do I Get The Scale of The Secondary Axis to be Based on My Series Values?

I'm using System.Web.UI.DataVisualization. Charting to create charts in MVC.
I have a chart displaying values in a StackedColumn100 SeriesChartType with the corresponding y-axis values on the primary y-axis on the left side.
Since it is a 100% stacked column series, the primary y-axis is scaled from 0 to 100.
I have then added a secondary series in the form of a Line SeriesChartType tied to a secondary axis (on the right side). I would like this axis to adjust its scale based on the values in the series but it doesn't. No matter what the highest value of this series is, the secondary y-axis also has a scale between 0 to 100.
If I manually set the maximum value for the secondary y-axis the following way:
chart.ChartAreas[0].AxisY2.Maximum = 20;. It works but I don't want to do that since the maximum value can differ greatly based on the search criteria used.
I have really tried to find a solution for this but I can't. According to the documentation and samples it seems that the scale should be based on the series values but I don't get it to work that way. Any help would be greatly appreciated!
Below is a stand alone test function that recreates the problem. I call the function from my view with the following line:
<p><img src="#Url.Action("CreateChart_TestSecondaryAxis")" /> </p>
public FileResult CreateChart_TestSecondaryAxis()
{
System.Web.UI.DataVisualization.Charting.Chart chart = new System.Web.UI.DataVisualization.Charting.Chart();
chart.Width = 800;
chart.Height = 400;
chart.BackColor = Color.FromArgb(211, 223, 240);
chart.BorderlineDashStyle = ChartDashStyle.Solid;
chart.BackSecondaryColor = Color.White;
chart.BackGradientStyle = GradientStyle.TopBottom;
chart.BorderlineWidth = 1;
chart.Palette = ChartColorPalette.BrightPastel;
chart.BorderlineColor = Color.FromArgb(26, 59, 105);
chart.RenderType = RenderType.BinaryStreaming;
chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
chart.AntiAliasing = AntiAliasingStyles.All;
chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
ChartArea chartArea = new ChartArea();
chartArea.Name = "TestSecondaryAxis";
chartArea.BackColor = Color.Transparent;
chartArea.AxisX.IsLabelAutoFit = false;
chartArea.AxisY.IsLabelAutoFit = false;
chartArea.AxisX.LabelStyle.Font =
new Font("Verdana,Arial,Helvetica,sans-serif",
8F, FontStyle.Regular);
chartArea.AxisY.LabelStyle.Font =
new Font("Verdana,Arial,Helvetica,sans-serif",
8F, FontStyle.Regular);
chartArea.AxisY.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.Title = "Airport";
chartArea.AxisY.Title = "LandingConf";
chartArea.AxisY.TextOrientation = TextOrientation.Rotated270;
chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;
chart.ChartAreas.Add(chartArea);
Series seriesPrimaryAxisConf3 = new Series();
seriesPrimaryAxisConf3.Name = "Conf 3";
seriesPrimaryAxisConf3.IsValueShownAsLabel = false;
seriesPrimaryAxisConf3.Color = Color.Blue;
seriesPrimaryAxisConf3.ChartType = SeriesChartType.StackedColumn100;
seriesPrimaryAxisConf3.BorderWidth = 2;
seriesPrimaryAxisConf3.ChartArea = "TestSecondaryAxis";
DataPoint point;
for (int i = 1; i < 11; i++)
{
point = new DataPoint();
point.AxisLabel = "Airport" + i.ToString();
point.YValues = new double[] { i };
seriesPrimaryAxisConf3.Points.Add(point);
}
chart.Series.Add(seriesPrimaryAxisConf3);
Series seriesPrimaryAxisConfFull = new Series();
seriesPrimaryAxisConfFull.Name = "Conf Full";
seriesPrimaryAxisConfFull.IsValueShownAsLabel = false;
seriesPrimaryAxisConfFull.Color = Color.Red;
seriesPrimaryAxisConfFull.ChartType = SeriesChartType.StackedColumn100;
seriesPrimaryAxisConfFull.BorderWidth = 2;
seriesPrimaryAxisConfFull.ChartArea = "TestSecondaryAxis";
for (int i = 1; i < 11; i++)
{
point = new DataPoint();
point.AxisLabel = "Airport" + i.ToString();
point.YValues = new double[] { 11-i };
seriesPrimaryAxisConfFull.Points.Add(point);
}
chart.Series.Add(seriesPrimaryAxisConfFull);
Series seriesSecondaryAxisNoOfFlights = new Series();
seriesSecondaryAxisNoOfFlights.Name = "NoOfFLights";
seriesSecondaryAxisNoOfFlights.IsValueShownAsLabel = false;
seriesSecondaryAxisNoOfFlights.Color = Color.Red;
seriesSecondaryAxisNoOfFlights.ChartType = SeriesChartType.Line;
seriesSecondaryAxisNoOfFlights.BorderWidth = 2;
seriesSecondaryAxisNoOfFlights.ChartArea = "TestSecondaryAxis";
for (int i = 1; i < 11; i++)
{
point = new DataPoint();
point.AxisLabel = "Airport" + i.ToString();
point.YValues = new double[] { i };
seriesSecondaryAxisNoOfFlights.Points.Add(point);
}
chart.Series.Add(seriesSecondaryAxisNoOfFlights);
chart.Series["NoOfFLights"].YAxisType = AxisType.Secondary;
chart.ChartAreas["TestSecondaryAxis"].AxisY2.LineColor = Color.Transparent;
chart.ChartAreas["TestSecondaryAxis"].AxisY2.MajorGrid.Enabled = false;
chart.ChartAreas["TestSecondaryAxis"].AxisY2.MajorTickMark.Enabled = false;
MemoryStream ms = new MemoryStream();
chart.SaveImage(ms);
return File(ms.GetBuffer(), #"image/png");
}
MSChart is a nice control but unfortunately Microsoft has always failed to properly document it.
And with the latest changes at MSDN things have gone from bad to worse, so I can't actually point to the rules that go for the various ChartTypes.
In your case I deduct this (rather wacky) rule:
To attach a non 100%-series to an indepently scaled secondary y-axis
it must be the first series but the stacked series still must be added
first.
So, if you want to get a result like this:
..you need to adapt the code. Here are the changes and additions needed..:
First we have to insert the line series at the front but do that after the stack100 series have beeen added..:
chart.Series.Insert(0, seriesSecondaryAxisNoOfFlights); // instead of adding it
Next we need to owner-draw the line as it would get burried under the columns otherwise.
Code the PostPaint event like this:
private void Chart_PostPaint(object sender, ChartPaintEventArgs e)
{
Chart chart = sender as Chart; //*
Series s = chart.Series[0]; // make sure to pick the right one!
Axis ax = chart.ChartAreas[0].AxisX;
Axis ay = chart.ChartAreas[0].AxisY2; // !!
var pts = s.Points.Select(x =>
new PointF((float)ax.ValueToPixelPosition(x.XValue),
(float)ay.ValueToPixelPosition(x.YValues[0])));
using (Pen pen = new Pen(s.Color, s.BorderWidth))
e.ChartGraphics.Graphics.DrawLines(pen, pts.ToArray());
}
For this to work the series need valid x-values. So add this line:
point.XValue = i; // set both x and y-values!
I also added a few nudges to the axis positioning:
ChartArea ca = chart.ChartAreas["TestSecondaryAxis"];
ca.AxisY.Maximum = 100;
ca.AxisX.Minimum = 0.5;
ca.AxisX.IntervalOffset = 0.5;

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?

visifire Custom Axis Labels Not Showing

I need to Export my Chart as an image without showing it first in WPF. So i built the Chart in Code:
public void CreateHistogram(CalcRepository cr, int i)
{
Chart chart = new Chart();
chart.Width = 300;
chart.Height = 200;
chart.ScrollingEnabled = false;
chart.AnimationEnabled = false;
chart.TrendLines.Add(new TrendLine{Value = cr.Mean,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines.Add(new TrendLine{Value = cr.ChartTrippleNegativeStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});chart.TrendLines.Add(new TrendLine{Value = cr.ChartTripplePositiveStdDeviation,Orientation = System.Windows.Controls.Orientation.Vertical,LineStyle = LineStyles.Dashed});
chart.TrendLines.Add(new TrendLine{Value = cr.UpperSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines.Add(new TrendLine{Value = cr.LowerSpecificationLimit,Orientation = System.Windows.Controls.Orientation.Vertical});
chart.TrendLines[0].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[1].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[2].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[3].SetValue(Canvas.ZIndexProperty, 40);
chart.TrendLines[4].SetValue(Canvas.ZIndexProperty, 40);
chart.DataPointWidth = cr.DataPointWidth;
chart.Visibility = Visibility.Visible;
Axis x = new Axis();
x.AxisMaximum = cr.VisUpperBound;
x.AxisMinimum = cr.VisLowerBound;
x.AxisType = AxisTypes.Primary;
CustomAxisLabels cal = new CustomAxisLabels();
cal.Labels.Add(new CustomAxisLabel {From = cr.Mean, To = cr.Mean, Text = "Mean"});
cal.Labels.Add(new CustomAxisLabel {From = cr.ChartTrippleNegativeStdDeviation,To = cr.ChartTrippleNegativeStdDeviation,Text = "LCL"});
cal.Labels.Add(new CustomAxisLabel{From = cr.ChartTripplePositiveStdDeviation,To = cr.ChartTripplePositiveStdDeviation,Text= "UCL"});
cal.Labels.Add(new CustomAxisLabel {From = cr.UpperSpecificationLimit, To = cr.UpperSpecificationLimit , Text = "USL"});
cal.Labels.Add(new CustomAxisLabel {From = cr.LowerSpecificationLimit, To = cr.LowerSpecificationLimit, Text = "LSL"});
cal.FontSize = 10;
cal.Angle = 0;
cal.FontColor = new SolidColorBrush(Colors.Black);
cal.Enabled = true;
x.CustomAxisLabels.Add(cal);
chart.AxesX.Add(x);
var ds = new DataSeries();
var dpc = new DataPointCollection(cr.HistogramValues);
ds.DataPoints = dpc;
chart.Series.Add(ds);
ds.ZIndex = 1;
ds.Bevel = false;
ds.ShadowEnabled = false;
ds.LightingEnabled = false;
ds.Color = new SolidColorBrush(Colors.SteelBlue);
chart.BeginInit();
chart.EndInit();
chart.Measure(new Size(300, 200));
chart.Arrange(new Rect(0, 0, 300, 200));
chart.UpdateLayout();
ExportToPng(new Uri("C:\\" + i + ".png"), chart);
}
everything works fine, except the custom Axis Labels are missing. This is how the Output looks like:
As you can see, there is even space allocated for the CustomAxis Labels but they are not shown. Anyone got an idea?
Hint: AnimationEnabled has to be set false otherwise the series is not rendered yet when the image is taken - took me a long time to figure that out.
I found already a solution:
When exceeding the bounds, the values are set to Double.NaN. I found out, that the creation of all Labels fails, if any value in the Collections Double.Nan or Double.Infinity - Seems lika a bug in visifire.
I solved it by adding each Label in its seperate Collection.

C# chart zooming precision

I have a chart with dates (strings) as X values and decimals as Y values. I want to zoom in the chart but when setting:
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
it zooms up to interval 1 on the X axis.
I want to zoom-in gradually on the axis but when i set\
chart1.ChartAreas[0].CursorX.Interval = 0.1;
(anything except 1) the labes on the X axis disappear. Can somebody help me please, i am new to the chart controls. Please excuse my ignorance. Any advice would be very grateful
Here is a piece of my code so far:
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.Series[0].IsVisibleInLegend = false;
chart1.Series[0].ChartType = SeriesChartType.Area;
DateTime sday = Convert.ToDateTime(earnings1.dataGridView1[0, 0].Value.ToString());
chart1.Series[0].XValueType = ChartValueType.String;
int i = 0;
chart1.Series[0].SmartLabelStyle.Enabled = false;
foreach (DataGridViewRow dgvr in earnings1.dataGridView1.Rows)
{
decimal testing = Convert.ToDecimal(earnings1.dataGridView1[1, i].Value);
testing = decimal.Truncate(testing);
var point = new DataPoint(i + 1, Convert.ToDouble(testing));
point.Label = testing.ToString();
point.Font = new Font("Century Gothic", 8, FontStyle.Bold);
chart1.Series[0].Points.Add(point);
chart1.Series[0].LabelAngle = -90;
chart1.Series[0].Points[i].AxisLabel = sday.ToString("dd/MM/yyyy");
sday = sday.AddDays(1);
i++;
}
I found the way to do it:
chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Auto;
chart1.ChartAreas[0].CursorX.Interval = 1;
and let Visual Studio do the job for you.

Categories

Resources