We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Chart not updating after new series and new x-axis type

Thread ID:

Created:

Updated:

Platform:

Replies:

131145 Jun 23,2017 08:23 AM Jun 27,2017 03:07 AM Windows Forms 3
loading
Tags: Chart
Matthijs de Zwart
Asked On June 23, 2017 08:23 AM

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[] { });

        }

}



Sanjith Kesavan [Syncfusion]
Replied On June 26, 2017 02:21 AM

Hi Matthijs, 

Thanks for contacting Syncfusion support. Please find the response for your queries below. 

Query1: I wanted to create a chart drill application using your example "ChartDrillDown_2017". For some reason, the chart doesn't refresh / show the data needed after click through.  

Answer: We have confirmed this as issue, and we have logged bug report on this. Also, we have created branch incident under your account for better follow up. 

Query2: 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.  
 
Answer: For setting series color programmatically, please follow the below code.  

[C#] 
ChartSeries series1 = new ChartSeries("Market"); 
series1.Style.Interior = new BrushInfo(Color.Red); 
 

Now the series will render in red color. Please find the below screenshot. 

 

Query3: Isn’t there an equivalent for the default .net dataGridView component property AutoSizeColumnsMode (None, ColumnHeader, AllCellsExceptHeader, AllCells….etc…) 
 
Answer: By default, GridDataBoundGrid does have the support like DataGridView.AutoSizeColumnsMode property. In order to proportionally fit the columns content in the control, you can use the AllowProportionalColumnSizing property. Please refer to the below code example,  
 
Code example  
this. gridDataBoundGrid1.AllowProportionalColumnSizing = true;  
 
  
If you want to fit the Rows/Columns based on the content, you can use the ResizeToFit method before that you should disable theAllowProportionalColumnSizing property. Please refer to the below code example,  
  
Code example  
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());  
 


Please let us know if you have any concern. 

Thanks, 
Sanjith. 


Matthijs de Zwart
Replied On June 26, 2017 07:39 AM

Hi Sanjith,


Thanks for helping out.
Regards,

Matthijs

Sanjith Kesavan [Syncfusion]
Replied On June 27, 2017 03:07 AM

Hi Matthijs, 
 
Thanks for your update. Please let us know if need any further assistance on this. 
 
Thanks, 
Sanjith. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;