protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { PnlTripData.Visible = true; int tripId = Convert.ToInt32(ListBox1.SelectedItem.Text); /* Gemiddelde snelheid */ int averageSpeed = GetAverageSpeed(dataSet, userId, tripId); Label5.Text = (averageSpeed * 3.6) + " km/uur"; int averageSpeedAll = GetAverageSpeed(dataSet, userId); Label10.Text = (averageSpeedAll * 3.6) + " km/uur"; /* linechart */ LineChart one = newLine(dataSet, "Trip nummer " + tripId, ColorTranslator.FromHtml("#f67027"), 2, userId, tripId); ConfigureColors(); one.ShowLineMarkers = false; ChartControl1.Charts.Add(one); ChartControl1.RedrawChart(); /* GoogleMaps */ String[] Latitude = GetLatitudes(dataSet, userId, tripId); String[] Longitude = GetLongitudes(dataSet, userId, tripId); js.Text = BuildScript(Latitude, Longitude); welkomstTekst.Text = "Trip is geselecteerd. Klik op een andere trip om deze weer te geven."; //int selectedIndex = Convert.ToInt32(ListBox1.SelectedItem.Text); //int tripId = selectedIndex; //ChartControl1.Charts.Clear(); ///* Gemiddelde snelheid */ //int averageSpeed = GetAverageSpeed(dataSet, userId, tripId); //Label5.Text = averageSpeed + " km/uur"; //int averageSpeedAll = GetAverageSpeed(dataSet, userId, 0); //Label10.Text = averageSpeedAll + " km/uur"; ///* linechart */ //LineChart one = newLine(dataSet, "Trip nummer 1", ColorTranslator.FromHtml("#f67027"), 2, userId, tripId); //ConfigureColors(); //one.ShowLineMarkers = false; //ChartControl1.Charts.Add(one); //ChartControl1.RedrawChart(); ///* GoogleMaps */ //String[] Latitude = GetLatitudes(dataSet, userId, tripId); //String[] Longitude = GetLongitudes(dataSet, userId, tripId); //js.Text = BuildScript(Latitude, Longitude); }
void CreateChart() { DataTable dtChart = InitializeDtChart(); dtChart.Rows.Add("Kullanýlan Kredi", this.ChartCreditUsed); dtChart.Rows.Add("Alýnan Kredi", this.ChartBoughtCredit); PieChart chart = new PieChart(); chart.DataSource = dtChart.DefaultView; chart.DataXValueField = "Description"; chart.DataYValueField = "Value"; chart.DataLabels.Visible = true; chart.DataLabels.ForeColor = System.Drawing.Color.Blue; chart.Shadow.Visible = true; chart.DataBind(); chart.Explosion = dtChart.Rows.Count; ChartControl1.Charts.Add(chart); ChartControl1.RedrawChart(); }
private void PlotChart() { // Preparing Data Source For Chart Control DataTable dt = new DataTable("Chart"); DataColumn dc = new DataColumn("Website", typeof(string)); DataColumn dc1 = new DataColumn("Validation", typeof(int)); dt.Columns.Add(dc); dt.Columns.Add(dc1); DataRow dr = dt.NewRow(); dr[0] = "www.united.com"; dr[1] = 184; dt.Rows.Add(dr); DataRow dr1 = dt.NewRow(); dr1[0] = "www.orbits.com"; dr1[1] = 9; dt.Rows.Add(dr1); //Chart type you can change chart type here ex. pie chart,circle chart LineChart chart = new LineChart();//Class instance for LineChart chart.Fill.Color = Color.FromArgb(50, Color.SteelBlue); chart.Line.Color = Color.SteelBlue; chart.Line.Width = 2; //chart.Legend = "X Axis: Year.\nY Axis: Average"; chart.Legend = "X Axis: Websites \nY Axis: Validations"; //looping through datatable and adding to chart control foreach (DataRow dr2 in dt.Rows) { string str = dr2["Website"].ToString(); chart.Data.Add(new ChartPoint(dr2["Website"].ToString(), (float)System.Convert.ToSingle(dr2["Validation"]))); } ConfigureColors(); ChartControl1.Charts.Add(chart); ChartControl1.RedrawChart(); }
private async void Plotly_Charts_Demo_Loaded(object sender, RoutedEventArgs e) { //------------ // Call the ChartControl.Initialize method to ensure that the Plotly JavaScript library has been loaded: //------------ LoadingPleaseWaitMessage.Visibility = Visibility.Visible; await ChartControl.Initialize(); LoadingPleaseWaitMessage.Visibility = Visibility.Collapsed; //------------ // BAR CHART (STACKED) //------------ ChartControl1.Layout = new Layout() { Title = "Bar Chart", BarMode = BarMode.Stack, Width = 320, Height = 320 }; ChartControl1.Data = new Data() { Traces = new List <Trace>() { new Trace() { Name = "Test", X = new List <object>() { "giraffes", "orangutans", "monkeys" }, Y = new List <object>() { 20, 14, 23 }, Type = TraceType.Bar }, new Trace() { Name = "Test2", X = new List <object>() { "giraffes", "orangutans", "monkeys" }, Y = new List <object>() { 12, 16, 23 }, Type = TraceType.Bar } } }; ChartControl1.Render(); //------------ // SCATTER CHART //------------ ChartControl2.Layout = new Layout() { Title = "Scatter Chart", Width = 320, Height = 320 }; ChartControl2.Data = new Data() { Traces = new List <Trace>() { new Trace() { X = new List <object>() { 1, 2, 3, 4 }, Y = new List <object>() { 10, 15, 13, 17 }, Type = TraceType.Scatter, }, new Trace() { X = new List <object>() { 2, 3, 4, 5 }, Y = new List <object>() { 16, 5, 11, 9 }, Type = TraceType.Scatter, Mode = TraceMode.Markers | TraceMode.Text, Text = new List <string>() { "B-a", "B-b", "B-c", "B-d", "B-e" }, Marker = new Marker() { Size = 14 } }, new Trace() { X = new List <object>() { 1, 2, 3, 4 }, Y = new List <object>() { 12, 9, 15, 12 }, Type = TraceType.Scatter, Mode = TraceMode.Lines | TraceMode.Markers }, } }; ChartControl2.Render(); //------------ // BASIC PIE CHART //------------ ChartControl3.Layout = new Layout() { Title = "Pie Chart", Width = 320, Height = 320 }; ChartControl3.Data = new Data() { Traces = new List <Trace>() { new Trace() { Values = new List <object>() { 19, 26, 55 }, Labels = new List <string>() { "Item 1", "Item 2", "Item 3" }, Type = TraceType.Pie } } }; ChartControl3.Render(); //------------ // WATERFALL BAR //------------ ChartControl4.Layout = new Layout() { Title = "Waterfall Bar [Profit 2015]", BarMode = BarMode.Stack, PlotBgColor = "rgba(245, 246, 249, 1)", ShowLegend = false, Annotations = new List <Annotation>(), Width = 320, Height = 320, }; var XData = new List <object>() { "Total\nrevenue", "Fixed\ncosts", "Variable\ncosts", "Total costs", "Total" }; var YData = new List <object>() { 500, 590, 400, 400, 340 }; var TextList = new List <string>() { "$690K", "$-120K", "$-200K", "$-320K", "$370K" }; ChartControl4.Data = new Data() { Traces = new List <Trace>() { new Trace() { X = XData, Y = new List <object> { 0, 570, 370, 370, 0 }, Marker = new Marker() { Color = "rgba(1, 1, 1, 0.0)" }, Type = TraceType.Bar }, new Trace() { X = XData, Y = new List <object>() { 690, 0, 0, 0, 0 }, Type = TraceType.Bar, Marker = new Marker() { Color = "rgba(55, 128, 191, 0.7)", Line = new Line() { Color = "rgba(55, 128, 191, 1.0)", Width = 2 } } }, new Trace() { X = XData, Y = new List <object>() { 0, 120, 200, 320, 0 }, Type = TraceType.Bar, Marker = new Marker() { Color = "rgba(219, 64, 82, 0.7)", Line = new Line() { Color = "rgba(219, 64, 82, 1.0)", Width = 2 } } }, new Trace() { X = XData, Y = new List <object>() { 0, 0, 0, 0, 370 }, Type = TraceType.Bar, Marker = new Marker() { Color = "rgba(50, 171, 96, 0.7)", Line = new Line() { Color = "rgba(50, 171, 96, 1.0)", Width = 2 } } } } }; for (int i = 0; i < 5; i++) { var result = new Annotation() { X = XData[i], Y = YData[i], Text = TextList[i], Font = new Font() { Family = "Arial", Size = 10, Color = "rgba(245, 246, 249, 1)" }, ShowArrow = false }; ChartControl4.Layout.Annotations.Add(result); } ChartControl4.Render(); //------------ // BAR CHART WITH RELATIVE BARMODE //------------ ChartControl5.Layout = new Layout() { BarMode = BarMode.Relative, Xaxis = new Axis() { Title = "X axis" }, Yaxis = new Axis() { Title = "Y axis" }, Title = "Relative Barmode", Width = 300, Height = 300 }; ChartControl5.Data = new Data() { Traces = new List <Trace>() { new Trace() { X = new List <object>() { 1, 2, 3, 4 }, Y = new List <object>() { 1, 4, 9, 16 }, Name = "Trace1", Type = TraceType.Bar }, new Trace() { X = new List <object>() { 1, 2, 3, 4 }, Y = new List <object>() { 6, -8, -4.5, 8 }, Name = "Trace2", Type = TraceType.Bar }, new Trace() { X = new List <object>() { 1, 2, 3, 4 }, Y = new List <object>() { -15, -3, 4.5, -8 }, Name = "Trace3", Type = TraceType.Bar }, new Trace() { X = new List <object>() { 1, 2, 3, 4 }, Y = new List <object>() { -1, 3, -3, -4 }, Name = "Trace4", Type = TraceType.Bar } } }; ChartControl5.Render(); //------------ // DONUT CHART //------------ ChartControl6.Layout = new Layout() { Title = "Donut Chart [1990-2011]", Annotations = new List <Annotation>() { new Annotation() { Font = new Font() { Size = 16 }, ShowArrow = false, Text = "CO2", X = 0.5, Y = 0.5 } }, Width = 320, Height = 320 }; ChartControl6.Data = new Data() { Traces = new List <Trace>() { new Trace() { Values = new List <object>() { 27, 11, 25, 8, 3, 25 }, Labels = new List <string>() { "US", "China", "EU", "Russia", "India", "Other" }, Text = "CO2", TextPosition = "inside", Domain = new Domain() { X = new List <double>() { 0, 1 } }, Name = "CO2 Emissions", HoverInfo = "label+percent+name", Hole = 0.4, Type = TraceType.Pie } } }; ChartControl6.Render(); }
private void LoadExcel2() { DataTable dt = new DataTable("Chart"); DataColumn dc = new DataColumn("Website", typeof(string)); //DataColumn dc1 = new DataColumn("Validation", typeof(string)); dt.Columns.Add(dc); //dt.Columns.Add(dc1); //DataRow dr = dt.NewRow(); Excel.Application xlApp = null; Excel.Workbook xlWorkBook = null; Excel.Worksheet xlWorkSheet = null; Excel.Range range = null; //Excel.Sheets sheets; //string str1, str2; //int rCnt = 0; //int cCnt = 0; //System.Array[] myvalues; //string[] strArray; object obj; try { xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Open(path1, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); //xlWorkSheet = (Excel.Worksheet)xlWorkBook.ActiveSheet; //sheets = xlWorkBook.Worksheets; //xlWorkSheet = (Excel.Worksheet)sheets.get_Item(1); //xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2); xlWorkSheet = (Excel.Worksheet)xlWorkBook.ActiveSheet; //str1 = xlWorkBook.Name; //str2 = xlWorkSheet.Name; int firstRow = 15; int lastRow = 1331; for (int i = firstRow; i <= lastRow; i++) { range = xlWorkSheet.get_Range("A" + i.ToString(), "Z" + i.ToString()); obj = range.Cells.Value; System.Array myvalues = (System.Array)obj; //myvalues = (System.Array)range.Cells.Value; //strArray = ConvertToStringArray(myvalues); //string str = strArray[1]; DataRow dr1 = dt.NewRow(); string str = myvalues.GetValue(1, 2).ToString(); dr1[0] = str; dt.Rows.Add(dr1); } var result = dt.AsEnumerable() .GroupBy(r => r.Field <string>("Website"), StringComparer.InvariantCultureIgnoreCase) .Select(r => new { Str = r.Key, Count = r.Count() }); //LineChart chart = new LineChart();//Class instance for LineChart //SmoothLineChart chart = new SmoothLineChart();//Class instance for LineChart //AreaChart chart = new AreaChart();//Class instance for LineChart ColumnChart chart = new ColumnChart(); //ScatterChart chart = new ScatterChart(); //StackedColumnChart chart = new StackedColumnChart(); chart.Fill.Color = Color.FromArgb(50, Color.SteelBlue); chart.Fill.Type = InteriorType.Hatch; chart.Fill.HatchStyle = System.Drawing.Drawing2D.HatchStyle.DottedDiamond; chart.Fill.ForeColor = Color.DarkBlue; chart.Line.Width = 1; chart.Line.Color = Color.SteelBlue; chart.ShowLineMarkers = true; chart.DataLabels.Visible = true; //chart.DataLabels.ShowValue = true; //chart.DataLabels.ShowXTitle = true; //chart.DataXValueField = "Websites"; ; //chart.DataYValueField = "Validations"; //chart.Legend = "X Axis: Websites \nY Axis: Validations"; //chart.ShowLegend = true; //looping through datatable and adding to chart control foreach (var item in result) { string str = item.Str; int i = item.Count; chart.Data.Add(new ChartPoint(str, (float)System.Convert.ToSingle(i))); //Console.WriteLine($"{item.Str} : {item.Count}"); } //chart.DataLabels.ForeColor = Color.White; //chart.DataLabels.NumberFormat = "$0.00"; //chart.DataLabels.Position = DataLabelPosition.Center; //chart.DataLabels.Background.Color = Color.SteelBlue; //chart.DataLabels.Border.Color = Color.Red; //chart.DataLabels.Separator = " "; //chart.DataLabels.ShowLegend = true; //chart.DataLabels.MaxPointsWidth = 1; //chart.ShowLineMarkers = true; //chart.LineMarker = new XLineMarker(6, Color.Red, Color.Green); //foreach (DataRow dr2 in dt.Rows) //{ // string str = dr2["Website"].ToString(); // chart.Data.Add(new ChartPoint(dr2["Website"].ToString(), (float)System.Convert.ToSingle(dr2["Validation"]))); //} //ChartEngine engine = new ChartEngine(); //ChartCollection charts = new ChartCollection(engine); //engine.Charts = charts; //engine.TopChartPadding = 20; //charts.Add(chart); ConfigureColors(); ChartControl1.Charts.Clear(); ChartControl1.Charts.Add(chart); ChartControl1.RedrawChart(); xlWorkBook.Close(false, Missing.Value, Missing.Value); xlApp.Quit(); } catch (Exception e) { string str = e.Message; } finally { // Close the Excel process releaseObject(range); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } }
protected void Button2_Click(object sender, EventArgs e) { Label1.Text = "RATING GIVEN TO '" + DropDownList1.SelectedItem.ToString() + "' FOR '" + DropDownList2.SelectedItem.ToString() + "' = " + DropDownList2.SelectedValue.ToString(); Label2.Text = DropDownList1.SelectedItem.ToString(); Label3.Text = DropDownList1.SelectedValue.ToString(); string st = DropDownList2.SelectedItem.ToString(); string ft = DropDownList2.SelectedValue.ToString(); float ft1 = float.Parse(ft); ////LineChart c = new LineChart(); //Chart c = new ColumnChart(); //c.Data.Add(new ChartPoint("", 0)); //c.Data.Add(new ChartPoint(st, ft1)); //c.Data.Add(new ChartPoint("", 0)); //c.Fill.Color = Color.CornflowerBlue; //c.Line.Color = Color.Red; //c.DataLabels.Visible = true; ////ChartControl1.YCustomStart = 0; //ChartControl1.YCustomEnd = 6; ////ChartControl1.YValuesInterval = (float)0.5; //ChartControl1.Charts.Add(c); //ChartControl1.RedrawChart(); //ChartControl1.Visible = true; MapColumnChart cl = new MapColumnChart(); cl.Legend = "User A"; cl.Fill.Color = Color.Blue; cl.DataLabels.Visible = true; // cl.DataLabels.Visible = true; // cl.Legend = DropDownList1.SelectedItem.ToString(); ChartPointCollection data2 = cl.Data; data2.Add(new ChartPoint("", 0)); data2.Add(new ChartPoint(st, ft1)); //data2.Add(new ChartPoint("Mar", 60)); //data2.Add(new ChartPoint("Apr", 40)); //data2.Add(new ChartPoint("May", 30)); //data2.Add(new ChartPoint("Jun", 10)); //data2.Add(new ChartPoint("Jul", 30)); //data2.Add(new ChartPoint("Aug", 20)); //data2.Add(new ChartPoint("Sep", 60)); //data2.Add(new ChartPoint("Oct", 40)); //data2.Add(new ChartPoint("Nov", 20)); //data2.Add(new ChartPoint("Dec", 30)); cl.Rects = new System.Collections.ArrayList(); ChartControl1.Charts.Add(cl); MapColumnChart c2 = new MapColumnChart(); c2.Legend = "User B"; c2.Fill.Color = Color.DarkBlue; data2 = c2.Data; data2.Add(new ChartPoint("", 0)); data2.Add(new ChartPoint(st, 0)); data2.Add(new ChartPoint("", 0)); data2.Add(new ChartPoint("", 0)); data2.Add(new ChartPoint("", 0)); data2.Add(new ChartPoint("", 0)); data2.Add(new ChartPoint("", 0)); data2.Add(new ChartPoint("", 0)); //data2.Add(new ChartPoint("", 0)); //data2.Add(new ChartPoint("", 0)); //data2.Add(new ChartPoint("", 0)); //data2.Add(new ChartPoint("", 0)); c2.Rects = cl.Rects; ChartControl1.Charts.Add(c2); ChartControl1.RedrawChart(); ChartControl1.YCustomEnd = 6; ChartControl1.Visible = true; }