c# - Why do Chart Stacked Columns show up as thin lines? -
i trying create stacked column chart 4 series in it. somehow, after populating series , making sure aligned, instead of columns, thin lines appears. code below.
foreach (series s in chartevents.series) s.points.clear(); foreach (datarow dr in data.rows) { string reason = ""; double xval = 0; double yval = 0; double overflow = 0; double existflow = 0; try { reason = dr["reasonid"].tostring(); xval = math.round(convert.todatetime(dr["xvalue"].tostring()).tooadate(), 6); yval = math.round(convert.todouble(dr["duration"].tostring()) / 60, 3); overflow = 0; // assume tooltip prepared , format length here { overflow = 0; #region check if duration @ x value exceed 60 mins foreach (series s in chartevents.series) { if (s.points.count > 0) { foreach (datapoint exist in s.points) { // if point found, add up. if (exist.xvalue == xval) { existflow += exist.yvalues[0]; } } } } // if added + new > 60, set current y 60 , calculate overflow if (existflow + yval > 60) { overflow += yval - (60 - existflow); yval = 60 - (existflow); } #endregion datapoint dp = new datapoint(xval, yval); datapoint dpempty = new datapoint(xval, 0); dpempty.isempty = true; #region check series type , add series. if (reason.contains("|")) { if (reason.split('|')[3] == "scheduled down") { if (reason.split('|')[4].contains("setup")) { dp.tooltip = convert.todatetime(dr["datestart"].tostring()).tostring("yyyy-mm-dd hh:mm:ss").padright(25) + "setup: " + actiondone; dp.color = color.goldenrod; chartevents.series["setup"].points.add(dp); chartevents.series["clear"].points.add(dpempty); chartevents.series["down"].points.add(dpempty); chartevents.series["others"].points.add(dpempty); } else { dp.tooltip = convert.todatetime(dr["datestart"].tostring()).tostring("yyyy-mm-dd hh:mm:ss").padright(25) + "others: " + actiondone; dp.color = color.orange; chartevents.series["others"].points.add(dp); chartevents.series["clear"].points.add(dpempty); chartevents.series["down"].points.add(dpempty); chartevents.series["setup"].points.add(dpempty); } } else if (reason.split('|')[3] == "unscheduled down") { dp.tooltip = convert.todatetime(dr["datestart"].tostring()).tostring("yyyy-mm-dd hh:mm:ss").padright(25) + "down: " + actiondone; dp.color = color.red; chartevents.series["down"].points.add(dp); chartevents.series["clear"].points.add(dpempty); chartevents.series["others"].points.add(dpempty); chartevents.series["setup"].points.add(dpempty); } else { // } } else { dp.tooltip = actiondone; dp.color = color.orange; chartevents.series["clear"].points.add(dp); chartevents.series["down"].points.add(dpempty); chartevents.series["others"].points.add(dpempty); chartevents.series["setup"].points.add(dpempty); } #endregion if (overflow > 0) { yval = overflow; xval = datetime.fromoadate(xval).addhours(1).tooadate(); existflow = 0; } } while (overflow != 0); } catch (exception ex) { // } }
you have wrong x-values
purpose.
note series
can stack datapoints
have same x-value
. datetimes
include times downto fractions of second, never stack unless twist them meet goal..
you code closely missing point here:
xval = math.round(convert.todatetime(dr["xvalue"].tostring()).tooadate(), 6);
rounding datetime
/ oadate double
6 digits unfortunately not trim time portion. instead write xvalue = somedatetimevariable.date;
for other time intervals must decide on time interval, days, minutes, hours etc.. , trim data multiples of interval.
there several ways that, here one:
// define suitable format string: string myintervalmonthformat = "yyyy-mm-01 00:00:00"; string myintervaldayformat = "yyyy-mm-dd 00:00:00"; string myintervalhourformat = "yyyy-mm-dd hh:00:00"; string myintervalminuteformat = "yyyy-mm-dd hh:mm:00"; // etc
now can use it:
string = ((datetime) dr["xvalue"]).tostring(yourformat ); xval = math.round(convert.todatetime(so).tooadate(), 6);
here 2 results, same data, 1 minute interval, , other days.:
i suggest considering set x-axis
, x-values
use datetime
datatype!
please ignore fact i'm not creating convincing stacked column chart, didn't create test data..
Comments
Post a Comment