i working on application chart boards inspected , board defects based on work order number. realize after looking @ chart , comparing actual data, series not match work order number. @ loss on how match both series work order number correct chart.
here code data pull boards_inspected pulled first
public dataset get_boards_inspected(string startdate, string enddate, int location) { dataset ds = new dataset(); npgsqlconnection conn = databaseconnection.getconnectionstring(); try { conn.open(); npgsqldataadapter da = new npgsqldataadapter("select new_table.top_or_bottom, new_table.board_wo_number, count(new_table.board_serial_number) from" + " (select distinct master_board.board_serial_number, board_wo.board_wo_number,board_wo.board_part_number, board_time.top_or_bottom master_board" + " inner join board_time on board_time.board_time_id = master_board.id" + " inner join board_wo on board_wo.board_wo_number = master_board.board_wo_number" + " time_in between '" + startdate + "' , '" + enddate + "'" + " , board_time.location_id = '" + location + "')" + " new_table" + " group new_table.top_or_bottom, new_table.board_wo_number" + " order top_or_bottom;", conn); ds.reset(); da.fill(ds); da.dispose(); } catch (exception ex) { messagebox.show("an unexpected error has occured application. \n" + "an email has been sent software developer analysis. \n" + "this program close.", "unexpected error", messageboxbuttons.ok, messageboxicon.error); emessagebody = ex.tostring(); mail sendmessage = new mail(); sendmessage.sendsmtp(emessagebody, emessagesubject); application.exit(); } { conn.close(); } return ds; } board defects
public dataset get_boards_with_issue(string startdate, string enddate, int location) { dataset ds = new dataset(); npgsqlconnection conn = databaseconnection.getconnectionstring(); try { conn.open(); npgsqldataadapter da = new npgsqldataadapter("select new_table.top_or_bottom, new_table.board_wo_number, count(new_table.defect_id) from" + " (select distinct defect_id, top_or_bottom, board_wo_number defect" + " inner join master_board on defect.defect_id = master_board.id" + " defect_time between '" + startdate + "' , '" + enddate + " 23:59:59'" + " , location_id = '" + location + "')" + " new_table" + " group new_table.top_or_bottom, new_table.board_wo_number" + " order top_or_bottom;", conn); ds.reset(); da.fill(ds); da.dispose(); } catch(exception ex) { messagebox.show("an unexpected error has occured application. \n" + "an email has been sent software developer analysis. \n" + "this program close.", "unexpected error", messageboxbuttons.ok, messageboxicon.error); emessagebody = ex.tostring(); mail sendmessage = new mail(); sendmessage.sendsmtp(emessagebody, emessagesubject); application.exit(); } { conn.close(); } return ds; } here chart series assignment code
private void boards_without_issue_chart(string stardate, string enddate, int location) { try { #region chart setup chart1.series.clear(); chart1.series.add("boards inspected"); chart1.series.add("boards without issue"); chart1.series.add("boards issue"); chart1.series["boards inspected"].points.clear(); chart1.series["boards without issue"].points.clear(); chart1.series["boards issue"].points.clear(); chart1.series["boards inspected"]["labelstyle"] = "top"; chart1.series["boards without issue"]["labelstyle"] = "top"; chart1.series["boards issue"]["labelstyle"] = "top"; chart1.chartareas[0].axisx.interval = 1; chart1.series["boards inspected"].charttype = seriescharttype.column; chart1.series["boards without issue"].charttype = seriescharttype.column; chart1.series["boards issue"].charttype = seriescharttype.column; chart1.series["boards inspected"]["drawingstyle"] = "lighttodark"; chart1.series["boards without issue"]["drawingstyle"] = "lighttodark"; chart1.series["boards issue"]["drawingstyle"] = "lighttodark"; if (chart1.titles.contains(t1)) { t1.font = new system.drawing.font("microsoft sans serif", 14, fontstyle.bold); t1.text = titletext + " - boards without issue - (" + startdate + " - " +enddate+ ")"; } else { t1.name = "ttitle1"; t1.font = new system.drawing.font("microsoft sans serif", 14, fontstyle.bold); t1.text = titletext + " - boards without issue - (" + startdate + " - " + enddate + ")"; chart1.titles.add(t1); } chart1.chartareas[0].borderdashstyle = chartdashstyle.solid; chart1.chartareas[0].axisx.majorgrid.linewidth = 0; chart1.chartareas[0].axisy.titlefont = new system.drawing.font("microsoft sans serif", 14, fontstyle.bold); chart1.chartareas[0].axisy.title = "amount of boards"; chart1.chartareas[0].axisx.titlefont = new system.drawing.font("microsoft sans serif", 14, fontstyle.bold); chart1.chartareas[0].axisx.title = "work order"; chart1.chartareas[0].axisx.labelstyle.angle = -45; chart1.chartareas[0].axisx.labelstyle.font = new system.drawing.font("microsoft sans serif", 12, fontstyle.regular); chart1.series["boards inspected"].isvalueshownaslabel = true; chart1.series["boards issue"].isvalueshownaslabel = true; #endregion #region chart data assignment dataaccess da = new dataaccess(); dataaccess da2 = new dataaccess(); dataset mda = new dataset(); if ((da.get_boards_inspected(startdate, enddate, location).tables[0].rows.equals(0)) && (da2.get_boards_with_issue(startdate, enddate, location).tables[0].rows.equals(0))) lblerror.text = "no information availiable"; else { foreach (datatable tb in da.get_boards_inspected(startdate, enddate, location).tables) { foreach (datarow dr in tb.rows) { object tpn = dr["top_or_bottom"]; var ct = (dr["count"].tostring()); var wo = (dr["board_wo_number"].tostring()); if (tpn == dbnull.value) chart1.series["boards inspected"].points.addxy(wo, ct); else chart1.series["boards inspected"].points.addxy(wo + " - " + tpn, ct); } } da.get_boards_inspected(startdate, enddate, location).clear(); da.get_boards_inspected(startdate, enddate, location).dispose(); foreach (datatable tb2 in da2.get_boards_with_issue(startdate, enddate, location).tables) { foreach (datarow dr2 in tb2.rows) { object tpn2 = dr2["top_or_bottom"]; var ct = (dr2["count"].tostring()); var wo = (dr2["board_wo_number"].tostring()); if (tpn2 == dbnull.value) chart1.series["boards issue"].points.addxy(wo, ct); else chart1.series["boards issue"].points.addxy(wo + " - " + tpn2, ct); } } da2.get_boards_with_issue(startdate, enddate, location).clear(); da2.get_boards_with_issue(startdate, enddate, location).dispose(); } #endregion } catch(exception ex) { messagebox.show("an unexpected error has occured application. \n" + "an email has been sent software developer analysis. \n" + "this program close.", "unexpected error", messageboxbuttons.ok, messageboxicon.error); emessagebody = ex.tostring(); mail sendmessage = new mail(); sendmessage.sendsmtp(emessagebody, emessagesubject); application.exit(); messagebox.show(ex.tostring()); } } edit: here code chart data
dataaccess da = new dataaccess(); dataaccess da2 = new dataaccess(); dataset mda = new dataset(); if ((da.get_boards_inspected(startdate, enddate, location).tables[0].rows.equals(0)) && (da2.get_boards_with_issue(startdate, enddate, location).tables[0].rows.equals(0))) lblerror.text = "no information availiable"; else { foreach (datatable tb in da.get_boards_inspected(startdate, enddate, location).tables) { foreach (datarow dr in tb.rows) { object tpn = dr["top_or_bottom"]; var ct = (dr["count"].tostring()); var wo = (dr["board_wo_number"].tostring()); if (tpn == dbnull.value) chart1.series["boards inspected"].points.addxy(wo, ct); else chart1.series["boards inspected"].points.addxy(wo + " - " + tpn, ct); } } da.get_boards_inspected(startdate, enddate, location).clear(); da.get_boards_inspected(startdate, enddate, location).dispose(); foreach (datatable tb2 in da2.get_boards_with_issue(startdate, enddate, location).tables) { foreach (datarow dr2 in tb2.rows) { object tpn2 = dr2["top_or_bottom"]; var ct = (dr2["count"].tostring()); var wo = (dr2["board_wo_number"].tostring()); if (tpn2 == dbnull.value) chart1.series["boards issue"].points.addxy(wo, ct); else chart1.series["boards issue"].points.addxy(wo + " - " + tpn2, ct); } } da2.get_boards_with_issue(startdate, enddate, location).clear(); da2.get_boards_with_issue(startdate, enddate, location).dispose(); edit: links
this classic mistake when working chart controls.
they seem automagically right until little closer , hit upon problems.
here rule:
all values, both x-values , y-values internally stored doubles.
if feed in numbers works fine. if feed in other data type heading trouble somewhere down line.
at first seems work , stuff feed shows nicely in labels.
but when want use advanced ability of chart, chances work work..
this can simple formatting labels, works string formats only. if want use number format need feed in numbers!
you hitting upon problem of matching points in different series.
you have fed in x-values strings , trouble starts data points need matching beyond order in add them.
you feed them in precise order need understand happens..
lets have behind scenes..: if use debugger x-values of series' datapoints, amazed see 0! strings fed in, have gone labels, x-values result of failed conversion double, resulting in 0. means datapoint have same x-value!
you have 2 options:
either add them in synch, in same order , same number of points in series.
use numbers x-values.
your workorder looks number; if can use it, if want to, spread out data according numbers. not idea. instead can assign each workorder index , use instead.
to create nice labels use axislabel property each data point!
it easiest, imo create datapoint first values , axislabel , maybe tooltips , colors , whatnot , add points collection.
now let sink in, have @ chart:

this code create it:
private void form1_load(object sender, eventargs e) { random r = new random(1); list<tuple<series, int>> misses = new list<tuple<series, int>>(); chart1.series.clear(); (int = 0; < 3; i++ ) { series s = new series("s" + (i + 1)); s.charttype = seriescharttype.column; chart1.series.add(s); } chart1.chartareas[0].axisx.interval = 1; foreach(series s in chart1.series) { (int = 0; < 30; i+=3) { if (r.next(3) > 0) s.points.addxy(i, i+1); else misses.add(new tuple<series, int>(s, i)); } } foreach (tuple<series, int> m in misses) { if (m.item1.name == "s1") m.item1.points.addxy(m.item2 + "x", m.item2 + 5); else m.item1.points.addxy(m.item2, m.item2 + 5); } (int = 0; < chart1.series[0].points.count - 1; i++) { chart1.series[0].points[i].axislabel = chart1.series[0].points[i].xvalue + "%"; } } let's have @ things happen:
i first create 3 series , fill few points them. randomly leave few slots empty.
i store these in list of tuples, can later add them out of order.
and can see they match up, except blue series 's1'.
can see why?
i use nice number x-values, not missed points in blues series, have attached "x" number.
now these points added too, x-value of 0 , sit @ position 0.
note: note above not code can use. code study learn data types of chart values , consequences of adding strings x-values!
Comments
Post a Comment