Jump to content
Software FX Community

Problem with embedding a line chart in a data grid column


amanax
 Share

Recommended Posts

Hi,

 

I need to expand an existing service watchingtool. This tool uses a datagrid to display information of severalservices. Each service contains a field for the actual CPU usage (inmore detail the past 60 values of the usage). I use these CPU usagevalues to draw a line chart in two different ways.

First way isto open a new window with the appropriate line chart when a doubleclick occurs on the appropriate data grid field. This works fine anddoesn't cause any problems.

Second way is to display a miniaturechart within the used grid. I've solved the problem to embed the chartin a seperate column.But here I've got a problem with the scaling of the graph. The points aren't drawn correctly scaled. What could be the problem?

Here is the code snipplet:

  public MyGridColumn(GridEX grid)   {   base.OwnerDrawnMode = ColumnOwnerDrawnMode.Cells;     // is called each time a cell is redrawn   grid.DrawGridArea += new DrawGridAreaEventHandler(GridEX_DrawGridArea);     chart_ = new Chart();   chart_.AxisX.Min = 1;   chart_.AxisX.Max = 30;   chart_.AxisX.Gridlines = false;   chart_.AxisX.Visible = false;   chart_.AxisY.Min = 1;   chart_.AxisY.Max = 100;   chart_.AxisY.Gridlines = false;   chart_.AxisY.Visible = false;   chart_.Gallery = Gallery.Lines;   chart_.MarkerShape = SoftwareFX.ChartFX.Lite.MarkerShape.None;   chart_.BorderStyle = System.Windows.Forms.BorderStyle.None;   chart_.LineStyle = System.Drawing.Drawing2D.DashStyle.Solid;   chart_.InsideColor = System.Drawing.Color.Black;   chart_.Visible = true;   chart_.Enabled = true;   chart_.AutoSize = false;     chart_.TopGap = 1;   chart_.LeftGap = 1;   chart_.RightGap = 1;   chart_.BottomGap = 1;   chart_.NSeries = 1;   chart_.NValues = 30;   chart_.ClearData(ClearDataFlag.Values);   chart_.Series[0].Color = Color.LightGreen;   chart_.Location = new Point(0, 0);   chart_.Size = new Size(100, 17);   }   // used to refresh the values of the chart   private void RefreshUsages(Queue<int> usages)   {     if (usages.Count > 0)   {   Queue<int> refreshUsages = new Queue<int>(usages);   chart_.OpenData(COD.Values | COD.Unchange | COD.NoInvalidate, 1, 30);   for (int i = 30 - refreshUsages.Count; i < 30; i++)   {   chart_.Value[0, i] = refreshUsages.Dequeue();   }   chart_.CloseData(COD.Values | COD.Unchange | COD.NoInvalidate);   }   }   // is called each time a cell is redrawn   void GridEX_DrawGridArea(object sender, DrawGridAreaEventArgs e)   {   ServiceListEntry sle = (ServiceListEntry)e.Row.DataRow;   if (!string.IsNullOrEmpty(sle.CpuUsage))   {   chart_.Location = e.Bounds.Location;   this.RefreshUsages(sle.CpuUsages);   Bitmap bm = new Bitmap(chart_.Width, chart_.Height);   chart_.DrawToBitmap(bm, chart_.ClientRectangle);   e.Graphics.DrawImage(bm, e.Bounds.Location);   }   else   {   chart_.ClearData(ClearDataFlag.Values);   }   e.Handled = true;   }

The chart should be much smaller than it is drawn each time.  Every second the cells are redrawn. Although the property AxisX.Max equals 100, the value e.g. 4 is drawn as it would be 90 or 95 (wrong scaled). However, I don't do anything concerning scaling and in case I open the usage window via double click the line chart is refreshed and redrawn correctly. Even when I change the size of the usage window, the line chart is scaled correctly.

I hope someone can help me to solve my problem because we need this feature!

greetz,

amanax 

Link to comment
Share on other sites

Hi Frank,
thanks for your reply!

I've attached a screenshot of some rows of the datagrid. There you can also see the embedded graphs. As I've mentioned in my prior post the Maximum of the Y-Axis is 100 but, however, the graphs are drawn as if e.g. 3 would have been the maximum value. The graph should be be drawn much flatter than it is drawn now.

What could be the problem?

Thanks in advance!

br,
Erol

Posted Image 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...