i whant join my control ultradatachart with my control ultraleyend yo show only 1 image of the code in my winform
private void Form1_Load(object sender, EventArgs e) { var data = CreateCharts2();
CreteGraphic(data, ultraDataChart1, ultraLegend1, "MS"); CreteGraphic(data, ultraDataChart2, ultraLegend2, "LIT"); CreteGraphic(data, ultraDataChart3, ultraLegend3, "MPR"); CreteGraphic(data, ultraDataChart4, ultraLegend4, "ALL");
}
private void CreteGraphic(DataSet data, UltraDataChart udChart, UltraLegend ultraLegend, string company) { var yAxis1 = new NumericYAxis { LabelLocation = AxisLabelsLocation.OutsideLeft, TickLength = 1, Stroke = new SolidColorBrush {Color = Color.Black}, LabelsVisible = true, }; var categoryXAxis0 = new CategoryXAxis { Label = "wk_nm", LabelLocation = AxisLabelsLocation.OutsideBottom, DataSource = data.Tables[0], Stroke = new SolidColorBrush { Color = Color.Black }, Strip = new SolidColorBrush { Color = Color.LightSkyBlue}, TickStrokeThickness = 3, Interval = .5, LabelAngle = 90 };
//1.this year client //2.this year non-client //3.this year client &non - client //4.last year client //5.last year non-client //6.last year client &non - client
ColumnSeries thisYearClient = CreteSeries( data.Tables[0], $"{company}_this_year_client", $"ThisYr{company}-Client", categoryXAxis0, yAxis1, ultraLegend);
ColumnSeries thisYearNonClient = CreteSeries( data.Tables[1], $"{company}_this_year_nonclient", $"ThisYr{company}-NonClient", categoryXAxis0, yAxis1, ultraLegend);
ColumnSeries thisYearAll = CreteSeries( data.Tables[2], $"{company}_this_year_all", $"ThisYr{company}-All", categoryXAxis0, yAxis1, ultraLegend);
ColumnSeries lastYearClient = CreteSeries( data.Tables[0], $"{company}_this_year_client", $"LastYr{company}-Client", categoryXAxis0, yAxis1, ultraLegend);
ColumnSeries lastYearNonClient = CreteSeries( data.Tables[1], $"{company}_last_year_nonclient", $"LastYr{company}-NonClient", categoryXAxis0, yAxis1, ultraLegend);
ColumnSeries lastYearAll = CreteSeries( data.Tables[2], $"{company}_last_year_all", $"LastYr{company}-All", categoryXAxis0, yAxis1, ultraLegend);
thisYearClient.Brush = new SolidColorBrush { Color = Color.Orange }; thisYearNonClient.Brush = new SolidColorBrush { Color = Color.Green }; thisYearAll.Brush = new SolidColorBrush { Color = Color.Purple }; lastYearClient.Brush = new SolidColorBrush { Color = Color.LightSalmon }; lastYearNonClient.Brush = new SolidColorBrush { Color = Color.LightGreen }; lastYearAll.Brush = new SolidColorBrush { Color = Color.Violet };
udChart.Series.Add(thisYearClient); udChart.Series.Add(thisYearNonClient); udChart.Series.Add(thisYearAll); udChart.Series.Add(lastYearClient); udChart.Series.Add(lastYearNonClient); udChart.Series.Add(lastYearAll);
udChart.Legend = ultraLegend; udChart.Legend.BorderStyle = BorderStyle.FixedSingle; udChart.Legend.Location = new Point(udChart.Right, udChart.Top); udChart.Legend.Size = new System.Drawing.Size(150, udChart.Height); udChart.Legend.BackColor = udChart.BackColor;
udChart.Axes.Add(categoryXAxis0); udChart.Axes.Add(yAxis1);
//udChart.Legend. = Bottom;
udChart.BackColor= new SolidColorBrush { Color =Color.Azure }; udChart.GridMode=GridMode.BehindSeries; udChart.VerticalZoomable = true; udChart.HorizontalZoomable = true; //this.ultraDataChart1.SaveTo(@"C:\Angelo\chart.png", ImageFormat.Png); }
private static ColumnSeries CreteSeries(DataTable data, string field, string title, CategoryXAxis x, NumericYAxis y, UltraLegend ultra) { var columnSeries = new ColumnSeries { DataSource = data, ValueMemberPath = field.ToLower(), Title = title, XAxis = x, YAxis = y, Legend = ultra, LegendItemVisibility = Visibility.Visible, Name = title, }; return columnSeries; }
this is the code i use to create independently
Hello Angelo,
From the code provided it seems that you are creating several UltraDataCharts together with UltraLegends. However, I am not sure what your issue is. In addition, I do not know what CreateCharts2 method does, therefore I am not able to test your code. Can you provide me information about what your aim is as well as what exactly you are not able to achieve? Also, what CreateCharts2 method does – if you can send me the body of this method it will be great.
Looking forward to your reply.
actually i had a control ultradatachart, in this control add 6 series, and in the same time this series feed other control (ultralegend), if you see is 2 controls individual, i want create o manage only 1 control (ultradatachart) and inside this control i wan to see the graphic of 6 series, and additional the legend, i want see the legend on right top of ultradatachart
Thank you for your feedback.
You need only one UltraDataChart, as may add several series to it. Please check this topic in our online documentation for additional information about this “Adding Multiple Series”.
Regarding the legend it is separate control. There is no build in legend in UltraDataChart control. Therefore, you are on the right path. You need to add UltraLegend to your application, position it as you need and add the series it should show. Please check the following article showing how to work with UltraLegend “Chart Legends”.
Please let me know if any additional questions arise.
Hello Milko,
I tried to add a legend to my UltraDataChart with dynamic count of LineSeries. I tried to use a UltraLegend and the UltraItemLegend.
The grid has the property to select the added legend. Unfortunately the legend is empty while adding new Series. The BubbleSeries has a property "LabelMemberPath", which I didn't found while I use LineSeries.
Init DataChart:
private void InitDataChart() { yAxis = new NumericYAxis(); xAxis = new CategoryDateTimeXAxis(); xAxis.Label = "Termin"; xAxis.LabelLocation = AxisLabelsLocation.OutsideBottom; xAxis.DisplayType = TimeAxisDisplayType.Continuous; xAxis.MinimumValue = DateTime.Now - TimeSpan.FromHours(96); xAxis.MaximumValue = DateTime.Now; xAxis.FormatLabel += XAxis_FormatLabel1; yAxis.Label = "Menge"; yAxis.FormatLabel += YAxis_FormatLabel; //ui_DataChart.IsHorizontalZoomEnabled = true; //ui_DataChart.IsVerticalZoomEnabled = true; ui_DataChart.Axes.Add(xAxis); ui_DataChart.Axes.Add(yAxis); }
Handler to Add new Series:
public void NeueWerte(Bestandsverlauf neueWerte) { Grid.ApplyDatasource(neueWerte.BestandsListe); Grid.Grid.DisplayLayout.Bands[0].Columns["VVIS"].CellClickAction = CellClickAction.EditAndSelectText; Grid.Grid.DisplayLayout.Override.AllowUpdate = Infragistics.Win.DefaultableBoolean.True; if (neueWerte.SiloBestandsVerlauf != null) { if (neueWerte.SiloBestandsVerlauf != null) { xAxis.DataSource = neueWerte.SiloBestandsVerlauf.Historie; xAxis.DateTimeMemberPath = "Termin"; var lineSeries = new LineSeries(); lineSeries.ValueMemberPath = _valueMemberPath_; lineSeries.Name = neueWerte.SiloBestandsVerlauf.vPE; lineSeries.XAxis = xAxis; lineSeries.YAxis = yAxis; lineSeries.DataSource = neueWerte.SiloBestandsVerlauf.Historie; lineSeries.Title = neueWerte.SiloBestandsVerlauf.vPE; lineSeries.ShowDefaultTooltip = true; lineSeries.Legend = ultraItemLegend1; ultraItemLegend1.ControlAdded += UltraItemLegend1_ControlAdded; //Didn't fired ui_DataChart.Series.Add(lineSeries); } } Initialized?.Invoke(this, null); }
Presented Class
SiloMengeHist is my DataPointClass. X-Axis = Termin
Y-Axis = Menge
public class SiloHist: Silo { [DataMember] public List<SiloMengeHist> Historie { get; set; } public SiloHist(Silo silo) { Anlage = silo.Anlage; Werk = silo.Werk; Buchungskreis = silo.Buchungskreis; vPE = silo.vPE; Bezeichnung = silo.Bezeichnung; Historie = new List<SiloMengeHist>(); } } [DataContract(Namespace = "PMS.StorageMgmt.Model")] public class Silo { //Anlage [DataMember] public string Buchungskreis { get; set; } [DataMember] public string Werk { get; set; } [DataMember] public string Anlage { get; set; } [DataMember] public string vPE { get; set; } [DataMember] public string Bezeichnung { get; set; } } [DataContract(Namespace = "PMS.StorageMgmt.Model")] public class SiloMengeHist { [DataMember] public string Label { get; set; } [DataMember] public DateTime Termin { get; set; } [DataMember] public Double Menge { get; set; } public SiloMengeHist(DateTime _termin, double _menge, string _label) { Label = _label; Termin = _termin; Menge = _menge; } /// <summary> /// Erstellt aus den Stings einen DateTime Termin und eine double Menge. /// Formatierung für _termin dd.MM.yyyy HH:mm:ss /// </summary> /// <param name="_termin"></param> /// <param name="_menge"></param> public SiloMengeHist(string _termin, string _menge, string _label) { Label = _label; Termin = DateTime.ParseExact(_termin, "dd.MM.yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); Menge = double.Parse(_menge); } } }