How do I display StringLabelValue? - c#

I'm use Teechart version .Net & VS2005.
X-axis of the graph type of date and time, Y-axis was added to the Point Series.
I want to show the StringLabelValue.
My Code :
private void GridPoint()
{
datatable dt_point = new datatable();
Steema.TeeChart.Styles.Points Pinpoint = new Steema.TeeChart.Styles.Points();
TChart1.Series.Add(Pinpoint);
Pinpoint.Pointer.Visible = false;
Pinpoint.Pointer.InflateMargins = false;
Pinpoint.Pointer.Transparency = 100;
Pinpoint.Pointer.Pen.Visible = false;
Pinpoint.Marks.Color = Color.White;
Pinpoint.Marks.Pen.Color = Color.White;
Pinpoint.Marks.Shadow.Visible = false;
Pinpoint.Marks.Visible = true;
Steema.TeeChart.Axis axis = new Steema.TeeChart.Axis();
TChart1.Axes.Custom.Add(axis);
axis.StartPosition = 9;
axis.EndPosition = 9;
axis.Labels.Items.Add(0, " ");
axis.Labels.Items.Add(2000, " ");
axis.Labels.Items[0].Visible = false;
axis.Labels.Items[1].Visible = false;
axis.Title.Caption = "";
axis.Title.Font.Color = Color.Black;
TChart1.Series[0].CustomVertAxis = axis;
TChart1.Series[0].Clear();
if (dt_Point.Columns.Count == 0)
{
dt_Point.Columns.Add("SetTime", typeof(DateTime));
dt_Point.Columns.Add("Value", typeof(int));
dt_Point.Columns.Add("Label", typeof(string));
}
DataRow row;
row = dt_Point.NewRow();
row["SetTime"] = "2012-08-02 18:14:24";
row["Value"] = 100;
row["Label"] = "Point";
dt_Point.Rows.Add(row);
TChart1.Series[0].XValues.DataMember = "SetTime";
TChart1.Series[0].YValues.DataMember = "Value";
TChart1.Series[0].DataMember = "Label";
TChart1.Series[0].DataSource = dt_Point;
}
show the Graph :
I want to show graph:

I recommend that you set XValues.DateTime to true and change the DateTimeFormat and Style of the Bottom Axis labels to achieve the result that you want:
//XValues as DateTimeValues.
Pinpoint.XValues.DateTime = true;
//Labels axes style and format
tChart1.Axes.Bottom.Labels.DateTimeFormat = "hh:mm:ss";
tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;

Related

Radgridview visual issue

I have problem displaying the columns correctly,
some columns have some gap in between
I wanted to attach a picture but I need 10 reputation points to post image
See picture link below!!
Here is my code:
private void UpdateProducts()
{
MyPharmacyDataContext db = new MyPharmacyDataContext();
int tabid = Convert.ToInt32(radRibbonBar1.SelectedCommandTab.Name);
var list = from g in db.OutOfStocks
where g.ListID == tabid
select new { g.ID, g.Product.CName, g.Required, g.Product.Price, g.Product.Disscount, g.Product.BuyPrice, g.TotalBuy, Stock = g.Product.Available + "," + g.Product.AvailableMid + "," + g.Product.AvailableSmall,g.Product.Supplier.Title };
if (list.Count() > 0)
{
radGridView1.SummaryRowsBottom.Clear();
radGridView1.Columns.Clear();
radGridView1.Visible = true;
radGridView1.TableElement.TableHeaderHeight = 60;
GridViewTextBoxColumn num = new GridViewTextBoxColumn();
num.MaxWidth = 50;
num.Name = "num";
num.HeaderText = "م";
num.DataType = typeof(int);
radGridView1.Columns.Add(num);
radGridView1.DataSource = list;
radGridView1.Columns[1].IsVisible = false;
radGridView1.Columns[2].Width = 350;
radGridView1.Columns[2].HeaderText = "اسم المنتج";
radGridView1.Columns[2].Name = "Name";
radGridView1.Columns[2].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[3].MaxWidth = 60;
radGridView1.Columns[3].HeaderText = "عدد";
radGridView1.Columns[3].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[3].Name = "Q";
radGridView1.Columns[4].MaxWidth = 90;
radGridView1.Columns[4].HeaderText = "السعر";
radGridView1.Columns[4].Name = "Price";
radGridView1.Columns[4].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[4].FormatString = "{0:G29}";
radGridView1.Columns[5].MaxWidth = 80;
radGridView1.Columns[5].HeaderText = "الخصم";
radGridView1.Columns[5].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[5].FormatString = "{0:G29}";
radGridView1.Columns[6].MaxWidth = 100;
radGridView1.Columns[6].HeaderText = "سعر\nالشراء";
radGridView1.Columns[6].Name = "BuyPice";
radGridView1.Columns[6].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[6].FormatString = "{0:G29}";
radGridView1.Columns[7].MaxWidth = 100;
radGridView1.Columns[7].HeaderText = "اجمالي\nالشراء";
radGridView1.Columns[7].Name = "TotalBuyPice";
radGridView1.Columns[7].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[7].FormatString = "{0:G29}";
radGridView1.Columns[8].MaxWidth = 80;
radGridView1.Columns[8].MinWidth = 80;
radGridView1.Columns[8].Name = "Stock";
radGridView1.Columns[8].HeaderText = "الرصيد";
radGridView1.Columns[8].TextAlignment = ContentAlignment.MiddleCenter;
radGridView1.Columns[9].MaxWidth = 100;
radGridView1.Columns[9].MinWidth = 100;
radGridView1.Columns[9].Name = "Supplier";
radGridView1.Columns[9].HeaderText = "افضل\nمورد";
radGridView1.Columns[9].TextAlignment = ContentAlignment.MiddleCenter;
GridViewCheckBoxColumn checkbox = new GridViewCheckBoxColumn();
checkbox.MaxWidth = 30;
checkbox.HeaderText = "";
checkbox.DataType = typeof(bool);
checkbox.Name = "Ordered";
radGridView1.Columns.Add(checkbox);
var allpro = from g in db.OutOfStocks
where g.ListID == tabid
select g;
foreach (OutOfStock p in allpro)
{
foreach (GridViewRowInfo row in radGridView1.Rows)
{
if ((int)row.Cells[1].Value == p.ID)
{
if (p.Ordered == 'y')
row.Cells["Ordered"].Value = true;
else
row.Cells["Ordered"].Value = false;
}
}
}
GridViewSummaryItem total = new GridViewSummaryItem("Name", "الاجمالي", GridAggregateFunction.Avg);
GridViewSummaryItem price = new GridViewSummaryItem();
price.Name = "Price";
price.AggregateExpression = "(Sum(Q*Price))";
price.FormatString = "{0:G29}";
// GridViewSummaryItem price = new GridViewSummaryItem("Price", "{0}", GridAggregateFunction.Sum);
GridViewSummaryItem buypice = new GridViewSummaryItem("TotalBuyPice", "{0:G29}", GridAggregateFunction.Sum);
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem(new GridViewSummaryItem[] { total, price, buypice });
radGridView1.SummaryRowsBottom.Add(summaryRowItem);
radGridView1.Focus();
}
else
{
radGridView1.Visible = false;
}
if (radGridView1.Rows.Count() > 0)
radGridView1.ChildRows.Last().IsCurrent = true;
}
Here is the pic
https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpa1/v/t34.0-12/10893575_742987025776952_423788280_n.jpg?efg=eyJpIjoidCJ9&oh=c69f42a8f47d6529f2b9d89ab2782711&oe=54A71C8A&gda=1420210517_66e1b08ccf9c00fd3dcff31e1854b3cc

Exclude xvalue in (3d) bar chart

I have the 3d bar chart below:
Was wondering if there's a way that I can exclude the 'Closed' and 'TOTALS' row in the chart?
Here's my code that generates this:
chtOverview.DataSource = dt;
var headercountries = new List<string>();
foreach (DataColumn dc in dt.Columns)
{
if (!(dc.ColumnName.ToLower().Contains("total") || dc.ColumnName.ToLower().Contains("status")))
{
headercountries.Add(dc.ColumnName);
chtOverview.Series.Add(new Series(dc.ColumnName));
}
}
chtOverview.Legends.Add(new Legend("Legend1"));
for (int i = 0; i < headercountries.Count; i++)
{
chtOverview.Series[i].ChartArea = "ChartArea1";
chtOverview.Series[i].ChartType = SeriesChartType.Column;
chtOverview.Series[i].IsValueShownAsLabel = true;
chtOverview.Series[i].Legend = "Legend1";
chtOverview.Series[i].XValueMember = "Case Status";
chtOverview.Series[i].YAxisType = AxisType.Primary;
chtOverview.Series[i].YValueMembers = headercountries[i];
}
chtOverview.DataBind();
Thanks for the help. :)
In the line where you declare the datasource:
chtOverview.DataSource = dt.Select("[Case Status] NOT IN ('Closed', 'TOTALS')");

Creating multiple chart in c#

for (int i = 0; i < 5; i += 1)
{
ShowReports(0);
}
private void ShowReports(int ComboID)
{
Graph.Series["Series1"].ChartType = SeriesChartType.Line;
Graph.Series["Series1"].BorderWidth = 2;
Graph.Series["Series1"].MarkerStyle = MarkerStyle.Circle;
Graph.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "dd-MMM-yyy";
Graph.ChartAreas["ChartArea1"].AxisX.Title = "Date";
Graph.ChartAreas["ChartArea1"].AxisY.Title = "Average Score (%) ";
Graph.ChartAreas["ChartArea1"].AxisY.Minimum = 0;
Graph.ChartAreas["ChartArea1"].AxisY.Maximum = 100;
Graph.ChartAreas["ChartArea1"].AxisY.Interval = 10;
Graph.Series["Series1"].ToolTip = "Date :#VALX Avg Score(%) :#VALY";
Graph.Titles.Add(dtReportDetails.Rows[0].ItemArray[1].ToString());
Graph.Titles.Add(SetGraphTitile());
Graph.Titles[0].Font = new System.Drawing.Font("Arial", 20);
Graph.Titles[0].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Font = new System.Drawing.Font("Arial", 13);
Graph.Titles[1].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Visible = false;
// Graph.Series[0].Points.AddXY(DateTime.Parse(dtReportDetails.Rows[0].ItemArray[4].ToString()), dtReportDetails.Rows[0].ItemArray[5].ToString());
Graph.Series[0].XValueMember = dtReportDetails.Rows[0].ItemArray[4].ToString();
Graph.Series[0].YValueMembers = dtReportDetails.Rows[0].ItemArray[5].ToString();
Graph.Series[0].MarkerStyle = MarkerStyle.Circle;
Graph.Legends.Add("Legend1");
Graph.Legends[0].Enabled = false;
Graph.Legends[0].Docking = Docking.Bottom;
Graph.Legends[0].Alignment = System.Drawing.StringAlignment.Center;
Graph.DataSource = dv;
Graph.DataBind();
}
else if (dtReportDetails.Rows[0].ItemArray[7].ToString() == "Bar")
{
Graph.Series["Series1"].ChartType = SeriesChartType.Column;
Graph.Series["Series1"].BorderWidth = 2;
//Graph.Series["Series1"].MarkerStyle = MarkerStyle.Circle;
//Graph.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "dd-MMM-yyy";
//Graph.ChartAreas["ChartArea1"].AxisX.Title = "Date";
//Graph.ChartAreas["ChartArea1"].AxisY.Title = "Average Score (%) ";
Graph.Series["Series1"].ToolTip = "(#VALX,#VALY)";
Graph.Titles.Add(dtReportDetails.Rows[0].ItemArray[1].ToString());
Graph.Titles.Add(SetGraphTitile());
Graph.Titles[0].Font = new System.Drawing.Font("Arial", 20);
Graph.Titles[0].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Font = new System.Drawing.Font("Arial", 13);
Graph.Titles[1].ForeColor = System.Drawing.Color.Black;
Graph.Titles[1].Visible = false;
Graph.ChartAreas["ChartArea1"].AxisX.Title = "Learning Domains";
Graph.ChartAreas["ChartArea1"].AxisY.Title = "Covered";
// Graph.Series[0].Points.AddXY(DateTime.Parse(dtReportDetails.Rows[0].ItemArray[4].ToString()), dtReportDetails.Rows[0].ItemArray[5].ToString());
Graph.Series[0].XValueMember = dtReportDetails.Rows[0].ItemArray[4].ToString();
Graph.Series[0].YValueMembers = dtReportDetails.Rows[0].ItemArray[5].ToString();
// Graph.Series[0].MarkerStyle = MarkerStyle.Circle;
Graph.Legends.Add("Legend1");
Graph.Legends[0].Enabled = false;
Graph.Legends[0].Docking = Docking.Bottom;
Graph.Legends[0].Alignment = System.Drawing.StringAlignment.Center;
Graph.DataSource = dv;
Graph.DataBind();
Random random = new Random();
foreach (var item in Graph.Series[0].Points)
{
System.Drawing.Color c = System.Drawing.Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
item.Color = c;
}
Graph.Series[0]["PointWidth"] = "0.2";
Graph.Series[0]["BarLabelStyle"] = "Center";
Graph.Series[0]["PixelPointDepth"] = "99";
Graph.Series[0]["DrawingStyle"] = "Cylinder";
}
This is my code for creating graph,for creating 1 graph i have no problem ,but creating more than one i will get error:A chart element with the name 'Legend1' already exists in the 'LegendCollection'.because i am creating same legends each time.So can you help to get rid of this problem.
Getting around the issue of the legend object name should be as simple as setting it via a string that takes your ComboID parameter into account.
string myLegendTitle = "Legend" + ComboID;
Graph.Legends.Add(myLegendTitle);
In order to create multiple charts - on the assumption you're using Microsoft Chart controls would look something like
for (int i = 0; i < 5; i += 1)
{
ShowReports(0);
}
private void ShowReports(int ComboID)
{
var myNewGraph = new System.Windows.Forms.DataVisualization.Charting.Chart();
myNewGraph .Series["Series1"].ChartType = SeriesChartType.Line;
myNewGraph .Series["Series1"].BorderWidth = 2;
myParentControl.Controls.Add(myNewGraph);
}
The key points being to instantiate a new Chart in your ShowReports method, then set all the properties specifically as before BUT on the new graph / chart object. Then ensure you add the control to the appropriate container if it's not already there.
If you know you will have, for example, 5 charts, then another approach is to build them at design time instead, and use a switch approach to set your variable, eg.
private void ShowReports(int ComboID)
{
Chart myNewGraph;
switch (ComboID)
{
case 1:
myNewGraph = Graph1;
break;
}
myNewGraph .Series["Series1"].ChartType = SeriesChartType.Line;
myNewGraph .Series["Series1"].BorderWidth = 2;
}
Is the code for create 5 graphs..
for(int i=0;i< 6;i++)
{
Chart1.Series.Add("Series1" + t.ToString());
Chart1.ChartAreas.Add("ChartArea1" + t.ToString());
Chart1.Legends.Add("Legend1" + t.ToString());
Chart1.Series[t].ChartArea = "ChartArea1" + t.ToString();
Chart1.Series[t].ChartType = SeriesChartType.Column;
Chart1.Series[t].BorderWidth = 2;
Chart1.Series[t].ToolTip = "(#VALX,#VALY)";
Chart1.ChartAreas["ChartArea1" + t.ToString()].AxisX.Title = "Learning Domains";
Chart1.ChartAreas["ChartArea1" + t.ToString()].AxisY.Title = "Covered";
}

Issues using 2 axis labels with RadBarChart and no Gap between bars

I have 2 problems:
I want the names from the datatable but it is showing me in numeric form.
I would like a gap between the two bars but I can't find a way.
Here is the code:
private void InitializeGraph (DataTable poDt)
{
Telerik.Charting.ChartSeries chartseries = new Telerik.Charting.ChartSeries();
try
{
chartseries.Type = Telerik.Charting.ChartSeriesType.Bar;
Telerik.Charting.ChartSeriesItem csItem;
RadChart1.PlotArea.XAxis.AutoScale = true;
RadChart1.PlotArea.XAxis.DataLabelsColumn = "Name";
for (int iRow = 0; iRow < poDt.Rows.Count; iRow++)
{
chartseries = new Telerik.Charting.ChartSeries();
chartseries.Type = Telerik.Charting.ChartSeriesType.Bar;
chartseries.Name = poDt.Rows[iRow]["Name"].ToString().Trim();
csItem = new Telerik.Charting.ChartSeriesItem();
csItem.Name = poDt.Rows[iRow]["Name"].ToString();
csItem.Label.TextBlock.Text = poDt.Rows[iRow]["Value"].ToString();
RadChart1.PlotArea.XAxis.Appearance.TextAppearance.AutoTextWrap = Telerik.Charting.Styles.AutoTextWrap.True;
csItem.YValue = Int32.Parse(poDt.Rows[iRow]["Value"].ToString());
chartseries.AddItem(csItem);
RadChart1.Series.Add(chartseries);
}
RadChart1.PlotArea.XAxis.AddRange(1, poDt.Rows.Count, 1);
RadChart1.PlotArea.XAxis[poDt.Rows.Count].TextBlock.Text = chartseries.Name;
poDt.Rows.Count.ToString();
RadChart1.PlotArea.XAxis.AutoShrink = false;
RadChart1.PlotArea.XAxis.AutoShrink = true;
RadChart1.Series.Add(chartseries);
RadChart1.PlotArea.Appearance.Border.Visible = false;
RadChart1.Appearance.Border.Visible = true;
RadChart1.PlotArea.YAxis.IsLogarithmic = true;
RadChart1.PlotArea.YAxis.AutoScale = true;
RadChart1.PlotArea.YAxis.Appearance.ValueFormat=Telerik.Charting.Styles.ChartValueFormat.Number;
RadChart1.Appearance.BarWidthPercent = 50;
RadChart1.Chart.Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
RadChart1.Chart.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;
RadChart1.Legend.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;
}
catch (Exception Ex)
{
//throw;
}
finally
{
poDt.Clear();
poDt = null;
chartseries = null;
}
}
Sorry, I do not believe there is a way to display two X-axis at the same time.
My suggestion is you use a CategoricalAxis for your X axis and create a custom bar chart that has a legend which differentiates the two values. I don't have any working samples, however you can use this Telerik Silverlight demo for starters.
Also, switch to RadChartView if you can. Because I would then suggest an easier approach, which is using a Categorical X-Axis and create multiple Y axes. If you go that route, you can do something like this for a DateTimeContinuous (or Categorical) X-axis with multiple Y-axes :
int count = 0;
LineSeries lineSeries = new LineSeries();
lineSeries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "TimeStamp" };
lineSeries.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Value" };
lineSeries.VerticalAxis = new LinearAxis()
{
Title = "Title Here"
};
lineSeries.ItemsSource = yourCollection.Values;
//First Y-axis to be placed on the left of X-axis,
//additional Y-axes to be placed on right
if (count > 0 )
{
lineSeries.VerticalAxis.HorizontalLocation = Telerik.Charting.AxisHorizontalLocation.Right;
}
count++;
chartName.Series.Add(lineSeries);
Hope this helps.

Why Doesn't MSChart Fill Entire Chart Area?

I am working on creating a couple of charts and I cannot figure out why there is so much empty space on the left and right side of the chart. I have a Winforms Chart, ChartArea, and Series and there is always a good inch to the left and right side of the chart that seems like wasted space. What setting do I need to change to reduce the size of this empty space? I have included a screenshot of the chart with empty space with this post as well as the code that I use to create it. Thanks in advance.
if (listBoxCharts.SelectedItems.Count == 1)
{
switch (listBoxCharts.SelectedItem.ToString().Trim())
{
case "Incomplete Work Orders By Status":
ChartArea chartArea = new ChartArea();
Series series = new Series();
Title title = new Title();
chartArea.Area3DStyle.Enable3D = true;
chartArea.Area3DStyle.LightStyle = LightStyle.Realistic;
chartArea.Area3DStyle.Rotation = 10;
chartArea.Area3DStyle.WallWidth = 3;
chartArea.BorderColor = Color.Transparent;
chartArea.Name = "IncompleteWorkOrdersByStatus_ChartArea";
// Fix this hack
ChartContainer.ChartAreas.Clear();
this.ChartContainer.ChartAreas.Add(chartArea);
this.ChartContainer.Dock = DockStyle.Fill;
this.ChartContainer.Location = new Point(2, 21);
this.ChartContainer.Name = "Charts";
this.ChartContainer.PaletteCustomColors = new Color[] { Color.LemonChiffon };
series.ChartArea = "IncompleteWorkOrdersByStatus_ChartArea";
series.ChartType = SeriesChartType.StackedColumn;
series.CustomProperties = "DrawingStyle=Cylinder";
series.EmptyPointStyle.BorderDashStyle = ChartDashStyle.NotSet;
series.IsXValueIndexed = true;
series.Name = "IncompleteWorkOrdersByStatus_Series";
List<WorkOrder> incompleteWorkOrders = woDao.getIncompleteWorkOrders();
var uniqueStatuses = (
from statuses in incompleteWorkOrders
select statuses.fkOrderStatus).Distinct().ToList();
int xVal = 1;
foreach (var status in uniqueStatuses)
{
var count = (
from wo in incompleteWorkOrders
where wo.fkOrderStatus == status
select wo).Count();
DataPoint dPoint = new DataPoint(xVal, count);
if (status == null)
{
dPoint.AxisLabel = "No Status";
}
else
{
dPoint.AxisLabel = status.codedesc;
}
dPoint.ToolTip = count + " " + dPoint.AxisLabel;
series.Points.Add(dPoint);
xVal++;
}
this.ChartContainer.Series.Clear();
this.ChartContainer.Series.Add(series);
title.DockedToChartArea = "IncompleteWorkOrdersByStatus_ChartArea";
title.IsDockedInsideChartArea = false;
title.Name = "IncompleteWorkOrdersByStatus_Title";
title.Text = "Incomplete Work Orders By Status";
this.ChartContainer.Titles.Clear();
this.ChartContainer.Titles.Add(title);
break;
default:
break;
}
}
Try playing with the InnerPlotPosition settings:
chart1.ChartAreas[0].InnerPlotPosition.X = 0;

Categories

Resources