protected void Page_Load(object sender, EventArgs e) { ChartSession cs = SessionManager.ChartSession; if (!cs.IsEmpty()) { LineChartConfig cfg = cs.ChartConfig as LineChartConfig; if (cs.Name == SessionChartName.P2Hour || cs.Name == SessionChartName.PDuringWL || cs.Name == SessionChartName.PDuringFlux || cs.Name == SessionChartName.PDuringAmount) { CreateLineConfig(cfg, cs.DataSource); //LineChartConfig cfg = Create(cs.DataSource); } //if (cs.Name == SessionChartName.PDuringWL) //{ // LineChartConfig cfg = cs.ChartConfig as LineChartConfig; // CreateLineConfig(cfg, cs.DataSource); //} //if (cs.Name == "...") //{ //} ChartFactory f = new ChartFactory(); OpenFlashChart.OpenFlashChart chart = f.Create(cs.DataSource as DataTable, cfg); Response.Write(chart.ToString()); } }
///// <summary> ///// ///// </summary> ///// <param name="cfg"></param> ///// <param name="p"></param> //private void CreateLineConfigPDuring(LineChartConfig cfg, object dataSource) //{ // DataTable tbl = dataSource as DataTable; // ColorProvider cp = new ColorProvider(); // for( int i=1; //} /// <summary> /// /// </summary> /// <param name="p"></param> /// <returns></returns> private void CreateLineConfig(LineChartConfig cfg, object datasource) { // tbl 表格样式 // ---------------------------------------------------------- // DT | st1 | st2 | st3 | st4 | ... // ---------------------------------------------------------- // 2011-1-1 12:00:00 | 12 | 23 | 17 | 5 | ... // 2011-1-1 12:00:00 | 12 | 23 | 17 | 5 | ... // 2011-1-1 12:00:00 | 12 | 23 | 17 | 5 | ... // ... // // st - 站名称 // DataTable tbl = datasource as DataTable; ColorProvider cp = new ColorProvider(); // create line data configs // 生成除第一列(时间列)意外的所有列的曲线配置 // for (int i = 1; i < tbl.Columns.Count; i++) { DataColumn col = tbl.Columns[i]; string name = col.ColumnName; LineDataConfig ldcfg = new LineDataConfig(name, name, cp.GetNextColorString()); cfg.LineDataConfigCollection.Add(ldcfg); } }
/// <summary> /// /// </summary> public void Bind() { ChartSession cs = SessionManager.ChartSession; DataTable[] tbls = cs.DataSource as DataTable[]; int no = 0; foreach (DataTable tbl in tbls) { LineChartConfig cfg = new LineChartConfig( tbl.TableName, "时间", "水位....", "DT"); LineDataConfig item = new LineDataConfig( tbl.TableName, "wl1", new ColorProvider().GetNextColorString()); cfg.LineDataConfigCollection.Add(item); ChartSessionManager manager = SessionManager.ChartSessionManager; ChartSession itemcs = manager.GetChartSession(no); itemcs.ChartConfig = cfg; itemcs.DataSource = tbl; UCChart uc = GetUCChartByNO(no); uc.Bind(GetChartDataPageName(no)); uc.Show(); //this.Controls.Add(uc); no++; } }
/// <summary> /// /// </summary> /// <param name="dataSource"></param> /// <param name="lcCfg"></param> public void SetLineChartInfo(object dataSource, string filterColumn, string dateTimeColumn, string dataColumn, string title, string yTitle) { //string chartTitle = "2001-1-1 12:00:00 ~ 2001-1-1 12:00:00 一干渠 水位曲线"; //this.LineChart1.Series.Clear(); ////this.LineChart1.Graphs.Clear(); //if (LineChart1.Graphs.Count > 0) //{ // this.LineChart1.Graphs[0].Items.Clear(); //} this.LineChart1.Labels.Clear(); //this.LineChart1 = new LineChart(); //this.LineChart1 = new LineChart(); ChartLabel titleLabel = new ChartLabel(title, 60, 20, false, 600, LabelAlignments.Center, System.Drawing.Color.Black, 18); this.LineChart1.Labels.Add(titleLabel); ChartLabel yLabel = new ChartLabel(yTitle, 5, 150, true, 20, LabelAlignments.Center, System.Drawing.Color.Black, 12); this.LineChart1.Labels.Add(yLabel); DataTable source = dataSource as DataTable; DataTable convertedTable = DataTableConverter.ConvertRowToColumn(source, filterColumn, dataColumn, dateTimeColumn); LineChartConfig lccfg = new LineChartConfig(); lccfg.DataSeriesIDField = dateTimeColumn; lccfg.YLeftValueMin = 0; foreach (DataColumn col in convertedTable.Columns) { if (!StringHelper.Equal(col.ColumnName, dateTimeColumn)) { LineGraphItemConfig item = new LineGraphItemConfig(); item.DataValueField = col.ColumnName; item.Title = col.ColumnName; item.Color = GetLineColor(col.ColumnName); lccfg.LineGraphItemConfigCollection.Add(item); } } //Sort(lccfg.LineGraphItemConfigCollection); lccfg.LineGraphItemConfigCollection.Sort(this.StationOrderList); convertedTable.DefaultView.Sort = dateTimeColumn; LineGraphSetter.Set(this.LineChart1, lccfg, convertedTable.DefaultView, FormatStringManager.FloatValueFormatString); this.ColumnChart1.Visible = false; this.LineChart1.Visible = true; }
protected void Page_Load(object sender, EventArgs e) { int i = 2 - 1; ChartSession cs = SessionManager.ChartSessionManager.GetChartSession(i); LineChartConfig cfg = cs.ChartConfig as LineChartConfig; ChartFactory f = new ChartFactory(); OpenFlashChart.OpenFlashChart chart = f.Create(cs.DataSource as DataTable, cfg); Response.Write(chart.ToString()); }
public void DesiredUseCase() { LineChartConfig config = new LineChartConfig(); // Must use reference types to take advantage of type variance in C# LineChartDataset <string> intDataset = new LineChartDataset <string>(); // Using the non-interface method to add the range, you can still mutate the object intDataset.AddRange(new[] { "1", "2", "3", "4", "5" }); // Your original code works fine when reference types are used config.ChartData.Datasets.Add(intDataset); }
protected override async Task OnInitAsync() { AppMetrics = await Http.GetJsonAsync <AppMetric[]>($"api/Metrics/{App.AppId}/{StartDay}/{EndDay}"); AppMetrics = AppMetrics.Reverse().ToArray(); var labels = AppMetrics.Select(x => DateTimeOffset.FromUnixTimeSeconds(x.EpochTime).LocalDateTime.ToString("MM/dd")).ToList(); var points = AppMetrics.Select(x => x.OperationCount).OfType <object>().ToList(); lineChartConfig = CardChartData.GetLineConfig("Operations by day", App.AppId, labels, points); lineChartJs = new ChartJsLineChart(); }
protected override async Task OnInitAsync() { ChartConfig = new LineChartConfig(); var chartData = await Client.GetAsync("/api/prices/ChartData"); ChartConfig = chartData.IsSuccessStatusCode ? await BuildChartConfig(chartData) : new LineChartConfig(); // LineChartJs.Reload(); }
/// <summary> /// /// </summary> /// <param name="dataSource"></param> /// <param name="lcCfg"></param> public void SetDayLineChartInfo(object dataSource, string filterColumn, string dateTimeColumn, string dataColumn, string title, string yTitle) { this.LineChart1.Labels.Clear(); ChartLabel titleLabel = new ChartLabel(title, 60, 20, false, 600, LabelAlignments.Center, System.Drawing.Color.Black, 18); this.LineChart1.Labels.Add(titleLabel); ChartLabel yLabel = new ChartLabel(yTitle, 5, 150, true, 20, LabelAlignments.Center, System.Drawing.Color.Black, 12); this.LineChart1.Labels.Add(yLabel); DataTable source = dataSource as DataTable; DataTable convertedTable = DataTableConverter.ConvertRowToColumn(source, filterColumn, dataColumn, dateTimeColumn); LineChartConfig lccfg = new LineChartConfig(); lccfg.DataSeriesIDField = dateTimeColumn; lccfg.YLeftValueMin = 0; foreach (DataColumn col in convertedTable.Columns) { if (!StringHelper.Equal(col.ColumnName, dateTimeColumn)) { LineGraphItemConfig item = new LineGraphItemConfig(); item.DataValueField = col.ColumnName; item.Title = col.ColumnName; item.Color = GetLineColor(col.ColumnName); lccfg.LineGraphItemConfigCollection.Add(item); } } convertedTable.DefaultView.Sort = dateTimeColumn; //LineGraphSetter.Set(this.LineChart1, lccfg, convertedTable.DefaultView); DataTable xAxisDataSource = GetDayXAxisDataSource(convertedTable, dateTimeColumn); xAxisDataSource.DefaultView.Sort = dateTimeColumn; LineGraphSetter.Set(this.LineChart1, lccfg, convertedTable.DefaultView, xAxisDataSource.DefaultView, FormatStringManager.FloatValueFormatString); this.ColumnChart1.Visible = false; this.LineChart1.Visible = true; }
/// <summary> /// /// </summary> private void f2(DataTable tbl) { LineChartConfig cfg = new LineChartConfig( "use line chart config", "x title(X轴承)", "Y title(Y轴承)", "DT"); //cfg.XSegmentCount LineDataConfig ldc = new LineDataConfig("line1", "wl1","#00ff00"); LineDataConfig ldc2 = new LineDataConfig("line2", "wl2", "#0000ff"); //ldc2.Name = "line2"; //ldc2.DataFieldName = "wl2"; cfg.LineDataConfigCollection.Add(ldc); cfg.LineDataConfigCollection.Add(ldc2); OpenFlashChart.OpenFlashChart chart = new ChartFactory().Create(tbl, cfg); Response.Write(chart.ToString()); }
/// <summary> /// /// </summary> private void f2(DataTable tbl) { LineChartConfig cfg = new LineChartConfig( "use line chart config", "x title(X轴承)", "Y title(Y轴承)", "DT"); //cfg.XSegmentCount LineDataConfig ldc = new LineDataConfig("line1", "wl1", "#00ff00"); LineDataConfig ldc2 = new LineDataConfig("line2", "wl2", "#0000ff"); //ldc2.Name = "line2"; //ldc2.DataFieldName = "wl2"; cfg.LineDataConfigCollection.Add(ldc); cfg.LineDataConfigCollection.Add(ldc2); OpenFlashChart.OpenFlashChart chart = new ChartFactory().Create(tbl, cfg); Response.Write(chart.ToString()); }
public static Task <bool> UpdateLineChart(LineChartConfig lineChart) { return(JSRuntime.Current.InvokeAsync <bool>("ChartJSInterop.UpdateChart", lineChart)); }
public static Task <bool> InitializeLineChart(LineChartConfig lineChartConfig) { return(JSRuntime.Current.InvokeAsync <bool>("ChartJSInterop.InitializeChart", lineChartConfig)); }
public static Task <bool> ReloadLineChart(LineChartConfig lineChartConfig) { return(JSRuntime.Current.InvokeAsync <bool>("ChartJSInterop.ReloadChart", lineChartConfig)); }
private async Task <LineChartConfig> BuildChartConfig(HttpResponseMessage responseMessage) { var contentString = await responseMessage.Content.ReadAsStringAsync(); var chartData = Json.Deserialize <ChartData>(contentString); var buildChartConfig = new LineChartConfig { CanvasId = "myFirstLineChart", Options = new LineChartOptions { Text = "Item Prices", Display = true, Responsive = true, Title = new OptionsTitle { Display = true, Text = "Item Prices" }, Legend = new Legend { Position = LegendPosition.TOP.ToString(), Labels = new Labels { UsePointStyle = true, } }, Hover = new LineChartOptionsHover() { Intersect = true, Mode = Mode.nearest }, Tooltips = new Tooltips { Mode = Mode.nearest, Intersect = true }, }, Data = new LineChartData { Labels = chartData.Labels, Datasets = new List <LineChartDataset>() } }; foreach (var dataSet in chartData.DataSets) { var chartDataSet = new LineChartDataset { Label = dataSet.Label, BackgroundColor = GetRandomColor(), BorderColor = GetRandomColor(), BorderWidth = 2, PointRadius = 3, PointBorderWidth = 1, Data = new List <object>() }; foreach (var datum in dataSet.Data) { chartDataSet.Data.Add(datum); } buildChartConfig.Data.Datasets.Add(chartDataSet); } return(buildChartConfig); }