hi,
I am currently having a radgridview with 3 columns in which the 3rd column is a chart type custom column. i have set a minimum width to it which leads to scroll bar on smaller displays. Now , if i scroll across a few times the data in the chart disappears.
Is there any event where i can write code to prevent from happening ? Code below updated
public RadForm1()
{
InitializeComponent();
this.radGridView1.Columns.Add("Column1");
this.radGridView1.Columns.Add("Column2");
ChartColumn customColumn = new ChartColumn("Chart column");
this.radGridView1.Columns.Add(customColumn);
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
for (int i = 0; i < 10; i++)
{
this.radGridView1.Rows.Add(i, i, i);
}
this.radGridView1.TableElement.RowHeight = 200;
this.radGridView1.AllowAddNewRow = false;
}
public class ChartCell : GridDataCellElement
{
public ChartCell(GridViewColumn column, GridRowElement row) : base(column, row)
{
}
RadChartElement chart = new RadChartElement();
protected override void CreateChildElements()
{
base.CreateChildElements();
LoadBarChart();
this.Children.Add(chart);
}
private void LoadBarChart()
{
chart.View.AreaType = ChartAreaType.Cartesian;
chart.AngleTransform = 90;
RangeBarSeries rangeBarSeries = new RangeBarSeries("End Time", "Start Time", "Summarization Date");
rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 14, DateTime.Now.TimeOfDay.TotalMinutes + 10, "6/8/2021"));
rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 7, DateTime.Now.TimeOfDay.TotalMinutes + 5, "6/8/2021"));
rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 4, DateTime.Now.TimeOfDay.TotalMinutes + 2, "6/8/2021"));
rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 30, DateTime.Now.TimeOfDay.TotalMinutes + 10, "6/7/2021"));
rangeBarSeries.DataPoints.Add(new RangeDataPoint(DateTime.Now.TimeOfDay.TotalMinutes + 7, DateTime.Now.TimeOfDay.TotalMinutes + 5, "6/7/2021"));
CategoricalAxis horizontalAxis = new CategoricalAxis();
//horizontalAxis.Title = "Summarization Days";
horizontalAxis.ClipLabels = false;
horizontalAxis.LabelRotationAngle = -90;
horizontalAxis.LabelFitMode = AxisLabelFitMode.Rotate;
horizontalAxis.PlotMode = AxisPlotMode.BetweenTicks;
rangeBarSeries.HorizontalAxis = horizontalAxis;
chart.View.Series.Add(rangeBarSeries);
rangeBarSeries.VerticalAxis.LabelFormatProvider = new MyFormatProvider();
//rangeBarSeries.VerticalAxis.Title = "Time of the day";
rangeBarSeries.VerticalAxis.ClipLabels = false;
rangeBarSeries.VerticalAxis.LabelRotationAngle = -45;
rangeBarSeries.VerticalAxis.LabelFitMode = AxisLabelFitMode.Rotate;
LinearAxis verticalAxis = chart.View.Axes.Get<LinearAxis>(1);
verticalAxis.Minimum = 0; //Minutes 0:00
verticalAxis.Maximum = 1380; //Minutes 23:00
verticalAxis.MajorStep = 60; //60 minutes in an hour
CartesianArea area = chart.View.GetArea<CartesianArea>();
area.ShowGrid = true;
CartesianGrid grid = area.GetGrid<CartesianGrid>();
grid.DrawVerticalStripes = true;
grid.DrawHorizontalStripes = false;
}
protected override void SetContentCore(object value)
{
base.SetContentCore(value);
//you can synchronize the chart data points according to the cell value if necessary
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataCellElement);
}
}
public override bool IsCompatible(GridViewColumn data, object context)
{
return data is ChartColumn && context is GridDataRowElement;
}
}
public class ChartColumn : GridViewDataColumn
{
public ChartColumn(string fieldName) : base(fieldName)
{
}
public override Type GetCellType(GridViewRowInfo row)
{
if (row is GridViewDataRowInfo)
{
return typeof(ChartCell);
}
return base.GetCellType(row);
}
}
public class MyFormatProvider : IFormatProvider, ICustomFormatter
{
public object GetFormat(Type formatType)
{
return this;
}
public string Format(string format, object arg, IFormatProvider formatProvider)
{
int totalminutes = Convert.ToInt32(arg);
TimeSpan timeSpan = TimeSpan.FromMinutes(totalminutes);
return timeSpan.ToString(@"hh\:mm");
}
}