DevExpress 网格单元中的价值百分比图

Percent of Value graph in DevExpress Grid Cell

我需要在 DevExpress 网格单元格中将价值的百分比表示为图表。我可以使用 DrawLine 进行绘画,但我的问题是一旦百分比值等于大于 1,它就会在此代码中被视为 100%。请找到下面的代码,如截图所示,3.59应该显示小于8.35!请帮忙

private void CustomDrawCell(object sender, RowCellCustomDrawEventArgs args)
{
    args.Appearance.DrawBackground(args.Graphics, args.Cache, args.Bounds);
      if (column != null)
      {
        int penSize = args.Bounds.Height * 2 / 3;
        double value = GetValue(); // This is the value against which I have to display the graph, its in %.

        int left = args.Bounds.Left;
        int middle = args.Bounds.Height / 2 + args.Bounds.Top;
        int width = args.Bounds.Width;

        int right = (int)(left + width * value);
        args.Graphics.DrawLine(new Pen(Color.Green, penSize), left, middle, right, middle);

       }        
    args.Handled = true;
  }

int right = (int)(left + width * value);

仅当 value 介于 0 和 1 之间时,此代码才能正确计算条形长度。如果值介于 0 和 100 之间或介于 0 和 10 之间,则需要将相应乘以100或10的结果。

int right = (int)(left + width * value / 100);

对了,自定义绘图不用纠结,因为你用的是XtraGrid。还有 RepositoryItemProgressBar component, which can be embedded into XtraGrid cell. It displays the line according to the cell value and allows you to define the maximum and minimum value, so that the line is most exactly visualize the cell value. Read this article to learn how to assign editors to columns: Assigning Editors to Columns and Card Fields