Моя модификация старой веб-программы в моей компании немного загадочна.По сути, его функция заключается в создании нескольких круговых диаграмм на основе данных в DataTable.
Ранее оператор SQL и генерация круговой диаграммы объединялись в цикл For, что приводило к медленному времени загрузки (40 диаграмм = 30+ секунд).
Поэтому первым делом я отделил оператор SQL от цикла For.
Dim query1 As String = String.Format("SELECT DISTINCT A.MacID FROM dbo.tblMachine A LEFT JOIN dbo.tblDataHdr b on a.MacID = b.MacID where DayID between '" & TextBox1.Text & "' AND '" & TextBox3.Text & "' ORDER BY A.MACID")
Dim dt1 As DataTable = GetData(query1)
Dim result As String = dt1.AsEnumerable().[Select](Function(x) x("MacId").ToString()).Aggregate(Function(a, b) String.Concat(a & "'" & "," & "'" & b))
Dim query As String = String.Format("SELECT Z.MacID, Z.EventName, ISNULL(DIFF,0) AS DIFF FROM (select distinct MacID, EventName from dbo.tblMachine a " _
& "join (SELECT DISTINCT EVENTNAME FROM dbo.tblEvtDur where EventName <> 'ON' ) b on b.EventName <> '' and MacID in ('" & result & "') ) Z " _
& "LEFT JOIN (SELECT A.MacID, A.EventName, SUM(DATEDIFF(SECOND, A.STARTdt, A.eNDdt)) as diff,round(SUM(DATEDIFF(SECOND, A.STARTdt, A.eNDdt)) / cast(aVG(Tdiff) " _
& "as decimal(30,8)),4) * 100 AS PER FROM dbo.tblEvtDur A LEFT JOIN ( SELECT MacID, SUM(DATEDIFF(SECOND, STARTdt, eNDdt)) as Tdiff FROM dbo.tblEvtDur " _
& "WHERE DayID between '" & TextBox1.Text & "' and '" & TextBox3.Text & "' GROUP BY MacID ) B ON A.MacID = B.MacID WHERE DayID " _
& "between '" & TextBox1.Text & "' and '" & TextBox3.Text & "' AND A.MacID in ('" & result & "') group by A.MacID, A.EventName) a " _
& "ON A.EVENTNAME = Z.EVENTNAME and Z.MacID = a.MacID order by Z.MacID, Z.EventName")
Dim dt As DataTable = GetData(query)
DataTable dt
будет использоваться при создании круговых диаграмм.В качестве примера того, как данные выглядят здесь, приведем пример:
----------------------------
| MacID | EventName | DIFF | 'DIFF is total time recorded in seconds
----------------------------
| A01 | BLK | 65 |
| A01 | COM | 0 |
| A01 | MDL | 0 |
| A01 | MTL | 0 |
| A01 | OFF | 0 |
| A01 | RPR | 0 |
| A01 | RUN | 0 |
| Z09 | BLK | 0 |
| Z09 | COM | 0 |
| Z09 | MDL | 0 |
| Z09 | MTL | 256 |
| Z09 | OFF | 3220 |
| Z09 | RPR | 1164 |
| Z09 | RUN | 19874|
----------------------------
На каждой машине есть 7 различных EventName
, и время под каждым событием записывается.Теперь мне нужно создать круговую диаграмму, по одной для каждой машины, которая покрывает 7 EventName
.
Однако, когда я перемещаю SQL из цикла For, круговая диаграмма генерируется странным образом.Вот код для создания круговой диаграммы под той же подпунктом.
Dim check2
PlaceHolder1.Dispose()
PlaceHolder2.Dispose()
For a As Integer = 0 To dt1.Rows.Count - 1
check2 = dt1.Rows(a)(0).ToString()
Dim mychart As Chart = New Chart
Dim ChartArea1 As ChartArea = New ChartArea
Dim Legend1 As Legend = New Legend
Dim x As String() = New String(dt.Rows.Count - 1) {}
Dim y As Integer() = New Integer(dt.Rows.Count - 1) {}
For i As Integer = 0 To dt.Rows.Count - 1
x(i) = dt.Rows(i)(1).ToString()
y(i) = Convert.ToInt32(dt.Rows(i)(2))
Next
mychart.Width = 600
mychart.Height = 400
mychart.ChartAreas.Clear()
mychart.ChartAreas.Add("ChartArea1")
mychart.Series.Clear()
mychart.Series.Add(0)
mychart.Series(0).Points.DataBindXY(x, y)
mychart.Titles.Clear()
mychart.Titles.Add("[" & a + 1 & "] " & check2.ToString.ToUpper)
mychart.Titles(0).Font = New System.Drawing.Font("Tahoma", 12, System.Drawing.FontStyle.Bold)
mychart.Titles(0).BackColor = Color.PaleTurquoise
mychart.Titles(0).ForeColor = Color.Black
mychart.Series(0).ChartType = SeriesChartType.Pie
mychart.Series(0).LegendText = "#VALX"
mychart.Series(0)("BarLabelStyle") = "Center"
mychart.Series(0)("pointWidth") = "1"
mychart.Series(0).BorderDashStyle = ChartDashStyle.Solid
mychart.Series(0).BorderWidth = 2
mychart.Series(0).Label = "#PERCENT"
mychart.Series(0).ShadowColor = Color.Gray
mychart.Series(0).ShadowOffset = 10
mychart.Series(0).LabelBackColor = Drawing.Color.Cornsilk
mychart.Series(0).Font = New Font("Tahoma", 9, FontStyle.Bold)
mychart.Series(0).LegendToolTip = "#VALX - #PERCENT"
mychart.Series(0).ToolTip = "#VALX - #PERCENT"
mychart.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True
mychart.Series(0).CustomProperties = "DrawingStyle=LightToDark"
'new
Chart1.Series(0).CustomProperties = "PieLabelStyle=Outside"
mychart.ChartAreas("ChartArea1").BorderDashStyle = BorderStyle.Solid
mychart.Palette = ChartColorPalette.None
mychart.Series(0).BorderDashStyle = ChartDashStyle.Solid
mychart.Series(0).BorderWidth = 2
mychart.Series(0).BorderColor = Color.Black
mychart.PaletteCustomColors = {Drawing.Color.Black, Drawing.Color.White, Drawing.Color.Blue, Drawing.Color.Yellow, Drawing.Color.Red, Drawing.Color.Orange, Drawing.Color.Green}
mychart.Legends.Clear()
mychart.Legends.Add(0)
mychart.Legends(0).Font = New Font("Tahoma", 10, FontStyle.Bold)
mychart.Legends(0).Docking = System.Web.UI.DataVisualization.Charting.Docking.Bottom
mychart.DataBind()
If (a + 1) Mod 2 <> 0 Then
PlaceHolder1.Controls.Add(mychart)
End If
If (a + 1) Mod 2 = 0 Then
PlaceHolder2.Controls.Add(mychart)
End If
Next
Все, что я получаю, это все круговые диаграммы, имеющие слишком много квадрантов (как в более чем 40 срезах на круговой диаграмме) и одинаковыедля всех машин.Есть идеи, что изменить в коде моей круговой диаграммы?