c# - got an error Null reference exception was Handled -


i trying show reporting chart clicking on 1 chart using following

code showing error

error : null reference exception handled object reference not set instance of object. @ line targetcontrol.chartareas.clear();

and click event chart control

 using system.windows.forms.datavisualization.charting;   private void kpichartcontrol_click(object sender, eventargs e) {   chart targetcontrol = null;   series series = null;   title title;   string are;    targetcontrol.chartareas.clear();   targetcontrol.series.clear();   targetcontrol.titles.clear();    datatable accepts = null;   accepts = kpidata.acceptedvisitsbymembership(mf ,"accepted");   = " acceptedvisitsmshiptypes";   targetcontrol.chartareas.add(are);   series = targetcontrol.series.add(are);   series.chartarea = are;    title = targetcontrol.titles.add("accepted visits membership type");   title.dockedtochartarea = are;   title.font = new font(fontfamily.genericsansserif, 10, fontstyle.bold);   title.alignment = contentalignment.topleft;    foreach (title titles in targetcontrol.titles)   {     titles.isdockedinsidechartarea = false;   }     foreach (series serie in targetcontrol.series)   {       serie.charttype = seriescharttype.pie;      serie["pielabelstyle"] = "outside";     serie["doughnutradius"] = "30";     serie["piedrawingstyle"] = "softedge";      serie.backgradientstyle = gradientstyle.diagonalleft;     }   foreach (legend legend in targetcontrol.legends)   {     legend.enabled = false;   }    foreach (chartarea chartarea in targetcontrol.chartareas)   {     chartarea.area3dstyle.enable3d = true;     chartarea.area3dstyle.inclination = 45;     //chartarea.axisx.labelstyle.isendlabelvisible = !overview;   }    targetcontrol.series[0].points.databindxy(accepts.rows, "mshiptypenumbers", accepts.rows, "mshiptype_name");   foreach (series chartseries in targetcontrol.series)   {     foreach (datapoint point in chartseries.points)     {        switch (point.axislabel)       {         case "silver membership": point.color = color.green; break;         //case "refused": point.color = color.red; break;        }       point.label = string.format("{0:0}", point.yvalues[0]);     }    } } 

of course error, you're declaring

chart targetcontrol = null;  

then you're trying use without instantiating anything.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -