按照书上的我写了个base command
在form_load里面加载 
axToolbarControl1.AddItem(new BarChartRendererM(0, "Z120401",true, 0, "Z121301","Fill Symbol"), - 1, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); 
"Z120401","Z121301"是比较的两个字段为什么运行不出来?工具栏上已经显示加载成功了,但是运行不出效果
namespace test
{
   
    public sealed class BarChartRendererM : BaseCommand
    {
        #region COM Registration Function(s)
        [ComRegisterFunction()]
        [ComVisible(false)]
        static void RegisterFunction(Type registerType)
        {
            ArcGISCategoryRegistration(registerType);
        }        [ComUnregisterFunction()]
        [ComVisible(false)]
        static void UnregisterFunction(Type registerType)
        {
        ArcGISCategoryUnregistration(registerType);
        }        #region ArcGIS Component Category Registrar generated code
               private static void ArcGISCategoryRegistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            ControlsCommands.Register(regKey);        }
          private static void ArcGISCategoryUnregistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            ControlsCommands.Unregister(regKey);        }        #endregion
        #endregion        private IHookHelper m_hookHelper=new HookHelperClass();
        IMap pmap;
        IActiveView pactiveview;
        int playerinedex;
        string fieldname;
        int numfield;//加入的字段个数
        string barfieldsstring;//加入的这些以‘,’为间隔
        bool barstacktag;//是否堆积
        string m_strshapetype;        public BarChartRendererM(int layerin,string strfield,bool stacktag,int fieldcount,string fieldstring,string shapetype)
        {
            //
            // TODO: Define values for the public properties
            //
            base.m_category = "symbology"; //localizable text
            base.m_caption = "BarChartRenderer";  //localizable text
            base.m_message = "BarChartRenderer";  //localizable text 
            base.m_toolTip = "BarChartRenderer";  //localizable text 
            base.m_name = "BarChartRenderer";   //unique id, non-localizable (e.g. "MyCategory_MyCommand")
            base.m_enabled = true;
            playerinedex = layerin;
            fieldname = strfield;
            numfield = fieldcount;
            barfieldsstring = fieldstring;
            m_strshapetype = shapetype;
            barstacktag = stacktag;            try
            {
                //
                // TODO: change bitmap name if necessary
                //
                string bitmapResourceName = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }        #region Overriden Class Methods        /// <summary>
        /// Occurs when this command is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            if (hook == null)
                return;            if (m_hookHelper == null)
                m_hookHelper = new HookHelperClass();            m_hookHelper.Hook = hook;            // TODO:  Add other initialization code
        }        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        /// 
        
        public override void OnClick()
        {
            // TODO: Add BarChartRendererM.OnClick implementation
            IGeoFeatureLayer pgeofeaturel;
            IFeatureLayer pfeaturelayer;
            ITable ptable;
            ICursor pcursor;
            IQueryFilter pqueryfilter;
            string[] fieldstrarr = new string[numfield];
            double dmaxvalue;
            IChartRenderer pchartrenderer;
            IRendererFields prendererfields;
            IFillSymbol pfillsymbol;
            IMarkerSymbol persymbol;
            ISymbolArray psymbolarray;
            IChartSymbol pchartsymbols;
            bool firstValue=true;
            pactiveview = m_hookHelper.ActiveView;
            pmap = m_hookHelper.FocusMap;
            pfeaturelayer = (IGeoFeatureLayer)pmap.get_Layer(playerinedex);
            pgeofeaturel = (IGeoFeatureLayer)pfeaturelayer;
            ptable = (ITable)pgeofeaturel;
            pgeofeaturel.ScaleSymbols = true;
            pchartrenderer = new ChartRendererClass();
            //设置柱状图反映的多个字段
            prendererfields = (IRendererFields)pchartrenderer;
            pqueryfilter = new QueryFilterClass();
            //以空格为分隔符,取出numfields个字段名,放入fieldstrarr数组里
            for (int i = 0; i < numfield; i++)
            {
                int endindex = barfieldsstring.IndexOf(',');
                string strpopfield = barfieldsstring.Substring(0, endindex);
                barfieldsstring = barfieldsstring.Substring(endindex + 1);
                prendererfields.AddField(strpopfield, strpopfield);
                pqueryfilter.AddField(strpopfield);
                fieldstrarr[i] = strpopfield;
            }            int lfieldindex;
            dmaxvalue = 0;
            //获得所有要素中多个标注字段中的最大属性值
            for (lfieldindex = 0; lfieldindex <= numfield - 1; lfieldindex++)
            {
                pcursor = ptable.Search(pqueryfilter, true);
                //使用统计对象获得最大值
                IDataStatistics pDataStatistics;
                IStatisticsResults pstatisticsresult;
                pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pcursor;
                //设置统计字段
                pDataStatistics.Field = fieldstrarr[lfieldindex];
                pstatisticsresult = pDataStatistics.Statistics;
                //比较并存储最大值
                if (firstValue)
                {
                    dmaxvalue = pstatisticsresult.Maximum;
                    firstValue = false;
                }
                if (pstatisticsresult.Maximum > dmaxvalue)
                {
                    dmaxvalue = pstatisticsresult.Maximum;
                }            }
            if(dmaxvalue-0.01<0.0001)
            {
                dmaxvalue+=1;
            }            if (dmaxvalue <= 0)
            {
                MessageBox.Show("获得了无效的最大值。");
                return;
            }
            //设置柱状渲染方式
            IChartSymbol pbarchartsymbol;
            if (barstacktag == false)
            {
                pbarchartsymbol = new BarChartSymbolClass();            }
            else
            {
                ///柱状堆积排列
                pbarchartsymbol = new StackedChartSymbolClass();
             
            }                pchartsymbols = (IChartSymbol)pbarchartsymbol;
                persymbol = (IMarkerSymbol)pbarchartsymbol;
            //设置最大值
                pchartsymbols.MaxValue = dmaxvalue;
            //柱状图的最大尺寸
                persymbol.Size = 40;
            //为每条柱设置着色符号
                psymbolarray = (ISymbolArray)pbarchartsymbol;
            //为每条柱状设置颜色
                pfillsymbol = new SimpleFillSymbolClass();
                pfillsymbol.Color = GetRGB(230, 220, 240);
                psymbolarray.AddSymbol((ISymbol)pfillsymbol);
                pfillsymbol = new SimpleFillSymbolClass();
            //设置填充色
                pfillsymbol.Color = GetRGB(180, 240, 123);
                psymbolarray.AddSymbol((ISymbol)pfillsymbol);
            //设置图标符号为柱图
                pchartrenderer.ChartSymbol = (IChartSymbol)pbarchartsymbol;
                pchartrenderer.Label = fieldname;//标注名
            //设置背景符号
                pchartrenderer.BaseSymbol = GetSymbolByShpType(m_strshapetype, GetRGB(239, 0, 190));
            //将柱图显示在渲染要素的中部,并创建标签
                pchartrenderer.UseOverposter = false;
                pchartrenderer.CreateLegend();
            //刷新渲染及屏幕
                pgeofeaturel.Renderer = (IFeatureRenderer)pchartrenderer;
                pactiveview.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
        //定义颜色的方法
        private IRgbColor GetRGB(int r, int g, int b)
        {
            IRgbColor pColor;
            pColor = new RgbColorClass();
            pColor.Red = r;
            pColor.Green = g;
            pColor.Blue = b;
            return pColor;
        }
        public ISymbol GetSymbolByShpType(string strshptype, IColor fillcolor)
        {
            ISymbol returnsyb = null;
            IFillSymbol pfillsymbol;
            ILineSymbol plinesymbol;
            //设置背景符号
            if (strshptype == "Fill Symbols")
            {
                pfillsymbol = new SimpleFillSymbolClass();
                pfillsymbol.Color = fillcolor;
                plinesymbol = new SimpleLineSymbolClass();
                plinesymbol.Color = GetRGB(10, 28, 190);
                plinesymbol.Width = 1;
                pfillsymbol.Outline = plinesymbol;
                returnsyb = (ISymbol)pfillsymbol;
            }
            if (strshptype == "Line Symbols")
            {
                ILineSymbol plinebasesymbol;
                plinebasesymbol = new SimpleLineSymbolClass();
                plinebasesymbol.Color = fillcolor;
                returnsyb = (ISymbol)plinebasesymbol;
            }
            if (strshptype == "Marker Symbols")
            {
                IMarkerSymbol perbasesymbol;
                perbasesymbol = new SimpleMarkerSymbolClass();
                perbasesymbol.Color = fillcolor;
                perbasesymbol.Size = 1.5;
                returnsyb = (ISymbol)perbasesymbol;
            }
            return returnsyb;
        }
        #endregion
    }
}
gis