Xamarin.iOS iOS-Charts: Bar Chart not showing bars - c#

I'm using iOSCharts in project to draw bar chart. There's no official documentations available for iOSCharts and on the github page it says all the api's are same as MPAndroidChart plot. I followed everything I used to do in the android, but bars of the bar chart are not showing. The entire chart takes up the color of the bars
This is how it's showing..
BarChartView barChart = new BarChartView();
ChartXAxis xAxis = barChart.XAxis;
xAxis.LabelPosition = XAxisLabelPosition.Bottom;
xAxis.DrawGridLinesEnabled = false;
xAxis.AxisLineColor = UIColor.Clear.FromHexString("#DEDEDE");
barChart.RightAxis.Enabled = false;
barChart.LeftAxis.DrawAxisLineEnabled = false;
barChart.LeftAxis.GridColor = UIColor.Clear.FromHexString("#DEDEDE");
barChart.LeftAxis.StartAtZeroEnabled = false;
barChart.Legend.Enabled = false;
barChart.LeftAxis.LabelCount = 5;
barChart.BackgroundColor = UIColor.Clear.FromHexString("#FFFFFF");
barChart.GridBackgroundColor = UIColor.Clear.FromHexString("FFFFFF");
barChart.SetDescriptionText("");
barChart.MoveViewToX(7);
VitalGraph vGraph = ..............
barChart.SetData(GetBarData(vGraph.vitalId, vGraph));
barChart.Frame = measurementsChartContainer.Frame;
measurementsChartContainer.AddSubview(barChart);
private BarChartData GetBarData(int vitalId, VitalGraph vGraph)
{
List<float> valueList = vGraph.valueList.Select(x => float.Parse(x)).ToList();
UIColor[] colorList = new UIColor[vGraph.colorList.Count];
for (int i = 0; i < vGraph.colorList.Count; i++)
colorList[i] = UIColor.Clear.FromHexString(vGraph.colorList[i]);
BarChartDataEntry[] entries = new BarChartDataEntry[7];
for (int i = 0; i < valueList.Count; i++)
{
entries[i] = new BarChartDataEntry(valueList[i], i);
}
//barChart.MoveViewToX(valueList.Count)
BarChartDataSet barDataSet = new BarChartDataSet(entries, "Vital Reading");
barDataSet.BarSpace = 40f;
NSString[] dayList = new NSString[vGraph.dayList.Count];
for (int i = 0; i < vGraph.dayList.Count; i++)
dayList[i] = new NSString(vGraph.dayList[i]);
List<IBarChartDataSet> dataList = new List<IBarChartDataSet>();
dataList.Add(barDataSet);
BarChartData barData = new BarChartData(dayList, dataList.ToArray());
//barDataSet.SetColors(colorList);
return barData;
}
I had no trouble using MPAndroidChart in Xamarin.Drioid. Am I something wrong here?

BarChartDataSet yDataSet = new BarChartDataSet (barEntry, barChartModel.dataSetLegend [i]);
yDataSet.SetColor(UIColor.Red);
Hope it helps you.

Related

Select block on the drawings with C# using DraftSight API

I need to select a specific block/border on the drawing and print that block/border as a PDF. I can find border by name but I can not take border coordination or at least one point to select the border and then print only that border. I will insert a code snippet that I have. It's messy - in development. Not familiar with DraftSight and DraftSight API.
I'm sure it's several different ways to do it.
Any help will be appreciated.
public static void BlockSelection()
{
DraftSight.Interop.dsAutomation.Application dsApp;
Document dsDoc = default(Document);
PrintManager dsPrintMgr = null;
//Connect to DraftSight application
dsApp = (DraftSight.Interop.dsAutomation.Application)Marshal.GetActiveObject("DraftSight.Application");
dsApp.AbortRunningCommand(); // abort any command currently running in DraftSight to avoid nested commands
//Get active document
dsPrintMgr = dsApp.GetPrintManager();
dsDoc = (Document)dsApp.GetActiveDocument();
object[] dsVarBlkDefinitions = null;
BlockDefinition dsBlkDefinition = default(BlockDefinition);
object[] dsBlock = null;
DraftSight.Interop.dsAutomation.Viewport dsViewport = default(DraftSight.Interop.dsAutomation.Viewport);
MathUtility dsMathUtility = default(MathUtility);
MathPoint startCorner = default(MathPoint);
MathPoint oppositeCorner = default(MathPoint);
Model dsModel = default(Model);
SketchManager dsSketchManeger = default(SketchManager);
ViewManager dsViewManager = default(ViewManager);
object[] dsSheets = null;
Sheet dsSheet = default(Sheet);
string SheetName = null;
int count = 0;
string blockName = "BLOCK1";
string outputFileLocationName = $#"C:\\TestOutput\\fileName";
//Get all Block definitions in the drawing
dsVarBlkDefinitions = (object[])dsDoc.GetBlockDefinitions();
dsBlock = new object[dsVarBlkDefinitions.Length];
for (int index = 0; index < dsVarBlkDefinitions.Length; index++)
{
for (index = dsVarBlkDefinitions.GetLowerBound(0); index <= dsVarBlkDefinitions.GetUpperBound(0); index++)
{
dsBlkDefinition = (BlockDefinition)dsVarBlkDefinitions[index];
var name = dsBlkDefinition.GetName();
Debug.Print($#"Block name: {name}");
// found block that I need to select and print
if (dsBlkDefinition.GetName().Contains(blockName))
{
object[] blocks = dsBlkDefinition.GetBlockInstances();
SelectionManager dsSelectionManager = dsDoc.GetSelectionManager();
SelectionFilter dsSelectionFilter = dsSelectionManager.GetSelectionFilter();
dsSelectionFilter.Clear();
dsSelectionFilter.AddEntityType(dsObjectType_e.dsBlockInstanceType);
dsSelectionFilter.Active = true;
dsSelectionManager.ClearSelections(dsSelectionSetType_e.dsSelectionSetType_Previous);
//if (dsCommandMessage.PromptForSelection(true, "Select dynamic block", errorMessage)) //
count = 0;
count = dsSelectionManager.GetSelectedObjectCount(dsSelectionSetType_e.dsSelectionSetType_Previous);
dsObjectType_e entityType = dsObjectType_e.dsObjectUndefinedType;
//object selObject = dsSelectionManager.GetSelectedObject(dsSelectionSetType_e.dsSelectionSetType_Previous, index, out entityType);
// tried to find any point of the block - not sure how to do that..
MathPoint point = ;
// Pathing that point into the SelectByPoint method.
object selObject = dsSelectionManager.SelectByPoint(point);
BlockInstance dsBlockInstance = selObject as BlockInstance;
// Printer set up
double top = .25;
double bottom = .25;
double left = .25;
double right = .25;
/////dsPrintMgr.PaperSize = "ANSI_A_(8.50_x_11.00_Inches)"; //this overrides the paper size of "Letter" DO NOT USE FOR NITRO
dsPrintMgr.PaperSize = "Letter";
dsPrintMgr.Quality = 4000;
dsPrintMgr.PrintOnCenter = true;
dsPrintMgr.PrintInBackground = true;
dsPrintMgr.ScaleLineWeight = false;
dsPrintMgr.UseAssignedLineWeight = false;
dsPrintMgr.StyleTable = "monochrome.ctb";
dsPrintMgr.SetPrintRange(dsPrintRange_e.dsPrintRange_SpecifyWindow, "", true, 0D, 0D, 0D, 0D);
dsPrintMgr.ScaleToFit = true;
dsPrintMgr.SetPrintMargins(top, bottom, left, right);
dsPrintMgr.PrintOut(1, outputFileLocationName);
// end of printer set up
}
}
}
}// end of BlockSelection method

How can i use a variable in a for loop in a command ? (c#)

So i have a matrix of buttons, from a1f to a10f and from a to j, so a1f is on the top left and j10 is on the buttom right.
I want to to something like this:
for (i = 1; i < 11; i++)
{
a{i}f.BackgroundImage = Properties.Resources._1mal2_1_Rebellion;
b{i}f.BackgroundImage = Properties.Resources._1mal2_2_Rebellion;
a{i}f.Enabled = false;
a{i}f.Tag = "playerShip";
b{i}f.Enabled = false;
b{i}f.Tag = "playerShip";
}
so the first loop would be:
a1f.BackgroundImage = Properties.Resources._1mal2_1_Rebellion;
b1f.BackgroundImage = Properties.Resources._1mal2_2_Rebellion;
a1f.Enabled = false;
a1f.Tag = "playerShip";
b1f.Enabled = false;
b1f.Tag = "playerShip";
the second would be:
a2f.BackgroundImage = Properties.Resources._1mal2_1_Rebellion;
b2f.BackgroundImage = Properties.Resources._1mal2_2_Rebellion;
a2f.Enabled = false;
a2f.Tag = "playerShip";
b2f.Enabled = false;
b2f.Tag = "playerShip";
and so on..
a{i}f or a[i]f isnt working.
If you can't iterate the controls, you could store them in a temp array.
But you would probably better doing by generating the controls. It might be the next level for improvement. For now, you could try this:
For example:
// create arrays which contains the controls.
var aShips = new [] { a1f, a2f, a3f, a4f, a5f, a6f, a7f, a8f, a9f, a10f };
var bShips = new [] { b1f, b2f, b3f, b4f, b5f, b6f, b7f, b8f, b9f, b10f };
// notice the 0 and the < 10, because arrays are zero-indexed
for (i = 0; i < 10; i++)
{
// now you can access them via the array.
aShips[i].BackgroundImage = Properties.Resources._1mal2_1_Rebellion;
aShips[i].Enabled = false;
aShips[i].Tag = "playerShip";
bShips[i].BackgroundImage = Properties.Resources._1mal2_2_Rebellion;
bShips[i].Enabled = false;
bShips[i].Tag = "playerShip";
}

The call is ambiguous between the following methods when I want use a class

I defined a class in my ASP.NET webform page:
namespace AdsignInt_V0._2.AdvertiserZone.ChartReports
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<string> XAxisItems = new List<string>();
XAxisItems.Add("Monday");
XAxisItems.Add("Tuesday");
XAxisItems.Add("Wednesday");
XAxisItems.Add("Thursday");
XAxisItems.Add("Friday");
XAxisItems.Add("Saturday");
XAxisItems.Add("Sunday");
SeriesItem series1 = new SeriesItem("Week 1", Color.Red);
for (int i = 1; i < 8; i++)
series1.Items.Add(i * 10);
SeriesItem series2 = new SeriesItem("Week 2", Color.Blue);
for (int i = 1; i < 8; i++)
series2.Items.Add(100 - i * 10);
List<SeriesItem> SeriesItems = new List<SeriesItem>();
SeriesItems.Add(series1);
SeriesItems.Add(series2);
makeChart(XAxisItems, SeriesItems);
}
void makeChart(List<string> XAxisItems, List<SeriesItem> SeriesItems)
{
MyChart.Appearance.FillStyle.BackgroundColor = Color.White;
MyChart.ChartTitle.Text = "Server CPU Load By Days";
MyChart.ChartTitle.Appearance.Align = ChartTitleAlign.Center;
MyChart.ChartTitle.Appearance.BackgroundColor = Color.White;
MyChart.ChartTitle.Appearance.Position = ChartTitlePosition.Top;
MyChart.Legend.Appearance.BackgroundColor = Color.White;
MyChart.Legend.Appearance.Position = ChartLegendPosition.Bottom;
MyChart.PlotArea.Appearance.FillStyle.BackgroundColor = Color.White;
{ //XAxis
MyChart.PlotArea.XAxis.AxisCrossingValue = 0;
MyChart.PlotArea.XAxis.Color = Color.Black;
MyChart.PlotArea.XAxis.MajorTickType = TickType.Outside;
MyChart.PlotArea.XAxis.MinorTickType = TickType.Outside;
MyChart.PlotArea.XAxis.Reversed = false;
MyChart.PlotArea.XAxis.LabelsAppearance.DataFormatString = "{0}";
MyChart.PlotArea.XAxis.LabelsAppearance.RotationAngle = 0;
MyChart.PlotArea.XAxis.LabelsAppearance.Skip = 0;
MyChart.PlotArea.XAxis.LabelsAppearance.Step = 1;
MyChart.PlotArea.XAxis.MajorGridLines.Color = Color.Gray;
MyChart.PlotArea.XAxis.MinorGridLines.Color = Color.Gray;
MyChart.PlotArea.XAxis.TitleAppearance.Text = "Days";
MyChart.PlotArea.XAxis.TitleAppearance.Position = AxisTitlePosition.Center;
MyChart.PlotArea.XAxis.TitleAppearance.RotationAngle = 0;
foreach (string item in XAxisItems)
MyChart.PlotArea.XAxis.Items.Add(item);
}
{ //YAxis
MyChart.PlotArea.YAxis.MinValue = 0;
MyChart.PlotArea.YAxis.MaxValue = 100;
MyChart.PlotArea.YAxis.Step = 25;
MyChart.PlotArea.YAxis.AxisCrossingValue = 0;
MyChart.PlotArea.YAxis.Color = Color.Black;
MyChart.PlotArea.YAxis.MajorTickType = TickType.Outside;
MyChart.PlotArea.YAxis.MinorTickType = TickType.Outside;
MyChart.PlotArea.YAxis.Reversed = false;
MyChart.PlotArea.YAxis.LabelsAppearance.DataFormatString = "{0}%";
MyChart.PlotArea.YAxis.LabelsAppearance.RotationAngle = 0;
MyChart.PlotArea.YAxis.LabelsAppearance.Skip = 0;
MyChart.PlotArea.YAxis.LabelsAppearance.Step = 1;
MyChart.PlotArea.YAxis.MajorGridLines.Color = Color.Gray;
MyChart.PlotArea.YAxis.MinorGridLines.Color = Color.Gray;
MyChart.PlotArea.YAxis.TitleAppearance.Text = "CPU Load";
MyChart.PlotArea.YAxis.TitleAppearance.Position = AxisTitlePosition.Center;
MyChart.PlotArea.YAxis.TitleAppearance.RotationAngle = 0;
}
foreach (SeriesItem seriesItem in SeriesItems)
{
LineSeries lineSeries = new LineSeries();
lineSeries.Name = seriesItem.name;
lineSeries.Appearance.FillStyle.BackgroundColor = seriesItem.backgroundColor;
lineSeries.LabelsAppearance.DataFormatString = seriesItem.dataFormatString;
lineSeries.LabelsAppearance.Position = seriesItem.position;
lineSeries.LineAppearance.Width = seriesItem.lineWidth;
lineSeries.MarkersAppearance.BackgroundColor = seriesItem.markerBackgroundColor;
lineSeries.MarkersAppearance.MarkersType = seriesItem.markerType;
lineSeries.MarkersAppearance.Size = seriesItem.markerSize;
lineSeries.MarkersAppearance.BorderColor = seriesItem.markerBorderColor;
lineSeries.TooltipsAppearance.BackgroundColor = seriesItem.tooltipBackgroundColor;
lineSeries.TooltipsAppearance.DataFormatString = seriesItem.tooltipDataFormatString;
foreach (decimal value in seriesItem.Items)
lineSeries.Items.Add(value);
MyChart.PlotArea.Series.Add(lineSeries);
}
}
}
public class SeriesItem
{
public string name;
public Color backgroundColor;
public string dataFormatString;
public LineAndScatterLabelsPosition position;
public int lineWidth;
public Color markerBackgroundColor;
public MarkersType markerType;
public int markerSize;
public Color markerBorderColor;
public Color tooltipBackgroundColor;
public string tooltipDataFormatString;
public List<decimal> Items;
public SeriesItem(string Name, Color color)
{
name = Name;
backgroundColor = color;
dataFormatString = "{0}%";
position = LineAndScatterLabelsPosition.Above;
lineWidth = 1;
markerBackgroundColor = Color.Yellow;
markerType = MarkersType.Circle;
markerSize = 8;
markerBorderColor = Color.Green;
tooltipBackgroundColor = Color.White;
tooltipDataFormatString = "{0}%";
Items = new List<decimal>();
}
}
}
But when I want to use a method from the class, I have an error that says to me:
The call is ambiguous between the following methods or properties:
AdsignInt_V0._2.AdvertiserZone.ChartReports.SeriesItem.SeriesItem(string, System.Drawing.Color)
and
AdsignInt_V0._2.AdvertiserZone.ChartReports.SeriesItem.SeriesItem(string, System.Drawing.Color)
C:\Users\my media\Documents\Visual Studio 2013\Projects\AdsignInt_V0.2\AdsignInt_V0.2\AdvertiserZone\ChartReports\WebForm1.aspx.cs 27 34 AdsignInt_V0.2
Try cleaning the solution and the temporary ASP files, then rebuild. Most likely, the last build has assemblies that point to the same class name.
Also, the SeriesItem class is the old class that used to define RadHtmlChart series items, so you may want to change its name to avoid any conflicts. The current classes for series items are listed here: http://www.telerik.com/help/aspnet-ajax/htmlchart-server-side-api-configure-series-items.html.
On a side note - I do not think you need a new series for each series item, so you may want to put the foreach loop for the series items after the series creation.
I define de System.Drawing in top.
using Draw = System.Drawing;
After if I need use System.Drawing I use it with Draw.
Sample:
public SeriesItem(string Name, Draw.Color color)
{
name = Name;
backgroundColor = color;
dataFormatString = "{0}%";
position = LineAndScatterLabelsPosition.Above;
lineWidth = 1;
markerBackgroundColor = Draw.Color.Yellow;
markerType = MarkersType.Circle;
markerSize = 8;
markerBorderColor = Draw.Color.Green;
tooltipBackgroundColor = Draw.Color.White;
tooltipDataFormatString = "{0}%";
Items = new List<decimal>();
}

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.

Categories

Resources