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.
Related
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
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.
Is there ANY ways possible to manipulate, maybe even override the way the candlestick charts are colored?
What I'm trying to do, should look like this:
What happens here, is that the candles are filled with its color when the "Open" prices are higher than "Close" prices, and black when it's the other way around.
But this isn't possible in MS Chart? I was thinking about creating another candlestick series on top of the other, and get filled boxes from that, but it wouldn't work, since MS Chart automatically uses the "PriceDown/Up" colors. ...See my answer below.
Here's the code I use and which doesn't work the way I would like to:
DataPointCollection dpcCandle = Series[Candle].Points;
DataPointCollection dpcPrice = Series[Price].Points;
int candleCount = dpcCandle.Count;
dpcCandle.AddXY(time, high);
dpcCandle[candleCount].YValues[1] = low;
dpcCandle[candleCount].YValues[2] = open;
dpcCandle[candleCount].YValues[3] = close;
if( candleCount > 1 )
{
Color col;
float oldClose = (float)dpcCandle[candleCount-1].YValues[3];
float oldOpen = (float)dpcCandle[candleCount-1].YValues[2];
dpcCandle[candleCount].BorderWidth = 1;
// Determine color
if( oldClose <= close) // Price up!
col = Color.ForestGreen;
else // Price down...
col = Color.Red;
// Determine fill
if( open < close )
{
dpcCandle[candleCount].Color = Color.Black;
dpcCandle[candleCount].BorderColor = col;
}
else
{
dpcCandle[candleCount].Color = col;
dpcCandle[candleCount].BorderColor = col;
}
if( oldOpen.Equals(close) )
{
dpcCandle[candleCount].Color = dpcCandle[candleCount-1].Color;
dpcCandle[candleCount].BorderColor = dpcCandle[candleCount-1].BorderColor;
}
}
Well, it works, but the result looks like this:
...with these settings:
Series[Candle]["PriceUpColor"] = "Black";
Series[Candle]["PriceDownColor"] = "Black";
And when I change those to these:
Series[Candle]["PriceUpColor"] = "ForestGreen";
Series[Candle]["PriceDownColor"] = "Red";
...I get this ugly mess for a result:
Thanks in advance.
Ok, so I was able to do workaround which includes a total of three two Candlestick Serieses... It's kinda ugly, but it does what I wanted.
The setup:
// ****************************
// Candlestick setup
Series[Candle].ChartType = SeriesChartType.Candlestick;
Series[Candle]["OpenCloseStyle"] = "Triangle";
Series[Candle]["ShowOpenClose"] = "Both";
Series[Candle]["PriceUpColor"] = "Black";
Series[Candle]["PriceDownColor"] = "Black";
Series[Candle]["PointWidth"] = "0.75";
Series[CandleGreen].ChartType = SeriesChartType.Candlestick;
Series[CandleGreen]["OpenCloseStyle"] = "Triangle";
Series[CandleGreen]["ShowOpenClose"] = "Both";
Series[CandleGreen]["PriceUpColor"] = "ForestGreen";
Series[CandleGreen]["PriceDownColor"] = "Red";
Series[CandleGreen]["PointWidth"] = "0.75";
Series[CandleGreen].BorderColor = Color.Transparent;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Then I did this:
DataPointCollection dpcCandle = Series[Candle].Points;
DataPointCollection dpcCandleG = Series[CandleGreen].Points;
DataPointCollection dpcPrice = Series[Price].Points;
// Point count
int candleCount = dpcCandle.Count;
// Add the new point
dpcCandle.AddXY(time, high);
dpcCandle[candleCount].YValues[1] = low;
dpcCandle[candleCount].YValues[2] = open;
dpcCandle[candleCount].YValues[3] = close;
// Add the hacks...
int g = dpcCandleG.AddXY(dpcCandle[candleCount].XValue, 0);
dpcCandleG[g].YValues[1] = 0;
dpcCandleG[g].YValues[2] = 0;
dpcCandleG[g].YValues[3] = 0;
if( candleCount > 1 )
{
float oldClose = (float)dpcCandle[candleCount-1].YValues[3];
float oldOpen = (float)dpcCandle[candleCount-1].YValues[2];
dpcCandle[candleCount].BorderWidth = 1;
// Determine color
if( oldClose <= close) // Price up!
{
dpcCandle[candleCount].Color = Color.ForestGreen;
dpcCandle[candleCount].BorderColor = Color.ForestGreen;
}
else // Price down...
{
dpcCandle[candleCount].Color = Color.Red;
dpcCandle[candleCount].BorderColor = Color.Red;
}
// Determine fill
if( open > close )
{
if( dpcCandle[candleCount].Color == Color.Red )
{
dpcCandleG[g].YValues[2] = open;
dpcCandleG[g].YValues[3] = close;
}
else if( dpcCandle[candleCount].Color == Color.ForestGreen )
{
dpcCandleG[g].YValues[2] = close;
dpcCandleG[g].YValues[3] = open;
}
}
if( oldOpen.Equals(close) )
{
dpcCandle[candleCount].Color = dpcCandle[candleCount-1].Color;
dpcCandle[candleCount].BorderColor = dpcCandle[candleCount-1].BorderColor;
}
}
Result:
Setting PriceUpColor and PriceDownColor is necessary and correct. Why do you set any other colors?? All candle coloring should happen automatically!
If you want to style the vertical bar in a Series "price" of a Chart chart1 you can do it by setting the DataPoint.Color like this:
chart1.Series["price"].BorderWidth = 4;
foreach(DataPoint dp in chart1.Series["price"].Points)
{
dp.Color = (dp.YValues[2] > dp.YValues[3]) ? Color.CadetBlue : Color.Pink;
}
I took the code and the data from this post by zeFrenchy. Here is the result:
I added the loop after adding the data. But you can do it while adding points as well..
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;
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;