c# - MS Chart - How to put the X label on the left for a column series -


i working on graph (sorry it's first post, reputation can't post image directly) :

graph working on

for giving hour, example 10h, y value represents number of requests between 10h , 11h.

as can see on graph, columns centered on x label. question quite simple, how put label on left of column, on graph columns between 2 labels.

in resume, looking way on every columns :

what looking for

in case need this, here pertinent lines of code graph

    myadapter.fill(dailydata);      // add points series     (int = 0; < dailydata.rows.count; i++)     {         datarow row = dailydata.rows[i];         if (int.parse(row["hours"].tostring()) < 10)         {             dailychart.series["series1"].points.addxy("0" + row["hours"].tostring() + "h", row["requestsnumber"].tostring());         }         else         {             dailychart.series["series1"].points.addxy(row["hours"].tostring() + "h", row["requestsnumber"].tostring());         }     }      // set series chart type     dailychart.series["series1"].charttype = seriescharttype.column;     dailychart.series["series1"]["pointwidth"] = "1";      // set x axis labels format     dailychart.chartareas["chartarea1"].axisx.interval = 1; 

have day!

i know winformschartsample microsoft mschart has file called histogramhelper.vb if recall correctly solves problem.

i use modified version of code, i'll put here:

histogramhelper.vb

imports system imports system.drawing imports system.drawing.drawing2d imports system.windows.forms.datavisualization.charting imports system.collections  '-------------------------------------------------------------------------------------- 'code extracted winformschartsample microsoft 'modified use single series obj, instead of 2 1 of them hidden 'also removed out auto labels , % axis '--------------------------------------------------------------------------------------   ''' <summary> ''' helper class creates histogram chart. histogram data ''' distribution chart shows how many values, data series, ''' inside each segment interval.   '''  ''' can define how many intervals want have using segmentintervalnumber ''' field or exact length of interval using segmentintervalwidth ''' field. actual segment interval number can different due ''' automatic interval rounding. ''' </summary> public class histogramcharthelper #region "fields"      ''' <summary>     ''' number of class intervals data range devided in.     ''' property has affect when "segmentintervalwidth"      ''' set double.nan.     ''' </summary>     public segmentintervalnumber integer = 20      ''' <summary>     ''' histogram class interval width. setting value "double.nan"     ''' result in automatic width calculation based on data range     ''' , number of required interval specified in "segmentintervalnumber".     ''' </summary>     public segmentintervalwidth double = double.nan      ''' <summary>     ''' indicates percent frequency should shown on right axis     ''' </summary>     public showpercentonsecondaryyaxis boolean = true  #end region   ' fields  #region "methods"      ''' <summary>     ''' creates histogram chart.     ''' </summary>     ''' <param name="chartcontrol">chart control reference.</param>     ''' <param name="datapoints">original data series</param>     ''' <param name="histogramseriesname">name of histogram series.</param>     public function createhistogram(byval chartcontrol chart, byval datapoints() double, byval histogramseriesname string) series         ' validate input         if chartcontrol nothing             debug.print("invalid chart control passed")             return nothing         end if           dim aseries new series          ' set new series chart type , other attributes         aseries.charttype = seriescharttype.column         aseries.bordercolor = color.black         aseries.borderwidth = 1         aseries.borderdashstyle = chartdashstyle.solid           ' data series minimum , maximum values         dim minvalue double = double.maxvalue         dim maxvalue double = double.minvalue         dim pointcount integer = 0          integer = 0 datapoints.length - 1              ' process non-empty data points              if datapoints(i) > maxvalue                 maxvalue = datapoints(i)             end if             if datapoints(i) < minvalue                 minvalue = datapoints(i)             end if             pointcount += 1          next          ' calculate interval width if it's not set         if double.isnan(me.segmentintervalwidth)             me.segmentintervalwidth = (maxvalue - minvalue) / segmentintervalnumber             me.segmentintervalwidth = roundinterval(me.segmentintervalwidth)         end if          ' round minimum , maximum values         minvalue = math.floor(minvalue / me.segmentintervalwidth) * me.segmentintervalwidth         maxvalue = math.ceiling(maxvalue / me.segmentintervalwidth) * me.segmentintervalwidth          ' create histogram series points         dim currentposition double = minvalue         currentposition = minvalue         while currentposition <= maxvalue             ' count points data series in current interval             dim count integer = 0              integer = 0 datapoints.length - 1                  dim endposition double = currentposition + me.segmentintervalwidth                 if datapoints(i) >= currentposition andalso datapoints(i) < endposition                     count += 1                      ' last segment includes point values on both segment boundaries                 elseif endposition > maxvalue                     if datapoints(i) >= currentposition andalso datapoints(i) <= endposition                         count += 1                     end if                 end if              next               ' add data point histogram series             aseries.points.addxy(currentposition + me.segmentintervalwidth / 2.0, count)             currentposition += me.segmentintervalwidth         loop          ' adjust series attributes         'this "custom property" http://msdn.microsoft.com/en-us/library/dd456700.aspx         aseries("pointwidth") = "1"          ' adjust chart area         dim chartarea chartarea = chartcontrol.chartareas(0)         'chartarea.axisy.title = "frequency"         chartarea.axisx.minimum = minvalue         chartarea.axisx.maximum = maxvalue          ' set axis interval based on histogram class interval         ' , not allow more 10 labels on axis.         dim axisinterval double = me.segmentintervalwidth         while (maxvalue - minvalue) / axisinterval > 10.0             axisinterval *= 2.0         loop         chartarea.axisx.interval = axisinterval          return aseries     end function      ''' <summary>     ''' helper method rounds specified axsi interval.     ''' </summary>     ''' <param name="interval">calculated axis interval.</param>     ''' <returns>rounded axis interval.</returns>     friend function roundinterval(byval interval double) double         ' if interval 0 return error         if interval = 0.0             throw (new argumentoutofrangeexception("interval", "interval can not zero."))         end if          ' if real interval > 1.0         dim step_renamed double = -1         dim tempvalue double = interval         while tempvalue > 1.0             step_renamed += 1             tempvalue = tempvalue / 10.0             if step_renamed > 1000                 throw (new invalidoperationexception("auto interval error due invalid point values or axis minimum/maximum."))             end if         loop          ' if real interval < 1.0         tempvalue = interval         if tempvalue < 1.0             step_renamed = 0         end if          while tempvalue < 1.0             step_renamed -= 1             tempvalue = tempvalue * 10.0             if step_renamed < -1000                 throw (new invalidoperationexception("auto interval error due invalid point values or axis minimum/maximum."))             end if         loop          dim tempdiff double = interval / math.pow(10.0, step_renamed)         if tempdiff < 3.0             tempdiff = 2.0         elseif tempdiff < 7.0             tempdiff = 5.0         else             tempdiff = 10.0         end if          ' make correction of real interval         return tempdiff * math.pow(10.0, step_renamed)     end function  #end region   ' methods end class 

i have helper function generate histograms:

 public function hist(byval x double(), optional byval bins integer = 10) system.windows.forms.datavisualization.charting.series          ' histogramcharthelper helper class found in samples utilities folder.          dim histogramhelper new histogramcharthelper()          ' specify number of segment intervals         histogramhelper.segmentintervalnumber = bins          ' create histogram series             dim newseries series = histogramhelper.createhistogram(gca(), x, "histogram")         gca().chartareas(0).axisx.islogarithmic = false         gca().chartareas(0).axisy.islogarithmic = false         gca().series.add(newseries)         gcf().dorefresh()          return newseries     end function 

and trying generate histogram similar yours: hist({8,8,8,8,8,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,13,13,14,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,18,18})

i get: generated histogram


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -