How to change the default y axis for self stack bar - c#

I want to plot a Bar series with MultiBars style as SelfStack. By default the self stack bar y axis value is 0 , Is there any way to change the default y axis for self stack bar
public class Bar_SelfStack
{
private Steema.TeeChart.Styles.Bar bar1;
private System.ComponentModel.IContainer components = null;
private Steema.TeeChart.TChart tChart1;
private Steema.TeeChart.Tools.GridBand gridBand1;
public Bar_SelfStack()
{
// This call is required by the Windows Form Designer.
InitializeComponent();
bar1.Add(100, "Cars");
bar1.Add(300, "Phones");
bar1.Add(200, "Lamps");
// Set "Self-Stacked":
bar1.MultiBar = Steema.TeeChart.Styles.MultiBars.SelfStack;
// cosmetic
bar1.Marks.Visible = false;
bar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value;
bar1.ColorEach = true;
}
}

You can change the default Y axis to custom vertical axis as do in next simple code:
Steema.TeeChart.TChart tChart1;
public Form1()
{
InitializeComponent();
tChart1 = new TChart();
this.Controls.Add(tChart1);
tChart1.Top = 150;
tChart1.Left = 100;
tChart1.Height = 400;
tChart1.Width = 550;
InitializeChart();
}
Steema.TeeChart.Styles.Bar series1, series2, series3,series4;
Steema.TeeChart.Axis axis1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
series1 = new Bar(tChart1.Chart);
series2 = new Bar(tChart1.Chart);
series3 = new Bar(tChart1.Chart);
series4 = new Bar(tChart1.Chart);
axis1 = new Axis(tChart1.Chart);
tChart1.Axes.Custom.Add(axis1);
series1.FillSampleValues();
series2.FillSampleValues();
series3.FillSampleValues();
series4.FillSampleValues();
series1.Marks.Visible = false;
series2.Marks.Visible = false;
series3.Marks.Visible = false;
series4.Marks.Visible = false;
axis1.RelativePosition = tChart1.Panel.MarginLeft -12;
tChart1.Panel.MarginLeft = 10;
axis1.Horizontal = false;
series1.CustomVertAxis = axis1;
series1.MultiBar = MultiBars.SelfStack;
button1.Click +=button1_Click;
}
Could you tell us if previous code help you to achieve as you want?
I hope will helps.
Thanks,

Related

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"/>

Zoom in downsampling chart

I use a .NET Winform version teechart 4.1.2012.1032.
I modified the sample that you supplied. "Extended\Reducing number of points\DownSampling Additions"
But When I zoom in chart, fastline's marks count is not 100 , downSampling.DisplayedPointCount.
How can I resolve it?
private void InitializeChart()
{
this.cursorTool1 = new Steema.TeeChart.Tools.CursorTool();//
this.tChart1.Tools.Add(this.cursorTool1);//
this.cursorTool1.FollowMouse = true;//
this.cursorTool1.Style = Steema.TeeChart.Tools.CursorToolStyles.Vertical;//
this.cursorTool1.Change += new Steema.TeeChart.Tools.CursorChangeEventHandler(this.cursorTool1_Change);//
CreateArrays();
tChart1.Aspect.View3D = false;
tChart1.Zoom.Direction = ZoomDirections.Both;//.Horizontal;//
tChart1.Series.Add(points = new Steema.TeeChart.Styles.Points());
tChart1.Series.Add(fastLine = new Steema.TeeChart.Styles.FastLine());
downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
points.Add(xValues, yValues);
points.Active = false;
downSampling.DisplayedPointCount = 100;
downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLast;// Null;
fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
fastLine.DataSource = points;
fastLine.Function = downSampling;
this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(this.tChart1.Chart));//
this.tChart1[1].CustomVertAxis = this.tChart1.Axes.Custom[0];//
this.tChart1[0].CustomVertAxis = this.tChart1.Axes.Custom[0];//
this.fastLine.Marks.Visible = true;//
}
private void CreateArrays()
{
int length = 2600000;
xValues = new Nullable<double>[length];
yValues = new Nullable<double>[length];
Random rnd = new Random();
for (int i = 0; i < length; i++)
{
xValues[i] = i;
yValues[i] = i;
}
}
private void tChart1_Zoomed(object sender, EventArgs e)
{
tChart1[1].CheckDataSource(); //series 1 is the function series
}
The DisplayedPointCount specifies how many points the DownSampling function should paint and displays this number as a maximum number of points. As I explained here, you may need to combine it with Tolerance property to get the results you expect. So, you could do something like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
//tChart1.Dock = DockStyle.Fill;
tChart1.Aspect.View3D = false;
tChart1.Zoomed += tChart1_Zoomed;
Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
Random y = new Random();
for (int i = 0; i < 10000; i++)
{
points1.Add(DateTime.Now.AddHours(i), y.Next());
}
points1.XValues.DateTime = true;
points1.Pointer.HorizSize = 1;
points1.Pointer.VertSize = 1;
Steema.TeeChart.Functions.DownSampling downSampling1 = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
downSampling1.Method = Steema.TeeChart.Functions.DownSamplingMethod.Average;
downSampling1.Tolerance = 100;
downSampling1.DisplayedPointCount = Convert.ToInt32(downSampling1.Tolerance * 4);
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.Function = downSampling1;
line1.DataSource = points1;
line1.Marks.Visible = true;
line1.Marks.Style = MarksStyles.PointIndex;
UpdateTitle();
}
void tChart1_Zoomed(object sender, EventArgs e)
{
tChart1[1].CheckDataSource();
UpdateTitle();
}
private void UpdateTitle()
{
tChart1.Header.Text = (tChart1[1].Function as Steema.TeeChart.Functions.DownSampling).DisplayedPointCount.ToString();
}
}

Remove Grid Lines From Chart Control 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;

Teechart: bottom axes label angle

I'm using Teechart for .net V3.
When trying to rotate the X-labels to 45° some of the labels are not displayed, but if the angle is set to 90° it is OK.
Please see the following images:
This is 45° rotation:
This is 90° rotation:
Is it possible to show all the labels with 45° angle?
I think you can use custom labels to achieve all labels appear when you use an angle of 45º. You can do something as next code:
private Steema.TeeChart.TChart tChart1;
public Form1()
{
InitializeComponent();
tChart1 = new Steema.TeeChart.TChart();
this.Controls.Add(tChart1);
tChart1.Left = 100;
tChart1.Top = 50;
tChart1.Width = 500;
tChart1.Height = 350;
tChart1.Dock = DockStyle.Fill;
InitialzieChart();
}
private void InitialzieChart()
{
Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
DateTime dt = DateTime.Today;
Random rnd = new Random();
bar1.XValues.DateTime = true;
//bar1.date
for (int i = 0; i < 20; i++)
{
bar1.Add(dt, rnd.Next(100));
dt = dt.AddDays(5);
}
tChart1.Axes.Bottom.Labels.Angle = 45;
tChart1.Panel.MarginLeft = 10;
tChart1.Legend.Alignment = Steema.TeeChart.LegendAlignments.Bottom;
AddCustomLabels();
}
private void AddCustomLabels()
{
tChart1.Axes.Bottom.Labels.Items.Clear();
for (int i = 0; i < tChart1[0].Count; i++)
{
tChart1.Axes.Bottom.Labels.Items.Add(tChart1[0].XValues[i], DateTime.FromOADate(tChart1[0].XValues[i]).ToLongDateString());
}
}
Could you tell us if previous code works in your end?
Thanks,

GMap.NET question

i am trying to use GMap.NET to display a map using the following code
GMapControl g = new GMapControl();
GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
g.Dock = DockStyle.Fill;
pnlMap.Controls.Add(g);
g.MapType = MapType.GoogleMap;
g.MaxZoom = 6;
g.MinZoom = 1;
g.Position = new PointLatLng(51.31835, 0.873866);
The issue is, the control loads but there is no visible map inside. Does anyone know what i might need to do
Thanks
edit:
the fix was this
public Form1()
{
InitializeComponent();
SuspendLayout();
GMapControl MainMap = new GMapControl();
{
MainMap.MapProvider = GMapProviders.YahooMap;
MainMap.Position = new PointLatLng(54.6961334816182, 25.2985095977783);
MainMap.MinZoom = 1;
MainMap.MaxZoom = 17;
MainMap.Zoom = 9;
MainMap.Dock = DockStyle.Fill;
}
Controls.Add(MainMap);
ResumeLayout(true);
}

Categories

Resources