Hi,
I wanted to create a chartdrill application using your
example "ChartDrillDown_2017". For some reason, the chart doesn't
refresh / show the data needed after click through.
Only after I scroll with the mouse (zooming with the mouse is
enabled), the chart is instantly refreshed. I thought it might be a thread
issue, so I also tried it with invoke. (see commentated text).
What do I need to do, to make the switch of data be plotted to the charts immediately.
Furthermore: How can I specify a color for a series? I can only find the Palet
property in the chart control, but I cannot find anything to set a series to a
specific color manually / programmatically.
Please see the code below.
And a small question regarding your gridDataBoundGrid. Isn’t there an equivalent
for the default .net dataGridView component property AutoSizeColumnsMode (None,
ColumnHeader, AllCellsExceptHeader, AllCells….etc…)
Kind regards,
Matthijs
private bool _isDrilledDown=false;
private void chartControl1_ChartRegionClick(object sender, ChartRegionMouseEventArgs e)
{
if(_isDrilledDown)
{
FillChartWithCallsPerHour();
_isDrilledDown = false;
}
else
{
if(e.Region.IsChartPoint)
{
var a1 = e.Region.PointIndex;
var a2 = chartControl1.Series[0].Points[a1].X;
CreateDetailedUserActivity(a2);
_isDrilledDown = true;
}
}
}
private void FillChartWithCallsPerHour()
{
using(DirectMySQLConnectionObject conn = new DirectMySQLConnectionObject())
{
if(SpinWait.SpinUntil(() => conn.MayUseConnection, 5000))
{
// adding data to _callsPerHour
}
}
//this.chartControl1.SynchronizedInvoke(() =>
//{
try
{
this.chartControl1.Series.Clear();
Syncfusion.Windows.Forms.Chart.ChartSeries series = new Syncfusion.Windows.Forms.Chart.ChartSeries("API Calls");
series.Text = series.Name;
series.Type = ChartSeriesType.Column;
foreach(var item in _callsPerHour)
series.Points.Add(item.Key, item.Value);
chartControl1.ShowToolTips = false;
series.Style.Border.Width = 0;
series.Style.Border.Color = Color.Transparent;
chartControl1.Series.Add(series);
chartControl1.EnableXZooming = true;
chartControl1.EnableYZooming = false;
this.chartControl1.PrimaryXAxis.RangeType = ChartAxisRangeType.Set;
this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.DateTime;
this.chartControl1.PrimaryXAxis.DateTimeRange = new ChartDateTimeRange(_callsPerHour.Keys.Min(), _callsPerHour.Keys.Max(), 1, ChartDateTimeIntervalType.Days);
this.chartControl1.PrimaryXAxis.DateTimeFormat = "yyyy-MM-dd";
this.chartControl1.PrimaryXAxis.LabelAlignment = System.Drawing.StringAlignment.Center;
this.chartControl1.ZoomType = Syncfusion.Windows.Forms.Chart.ZoomType.MouseWheelZooming | Syncfusion.Windows.Forms.Chart.ZoomType.Selection;
this.chartControl1.PrimaryXAxis.GridLineType.ForeColor = Color.LightGray;
this.chartControl1.PrimaryYAxis.RangeType = ChartAxisRangeType.Set;
this.chartControl1.PrimaryYAxis.Range = new MinMaxInfo(0, _callsPerHour.Values.Max() + 100, 100);
this.chartControl1.PrimaryYAxis.Range.Interval = GetInterval(this.chartControl1.PrimaryYAxis.Range.Min, this.chartControl1.PrimaryYAxis.Range.Max);
this.chartControl1.PrimaryYAxis.GridLineType.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
this.chartControl1.PrimaryYAxis.GridLineType.ForeColor = Color.LightGray;
this.chartControl1.ForeColor = System.Drawing.SystemColors.ControlText;
chartControl1.Refresh();
gridDataBoundGrid1.DataSource = _callsPerHour.Select(row => new { CallDateTime = row.Key.ToString("dd-MM-yyyy HH:mm"), Count = (int)row.Value }).ToList();
this.gridDataBoundGrid1.AllowResizeToFit = true;
}
catch(Exception ex)
{
ex = ex;
}
//});
}
private void CreateDetailedUserActivity(double a2)
{
DateTime a3 = DateTime.FromOADate(a2);
using(DirectMySQLConnectionObject conn = new DirectMySQLConnectionObject())
{
if(SpinWait.SpinUntil(() => conn.MayUseConnection, 5000))
{
//add data to _callsPerUserInSpecificHour
}
}
//this.chartControl1.SynchronizedInvoke(() => {
try
{
//chartControl1.Series.Clear();
Syncfusion.Windows.Forms.Chart.ChartSeries series = new Syncfusion.Windows.Forms.Chart.ChartSeries("API Calls per user");
series.Name = "Calls/Hour";
series.Text = series.Name;
foreach(var item in _callsPerUserInSpecificHour.OrderByDescending(row => row.Key))
series.Points.Add(item.Value, item.Key);
series.Style.TextOrientation = ChartTextOrientation.RegionCenter;
chartControl1.ShowToolTips = false;
series.Style.Border.Width = 0;
series.Style.Border.Color = Color.Transparent;
this.chartControl1.Series.Clear();
chartControl1.Series.Add(series);
this.chartControl1.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
chartControl1.EnableXZooming = true;
chartControl1.EnableYZooming = false;
series.Type = ChartSeriesType.Column;
this.chartControl1.PrimaryXAxis.RangeType = ChartAxisRangeType.Set;
this.chartControl1.ZoomType = Syncfusion.Windows.Forms.Chart.ZoomType.MouseWheelZooming | Syncfusion.Windows.Forms.Chart.ZoomType.Selection;
this.chartControl1.PrimaryXAxis.GridLineType.ForeColor = Color.LightGray;
this.chartControl1.PrimaryXAxis.ResetZoom();
this.chartControl1.PrimaryYAxis.RangeType = ChartAxisRangeType.Set;
this.chartControl1.PrimaryYAxis.Range = new MinMaxInfo(0, _callsPerUserInSpecificHour.Keys.Max() + 100, 100);
this.chartControl1.PrimaryYAxis.Range.Interval = GetInterval(this.chartControl1.PrimaryYAxis.Range.Min, this.chartControl1.PrimaryYAxis.Range.Max);
this.chartControl1.PrimaryYAxis.GridLineType.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
this.chartControl1.PrimaryYAxis.GridLineType.ForeColor = Color.LightGray;
chartControl1.Redraw(true);
chartControl1.Refresh();
}
catch(Exception ex)
{
ex = ex;
throw;
}
//});
}
public static class Extensions
{
public static void SynchronizedInvoke(this ISynchronizeInvoke sync, Action action)
{
if(!sync.InvokeRequired)
{
action();
return;
}
sync.BeginInvoke(action, new object[] { });
}
}
ChartSeries series1 = new ChartSeries("Market");
series1.Style.Interior = new BrushInfo(Color.Red); |
this. gridDataBoundGrid1.AllowProportionalColumnSizing = true; |
this. gridDataBoundGrid1.AllowProportionalColumnSizing = false;
//Fit the row heights based on the content
this.gridDataBoundGrid1.Model.RowHeights.ResizeToFit(GridRangeInfo.Table());
//Fit the column width based on the content
this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Table()); |
Hi Sanjith,