public MainWindow() { InitializeComponent(); ThreadPool.QueueUserWorkItem(Connect); OutputChart.Series.Clear(); OutputChart.Axes.Clear(); var readseries = new ColumnSeries { Title = "Read", Background = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0)) }; var writeseries = new ColumnSeries { Title = "Write", Background = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)) }; var diskaxis = new CategoryAxis { Orientation = AxisOrientation.X }; OutputChart.Axes.Add(diskaxis); var iopsaxis = new LinearAxis { Minimum = 0, Maximum = 50, Orientation = AxisOrientation.Y, Title = "IOPS", ExtendRangeToOrigin = true }; OutputChart.Axes.Add(iopsaxis); readseries.IndependentValueBinding = new Binding("Key"); readseries.DependentValueBinding = new Binding("Value"); readseries.ItemsSource = _readdata; writeseries.IndependentValueBinding = new Binding("Key"); writeseries.DependentValueBinding = new Binding("Value"); writeseries.ItemsSource = _writedata; OutputChart.Series.Add(readseries); OutputChart.Series.Add(writeseries); }
/// <summary> /// Acquires an independent axis suitable for use with the data values of the series. /// </summary> /// <returns>Axis instance.</returns> protected override IAxis AcquireIndependentAxis() { IAxis independentAxis = SeriesHost.Axes .Where(a => (a.Orientation == IndependentAxisOrientation) && ((a is ICategoryAxis) || (a is IRangeAxis)) && DataItems.Any() && (a.CanPlot(DataItems.First().ActualIndependentValue))) .FirstOrDefault(); if (null == independentAxis) { independentAxis = new CategoryAxis { Orientation = IndependentAxisOrientation }; } return independentAxis; }
/// <summary> /// Acquires an independent axis suitable for use with the data values of the series. /// </summary> /// <returns>Axis instance.</returns> protected override IAxis AcquireIndependentAxis() { IAxis independentAxis = SeriesHost.Axes .Where(a => (a.Orientation == IndependentAxisOrientation) && ((a is ICategoryAxis) || (a is IRangeAxis)) && DataItems.Any() && (a.CanPlot(DataItems.First().ActualIndependentValue))) .FirstOrDefault(); if (null == independentAxis) { independentAxis = new CategoryAxis { Orientation = IndependentAxisOrientation }; } return(independentAxis); }
private void SetGraph(string strataValue, List<SimpleDataValue> actualValues, List<SimpleDataValue> trendValues, List<SimpleDataValue> aberrationValues, List<DataGridRow> aberrationDetails) { StackPanel chartPanel = new StackPanel(); chartPanel.Margin = (Thickness)this.Resources["genericElementMargin"]; chartPanel.Visibility = System.Windows.Visibility.Collapsed; strataPanelList.Add(chartPanel); if (GadgetOptions.StrataVariableNames.Count == 0) { panelMain.Children.Add(chartPanel); } else { TextBlock txtExpanderHeader = new TextBlock(); txtExpanderHeader.Text = strataValue; txtExpanderHeader.Style = this.Resources["genericOutputExpanderText"] as Style; Expander expander = new Expander(); expander.Margin = (Thickness)this.Resources["expanderMargin"]; //new Thickness(6, 2, 6, 6); expander.IsExpanded = true; expander.Header = txtExpanderHeader; expander.Visibility = System.Windows.Visibility.Collapsed; expander.Content = chartPanel; chartPanel.Tag = txtExpanderHeader.Text; panelMain.Children.Add(expander); strataExpanderList.Add(expander); } Chart chart = new Chart(); LinearAxis dependentAxis = new LinearAxis(); dependentAxis.Orientation = AxisOrientation.Y; dependentAxis.Minimum = 0; dependentAxis.ShowGridLines = true; CategoryAxis independentAxis = new CategoryAxis(); independentAxis.Orientation = AxisOrientation.X; independentAxis.SortOrder = CategorySortOrder.Ascending; independentAxis.AxisLabelStyle = Resources["RotateAxisAberrationStyle"] as Style; chart.PlotAreaStyle = new Style(); chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White)); dependentAxis.GridLineStyle = new Style(); dependentAxis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray)); //System.Windows.Controls.DataVisualization.Charting.Chart.BackgroundProperty try { independentAxis.AxisLabelStyle.Setters.Add(new Setter(AxisLabel.StringFormatProperty, "{0:d}")); } catch (Exception) { //already added } LineSeries series1 = new LineSeries(); series1.IndependentValuePath = "IndependentValue"; series1.DependentValuePath = "DependentValue"; series1.ItemsSource = actualValues; series1.Title = DashboardSharedStrings.GADGET_ABERRATION_ACTUAL; series1.DependentRangeAxis = dependentAxis; series1.IndependentAxis = independentAxis; LineSeries series2 = new LineSeries(); series2.IndependentValuePath = "IndependentValue"; series2.DependentValuePath = "DependentValue"; series2.ItemsSource = trendValues; series2.Title = DashboardSharedStrings.GADGET_ABERRATION_EXPECTED; series2.DependentRangeAxis = dependentAxis; series2.IndependentAxis = independentAxis; series2.PolylineStyle = Resources["GooglePolylineAberrationStyle"] as Style; series2.DataPointStyle = Resources["GoogleDataPointAberrationStyle"] as Style; ScatterSeries series3 = new ScatterSeries(); series3.IndependentValuePath = "IndependentValue"; series3.DependentValuePath = "DependentValue"; series3.ItemsSource = aberrationValues; series3.Title = DashboardSharedStrings.GADGET_ABERRATION; series3.DependentRangeAxis = dependentAxis; series3.IndependentAxis = independentAxis; series3.DataPointStyle = Resources["DataPointAberrationStyle"] as Style; chart.Series.Add(series1); chart.Series.Add(series3); chart.Series.Add(series2); chart.Height = 400; //if (actualValues.Count > 37) //{ // chart.Width = (actualValues.Count * (871.0 / 37.0)) + 129; //} //else //{ // chart.Width = 1000; //} chart.BorderThickness = new Thickness(0); chart.Margin = new Thickness(6, -20, 6, 6); //chart.Width = (actualValues.Count * (871.0 / 37.0)) + 539; //Label title = new Label(); //title.Content = strataValue; //title.Margin = new Thickness(10); //title.FontWeight = FontWeights.Bold; //panelMain.Children.Add(title); //panelMain.Children.Add(chart); ScrollViewer sv = new ScrollViewer(); sv.MaxHeight = 400; sv.MaxWidth = System.Windows.SystemParameters.PrimaryScreenWidth - 125; //if (actualValues.Count > 37) //{ chart.Width = (actualValues.Count * (871.0 / 37.0)) + 229; //} //else //{ // sv.Width = 900; //} sv.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; //sv.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; sv.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left; sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; sv.Content = chart; chartPanel.Children.Add(sv); if (aberrationDetails.Count == 0) { Label noAbberration = new Label(); noAbberration.Content = DashboardSharedStrings.GADGET_NO_ABERRATIONS_FOUND; noAbberration.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; noAbberration.Margin = new Thickness(0, 0, 0, 0); noAbberration.FontWeight = FontWeights.Bold; noAbberration.Foreground = Brushes.Red; //panelMain.Children.Add(noAbberration); chartPanel.Children.Add(noAbberration); } else { Label abberrationFound = new Label(); abberrationFound.Content = DashboardSharedStrings.GADGET_ABERRATIONS_FOUND; abberrationFound.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; abberrationFound.Margin = new Thickness(0, 0, 0, 5); abberrationFound.FontWeight = FontWeights.Bold; abberrationFound.Foreground = Brushes.Red; //panelMain.Children.Add(abberrationFound); chartPanel.Children.Add(abberrationFound); Grid grid = new Grid(); grid.SnapsToDevicePixels = true; grid.HorizontalAlignment = HorizontalAlignment.Center; grid.Margin = new Thickness(0, 0, 0, 0); ColumnDefinition column1 = new ColumnDefinition(); ColumnDefinition column2 = new ColumnDefinition(); ColumnDefinition column3 = new ColumnDefinition(); ColumnDefinition column4 = new ColumnDefinition(); column1.Width = GridLength.Auto; column2.Width = GridLength.Auto; column3.Width = GridLength.Auto; column4.Width = GridLength.Auto; grid.ColumnDefinitions.Add(column1); grid.ColumnDefinitions.Add(column2); grid.ColumnDefinitions.Add(column3); grid.ColumnDefinitions.Add(column4); RowDefinition rowDefHeader = new RowDefinition(); rowDefHeader.Height = new GridLength(25); grid.RowDefinitions.Add(rowDefHeader); //grdFreq.RowDefinitions.Add(rowDefHeader); for (int y = 0; y < /*grdFreq*/grid.ColumnDefinitions.Count; y++) { Rectangle rctHeader = new Rectangle(); rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style; Grid.SetRow(rctHeader, 0); Grid.SetColumn(rctHeader, y); grid.Children.Add(rctHeader); //grdFreq.Children.Add(rctHeader); } TextBlock txtValHeader = new TextBlock(); txtValHeader.Text = DashboardSharedStrings.GADGET_ABERRATION_DATE; txtValHeader.Style = this.Resources["columnHeadingText"] as Style; Grid.SetRow(txtValHeader, 0); Grid.SetColumn(txtValHeader, 0); grid.Children.Add(txtValHeader); //grdFreq.Children.Add(txtValHeader); TextBlock txtFreqHeader = new TextBlock(); txtFreqHeader.Text = DashboardSharedStrings.GADGET_ABERRATION_COUNT; txtFreqHeader.Style = this.Resources["columnHeadingText"] as Style; Grid.SetRow(txtFreqHeader, 0); Grid.SetColumn(txtFreqHeader, 1); grid.Children.Add(txtFreqHeader); //grdFreq.Children.Add(txtFreqHeader); TextBlock txtPctHeader = new TextBlock(); txtPctHeader.Text = DashboardSharedStrings.GADGET_ABERRATION_EXPECTED; txtPctHeader.Style = this.Resources["columnHeadingText"] as Style; Grid.SetRow(txtPctHeader, 0); Grid.SetColumn(txtPctHeader, 2); grid.Children.Add(txtPctHeader); //grdFreq.Children.Add(txtPctHeader); TextBlock txtAccuHeader = new TextBlock(); txtAccuHeader.Text = DashboardSharedStrings.GADGET_ABERRATION_DIFF; txtAccuHeader.Style = this.Resources["columnHeadingText"] as Style; Grid.SetRow(txtAccuHeader, 0); Grid.SetColumn(txtAccuHeader, 3); grid.Children.Add(txtAccuHeader); //panelMain.Children.Add(grid); chartPanel.Children.Add(grid); int rowcount = 1; foreach (DataGridRow aberrationDetail in aberrationDetails) { RowDefinition rowDef = new RowDefinition(); grid.RowDefinitions.Add(rowDef); TextBlock txtDate = new TextBlock(); txtDate.Text = aberrationDetail.Date.ToShortDateString(); txtDate.Margin = new Thickness(2); txtDate.VerticalAlignment = VerticalAlignment.Center; txtDate.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(txtDate, rowcount); Grid.SetColumn(txtDate, 0); grid.Children.Add(txtDate); TextBlock txtFreq = new TextBlock(); txtFreq.Text = aberrationDetail.Frequency.ToString(); txtFreq.Margin = new Thickness(2); txtFreq.VerticalAlignment = VerticalAlignment.Center; txtFreq.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(txtFreq, rowcount); Grid.SetColumn(txtFreq, 1); grid.Children.Add(txtFreq); TextBlock txtAvg = new TextBlock(); txtAvg.Text = aberrationDetail.RunningAverage.ToString("N2"); txtAvg.Margin = new Thickness(2); txtAvg.VerticalAlignment = VerticalAlignment.Center; txtAvg.HorizontalAlignment = HorizontalAlignment.Center; Grid.SetRow(txtAvg, rowcount); Grid.SetColumn(txtAvg, 2); grid.Children.Add(txtAvg); TextBlock txtDelta = new TextBlock(); txtDelta.Text = " " + aberrationDetail.Delta.ToString("N2") + " standard deviations "; StackPanel pnl = new StackPanel(); pnl.Orientation = Orientation.Horizontal; pnl.VerticalAlignment = VerticalAlignment.Center; pnl.HorizontalAlignment = HorizontalAlignment.Center; pnl.Children.Add(txtDelta); Grid.SetRow(pnl, rowcount); Grid.SetColumn(pnl, 3); grid.Children.Add(pnl); rowcount++; } int rdcount = 0; foreach (RowDefinition rd in grid.RowDefinitions) { int cdcount = 0; foreach (ColumnDefinition cd in grid.ColumnDefinitions) { //Rectangle rctBorder = new Rectangle(); //rctBorder.Stroke = Brushes.Black; //Grid.SetRow(rctBorder, rdcount); //Grid.SetColumn(rctBorder, cdcount); //grid.Children.Add(rctBorder); //cdcount++; Border border = new Border(); border.Style = this.Resources["gridCellBorder"] as Style; if (rdcount == 0) { border.BorderThickness = new Thickness(border.BorderThickness.Left, border.BorderThickness.Bottom, border.BorderThickness.Right, border.BorderThickness.Bottom); } if (cdcount == 0) { border.BorderThickness = new Thickness(border.BorderThickness.Right, border.BorderThickness.Top, border.BorderThickness.Right, border.BorderThickness.Bottom); } Grid.SetRow(border, rdcount); Grid.SetColumn(border, cdcount); grid.Children.Add(border); cdcount++; } rdcount++; } } }
/// <summary> /// Acquires an independent axis suitable for use with the data values of the series. /// </summary> /// <returns>Axis instance.</returns> protected override IAxis AcquireIndependentAxis() { IAxis independentAxis = SeriesHost.Axes .Where(a => (a.Orientation == AxisOrientation.X) && ((a is IRangeAxis) || (a is ICategoryAxis)) && DataItems.Any() && (a.CanPlot(DataItems.First().ActualIndependentValue))) .FirstOrDefault(); if (null == independentAxis) { object probeValue = DataItems.Any() ? DataItems.First().ActualIndependentValue : null; double convertedDouble; DateTime convertedDateTime; if ((null != probeValue) && ValueHelper.TryConvert(probeValue, out convertedDouble)) { independentAxis = new LinearAxis(); } else if ((null != probeValue) && ValueHelper.TryConvert(probeValue, out convertedDateTime)) { independentAxis = new DateTimeAxis(); } else { independentAxis = new CategoryAxis(); } independentAxis.Orientation = AxisOrientation.X; } return independentAxis; }
/// <summary> /// Acquire a horizontal linear axis and a vertical linear axis. /// </summary> /// <param name="firstDataPoint">The first data point.</param> protected override void GetAxes(DataPoint firstDataPoint) { GetAxes( firstDataPoint, (axis) => axis.Orientation == AxisOrientation.X, () => { IAxis axis = CreateRangeAxisFromData(firstDataPoint.IndependentValue); if (axis == null) { axis = new CategoryAxis(); } axis.Orientation = AxisOrientation.X; return axis; }, (axis) => axis.Orientation == AxisOrientation.Y && axis is IRangeAxis, () => { DisplayAxis axis = (DisplayAxis)CreateRangeAxisFromData(firstDataPoint.DependentValue); if (axis == null) { throw new InvalidOperationException(Properties.Resources.DataPointSeriesWithAxes_NoSuitableAxisAvailableForPlottingDependentValue); } axis.ShowGridLines = true; axis.Orientation = AxisOrientation.Y; return axis; }); }
/// <summary> /// SortOrderProperty property changed handler. /// </summary> /// <param name="d">CategoryAxis that changed its SortOrder.</param> /// <param name="e">Event arguments.</param> private static void OnSortOrderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { CategoryAxis source = (CategoryAxis)d; source.OnSortOrderPropertyChanged(); }
void dbCol1_GetRecordsCompleted(object sender, GetRecordsCompletedEventArgs e) { if (e.Error == null) { List<EstCol> estCols = GenerateColData1(e.Result); Dictionary<string, ColChart> ColValue = new Dictionary<string, ColChart>(); ColChart chart; foreach (EstCol estcol in estCols) { if (!ColValue.ContainsKey(estcol.Nm)) ColValue.Add(estcol.Nm, new ColChart() { Title = estcol.Nm, ItemSource = new List<EstCol> { new EstCol() { Amount = estcol.Amount, Month = estcol.Month } }, }); else { chart = ColValue[estcol.Nm]; List<EstCol> amt = chart.ItemSource; amt.Add(new EstCol() { Amount = estcol.Amount, Month = estcol.Month }); } } pieChart.Series.Clear(); int i = 0; foreach (KeyValuePair<string, ColChart> kvp in ColValue) { DataPointSeries series = new ColumnSeries(); series.Title = (kvp.Value).Title; series.ItemsSource = (kvp.Value).ItemSource; series.DependentValuePath = "Amount"; series.IndependentValuePath = "Month"; if (i == 0) { Style style = new Style(typeof(Control)); Setter str1 = new Setter(Control.BackgroundProperty, new SolidColorBrush(GetColorFromHexa("#FF938C39"))); style.Setters.Add(str1); series.DataPointStyle = style; } else { Style style = new Style(typeof(Control)); Setter str1 = new Setter(Control.BackgroundProperty, new SolidColorBrush(GetColorFromHexa("#FF70282B"))); style.Setters.Add(str1); series.DataPointStyle = style; } pieChart.Series.Add(series); i++; } CategoryAxis xAxis = new CategoryAxis(); xAxis.Title = "月(" + dateFrom.ToString("yyyy/MM/dd") + " ~ " + dateTo.ToString("yyyy/MM/dd") + ")"; xAxis.SortOrder = CategorySortOrder.Ascending; //xAxis.Orientation = AxisOrientation.X; pieChart.Axes.Add(xAxis); LinearAxis yAxis = new LinearAxis(); yAxis.Title = "金額(万)"; yAxis.Orientation = AxisOrientation.Y; pieChart.Axes.Add(yAxis); yAxis.Minimum = 0; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void dbCol_GetRecordsCompleted(object sender, GetRecordsCompletedEventArgs e) { if (e.Error == null) { List<EstCol> estCols = GenerateColData(e.Result); Dictionary<string, ColChart> ColValue = new Dictionary<string, ColChart>(); ColChart chart; foreach (EstCol estcol in estCols) { if (!ColValue.ContainsKey(estcol.Nm)) ColValue.Add(estcol.Nm, new ColChart() { Title = estcol.Nm, ItemSource = new List<EstCol> { new EstCol() { Amount = estcol.Amount, Month = estcol.Month } }, }); else { chart = ColValue[estcol.Nm]; List<EstCol> amt = chart.ItemSource; amt.Add(new EstCol() { Amount = estcol.Amount, Month = estcol.Month }); } } pieChart3.Series.Clear(); foreach (KeyValuePair<string, ColChart> kvp in ColValue) { DataPointSeries series = new ColumnSeries(); series.Title = (kvp.Value).Title; series.ItemsSource = (kvp.Value).ItemSource; series.DependentValuePath = "Amount"; series.IndependentValuePath = "Month"; pieChart3.Series.Add(series); } CategoryAxis xAxis = new CategoryAxis(); xAxis.Title = "月(" + dateFrom.ToString("yyyy/MM/dd") + " ~ " + dateTo.ToString("yyyy/MM/dd") + ")"; xAxis.SortOrder = CategorySortOrder.Ascending; xAxis.Orientation = AxisOrientation.X; pieChart3.Axes.Add(xAxis); LinearAxis yAxis = new LinearAxis(); yAxis.Title = "金額(万)"; yAxis.Orientation = AxisOrientation.Y; pieChart3.Axes.Add(yAxis); } }
private void RenderFinishSingleChart(List<List<StringDataValue>> stratifiedValues) { waitPanel.Visibility = System.Windows.Visibility.Collapsed; pnlMain.Children.Clear(); Chart chart = new Chart(); chart.Loaded += new RoutedEventHandler(chart_Loaded); chart.BorderThickness = new Thickness(0); LinearAxis dependentAxis = new LinearAxis(); dependentAxis.Minimum = 0; dependentAxis.ShowGridLines = (bool)checkboxShowHorizontalGridLines.IsChecked; CategoryAxis independentAxis = new CategoryAxis(); independentAxis.Orientation = AxisOrientation.X; foreach (List<StringDataValue> dataValues in stratifiedValues) { DataPointSeries series; LineSeries avgSeries = null; switch (((ComboBoxItem)cbxChartType.SelectedItem).Content.ToString()) { case "Bar": series = new BarSeries(); dependentAxis.Orientation = AxisOrientation.X; ((BarSeries)series).DependentRangeAxis = dependentAxis; chart.PlotAreaStyle = new Style(); chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White)); dependentAxis.GridLineStyle = new Style(); dependentAxis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray)); chart.Palette = (System.Collections.ObjectModel.Collection<ResourceDictionary>)this.Resources["defaultBarPalette"]; break; case "Column": series = new ColumnSeries(); if (DashboardHelper.IsColumnText(cbxSingleField.SelectedItem.ToString()) && axisLabelMaxLength > 5) independentAxis.AxisLabelStyle = Resources["RotateAxisStyle90"] as Style; ((ColumnSeries)series).IndependentAxis = independentAxis; dependentAxis.Orientation = AxisOrientation.Y; ((ColumnSeries)series).DependentRangeAxis = dependentAxis; chart.PlotAreaStyle = new Style(); chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White)); dependentAxis.GridLineStyle = new Style(); dependentAxis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray)); chart.Palette = (System.Collections.ObjectModel.Collection<ResourceDictionary>)this.Resources["defaultColumnPalette"]; //series.Effect = this.Resources["shadowEffect"] as System.Windows.Media.Effects.DropShadowEffect; dependentAxis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray)); //<Setter Property="Effect" Value="{StaticResource shadowEffect}"/>--> break; case "Pareto": series = new ColumnSeries(); if (DashboardHelper.IsColumnText(cbxSingleField.SelectedItem.ToString()) && axisLabelMaxLength > 5) independentAxis.AxisLabelStyle = Resources["RotateAxisStyle90"] as Style; ((ColumnSeries)series).IndependentAxis = independentAxis; dependentAxis.Orientation = AxisOrientation.Y; ((ColumnSeries)series).DependentRangeAxis = dependentAxis; LinearAxis percentAxis = new LinearAxis(); percentAxis.Minimum = 0; percentAxis.Maximum = 100; percentAxis.ShowGridLines = (bool)checkboxShowHorizontalGridLines.IsChecked; percentAxis.Orientation = AxisOrientation.Y; percentAxis.Location = AxisLocation.Right; avgSeries = new LineSeries(); avgSeries.IndependentValuePath = "IndependentValue"; avgSeries.DependentValuePath = "CurrentMeanValue"; avgSeries.Title = "Accumulated %"; avgSeries.DependentRangeAxis = percentAxis; avgSeries.IndependentAxis = independentAxis; avgSeries.PolylineStyle = Resources["GooglePolylineStyle"] as Style; avgSeries.DataPointStyle = Resources["GoogleDataPointStyle"] as Style; chart.PlotAreaStyle = new Style(); chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White)); dependentAxis.GridLineStyle = new Style(); dependentAxis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray)); //series.Effect = this.Resources["shadowEffect"] as System.Windows.Media.Effects.DropShadowEffect; chart.Palette = (System.Collections.ObjectModel.Collection<ResourceDictionary>)this.Resources["defaultColumnPalette"]; break; case "Line": series = new LineSeries(); if (DashboardHelper.IsColumnText(cbxSingleField.SelectedItem.ToString()) && axisLabelMaxLength > 5) independentAxis.AxisLabelStyle = Resources["RotateAxisStyle90"] as Style; ((LineSeries)series).IndependentAxis = independentAxis; dependentAxis.Orientation = AxisOrientation.Y; ((LineSeries)series).DependentRangeAxis = dependentAxis; break; case "Pie": if (stratifiedValues.Count > 1) { if (dataValues.Count > 0) { Label lblStrata = new Label(); lblStrata.Margin = new Thickness(0, 10, 0, 0); lblStrata.FontWeight = FontWeights.Bold; lblStrata.Content = dataValues[0].StratificationValue; pnlMain.Children.Add(lblStrata); } } chart = new LabeledPieChart(); chart.Loaded += new RoutedEventHandler(chart_Loaded); chart.BorderThickness = new Thickness(0); series = new LabeledPieSeries(); series.LegendItemStyle = Resources["PieLegendStyle"] as Style; ((LabeledPieSeries)series).PieChartLabelStyle=Resources["pieChartLabelStyle"] as Style; ((LabeledPieSeries)series).PieChartLabelItemTemplate=Resources["pieChartLabelDataTemplate"] as DataTemplate; ((LabeledPieSeries)series).LabelDisplayMode = DisplayMode.Auto; chart.LegendTitle = cbxSingleField.SelectedItem.ToString(); chart.Series.Add(series); chart.Height = 600; chart.Width = 920; chart.Margin = new Thickness(50, 0, 0, 0); chart.PlotAreaStyle = new Style(); chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White)); dependentAxis.GridLineStyle = new Style(); dependentAxis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray)); chart.Palette = (System.Collections.ObjectModel.Collection<ResourceDictionary>)this.Resources["defaultPiePalette"]; pnlMain.Children.Add(chart); break; case "Scatter": series = new ScatterSeries(); dependentAxis.Orientation = AxisOrientation.Y; ((ScatterSeries)series).DependentRangeAxis = dependentAxis; break; default: series = new LineSeries(); dependentAxis.Orientation = AxisOrientation.Y; ((LineSeries)series).DependentRangeAxis = dependentAxis; break; } series.IndependentValuePath = "IndependentValue"; series.DependentValuePath = "DependentValue"; series.ItemsSource = dataValues; if (avgSeries != null) { List<StringDataValue> paretoDataValues = new List<StringDataValue>(dataValues); double max = 0; foreach (StringDataValue sdv in paretoDataValues) { max = max + sdv.DependentValue; } double runningPercent = 0; foreach (StringDataValue sdv in paretoDataValues) { sdv.CurrentMeanValue = ((sdv.DependentValue / max) * 100) + runningPercent; runningPercent = sdv.CurrentMeanValue; } avgSeries.ItemsSource = paretoDataValues; } if (stratifiedValues.Count > 1) { if (!(series is LabeledPieSeries) && cbxStrataField.SelectedIndex > -1) { chart.LegendTitle = cbxStrataField.SelectedItem.ToString(); } if (dataValues.Count > 0 && !IsBooleanWithNoStratas) { series.Title = dataValues[0].StratificationValue.Split('=')[1].Trim(); } else if (dataValues.Count > 0 && IsBooleanWithNoStratas) { series.Title = dataValues[0].StratificationValue.Trim(); chart.LegendTitle = dataValues[0].IndependentValue; } } else { series.Title = "Count"; } if (series is LabeledPieSeries) { //chart.Height = 600; //chart.Width = 800; } else if (series is BarSeries) { if (dataValues.Count > 30) chart.Height = dataValues.Count * 30; else chart.Height = 600; chart.Width = 800; } else { chart.Height = 600; if (dataValues.Count > 20) chart.Width = dataValues.Count * 40; else chart.Width = 800; } if (!(series is LabeledPieSeries)) { chart.Series.Add(series); if (avgSeries != null) { chart.Series.Add(avgSeries); } } /////////////////////////////////////////////////////// string chartSize = "Medium"; if (GadgetOptions == null) { return; } if (GadgetOptions.InputVariableList != null && GadgetOptions.InputVariableList.ContainsKey("chartsize")) { chartSize = GadgetOptions.InputVariableList["chartsize"]; } switch (chartSize) { case "Small": chart.Height = chart.Height / 2; chart.Width = chart.Width / 2; break; case "Medium": chart.Height = chart.Height / 1.5; chart.Width = chart.Width / 1.5; break; case "Custom": if (GadgetOptions.InputVariableList.ContainsKey("chartheight")) { int height; bool success = int.TryParse(GadgetOptions.InputVariableList["chartheight"], out height); if (success) { chart.Height = height; } } if (GadgetOptions.InputVariableList.ContainsKey("chartwidth")) { int width; bool success = int.TryParse(GadgetOptions.InputVariableList["chartwidth"], out width); if (success) { chart.Width = width; } } break; } /////////////////////////////////////////////////////// } if (!((ComboBoxItem)cbxChartType.SelectedItem).Content.ToString().Equals("Pie")) { pnlMain.Children.Add(chart); } }
private void RenderFinishEpiCurve(DataTable data, List<List<StringDataValue>> dataValues) { waitPanel.Visibility = System.Windows.Visibility.Collapsed; StackedHistogramSeries stackedSeries = new StackedHistogramSeries(); LinearAxis axis = new LinearAxis(); axis.Orientation = AxisOrientation.Y; axis.Minimum = 0; axis.ShowGridLines = (bool)checkboxShowHorizontalGridLines.IsChecked; //true; stackedSeries.DependentAxis = axis; CategoryAxis independentAxis = new CategoryAxis(); independentAxis.Orientation = AxisOrientation.X; double extraRightPadding = 0; if (!DashboardHelper.IsColumnNumeric(cbxDateField.SelectedItem.ToString())) { if (cbxXAxisLabelRotation.SelectedIndex == -1 || ((ComboBoxItem)cbxXAxisLabelRotation.SelectedItem).Content.ToString().Equals("90")) { independentAxis.AxisLabelStyle = Resources["RotateAxisStyle90"] as Style; } else if (cbxXAxisLabelRotation.SelectedIndex >= 0 && ((ComboBoxItem)cbxXAxisLabelRotation.SelectedItem).Content.ToString().Equals("45")) { independentAxis.AxisLabelStyle = Resources["RotateAxisStyle45"] as Style; extraRightPadding = 50; } } stackedSeries.IndependentAxis = independentAxis; int counter = 1; foreach (var values in dataValues) { SeriesDefinition definition = new SeriesDefinition(); definition.DependentValuePath = "DependentValue"; definition.IndependentValuePath = "IndependentValue"; if (cbxCaseStatusField.SelectedIndex >= 0 && !string.IsNullOrEmpty(cbxCaseStatusField.SelectedItem.ToString())) { Field field = null; foreach (DataRow fieldRow in DashboardHelper.FieldTable.Rows) { if (fieldRow["columnname"].Equals(cbxCaseStatusField.SelectedItem.ToString())) { if (fieldRow["epifieldtype"] is Field) { field = fieldRow["epifieldtype"] as Field; } break; } } if (field != null && (field is YesNoField || field is CheckBoxField)) { string value = data.Columns[counter].ColumnName; if (value.ToLower().Equals("true") || value.Equals("1")) { definition.Title = DashboardHelper.Config.Settings.RepresentationOfYes; } else if (value.ToLower().Equals("false") || value.Equals("0")) { definition.Title = DashboardHelper.Config.Settings.RepresentationOfNo; } else { definition.Title = cbxCaseStatusField.SelectedItem.ToString(); } } else { definition.Title = data.Columns[counter].ColumnName; } } else { definition.Title = SharedStrings.DEFAULT_CHART_LEGEND_ITEM; } definition.ItemsSource = values; //definition.DataPointStyle = this.Resources["epiCurveDataPointStyle"] as Style; stackedSeries.SeriesDefinitions.Add(definition); counter++; } Chart chart = new Chart(); if (dataValues.Count == 1) { chart.LegendStyle = this.Resources["noLegendStyle"] as Style; } chart.PlotAreaStyle = new Style(); chart.PlotAreaStyle.Setters.Add(new Setter(Chart.BackgroundProperty, Brushes.White)); axis.GridLineStyle = new Style(); axis.GridLineStyle.Setters.Add(new Setter(Line.StrokeProperty, Brushes.LightGray)); chart.Palette = (System.Collections.ObjectModel.Collection<ResourceDictionary>)this.Resources["defaultColumnPalette"]; //stackedSeries chart.BorderThickness = new Thickness(0); chart.Loaded += new RoutedEventHandler(chart_Loaded); chart.Series.Add(stackedSeries); chart.Height = 500; chart.Width = (stackedSeries.IndependentValueCount * 25) + 150; chart.Margin = new Thickness(chart.Margin.Left, chart.Margin.Top, chart.Margin.Right + extraRightPadding, chart.Margin.Bottom); pnlMain.Children.Clear(); pnlMain.Children.Add(chart); SetChartLabels(ChartTitle, LegendTitle, XAxisLabel, YAxisLabel); }
public void UpdateGraph(CalculationOptionsMage calculationOptions) { DisplayCalculations calculations = calculationOptions.Calculations; Chart.Series.Clear(); Chart.Axes.Clear(); Chart.Text = null; if (calculationOptions.SequenceReconstruction == null) { Chart.Text = "Sequence reconstruction data is not available."; } else { List<EffectCooldown> cooldownList = calculationOptions.Calculations.CooldownList; /*brushSubPoints = new Brush[cooldownList.Count]; colorSubPointsA = new Color[cooldownList.Count]; colorSubPointsB = new Color[cooldownList.Count]; for (int i = 0; i < cooldownList.Count; i++) { Color baseColor = cooldownList[i].Color; brushSubPoints[i] = new SolidBrush(Color.FromArgb(baseColor.R / 2, baseColor.G / 2, baseColor.B / 2)); colorSubPointsA[i] = Color.FromArgb(baseColor.A / 2, baseColor.R / 2, baseColor.G / 2, baseColor.B / 2); colorSubPointsB[i] = Color.FromArgb(baseColor.A / 2, baseColor); } StringFormat formatSubPoint = new StringFormat(); formatSubPoint.Alignment = StringAlignment.Center; formatSubPoint.LineAlignment = StringAlignment.Center; int maxWidth = 1; for (int i = 0; i < cooldownList.Count; i++) { string subPointName = cooldownList[i].Name; int widthSubPoint = (int)Math.Ceiling(g.MeasureString(subPointName, fontLegend).Width + 2f); if (widthSubPoint > maxWidth) maxWidth = widthSubPoint; } for (int i = 0; i < cooldownList.Count; i++) { string cooldownName = cooldownList[i].Name; rectSubPoint = new Rectangle(2, legendY, maxWidth, 16); blendSubPoint = new System.Drawing.Drawing2D.ColorBlend(3); blendSubPoint.Colors = new Color[] { colorSubPointsA[i], colorSubPointsB[i], colorSubPointsA[i] }; blendSubPoint.Positions = new float[] { 0f, 0.5f, 1f }; brushSubPointFill = new System.Drawing.Drawing2D.LinearGradientBrush(rectSubPoint, colorSubPointsA[i], colorSubPointsB[i], 67f); brushSubPointFill.InterpolationColors = blendSubPoint; g.FillRectangle(brushSubPointFill, rectSubPoint); g.DrawRectangle(new Pen(brushSubPointFill), rectSubPoint); g.DrawRectangle(new Pen(brushSubPointFill), rectSubPoint); g.DrawRectangle(new Pen(brushSubPointFill), rectSubPoint); g.DrawString(cooldownName, fontLegend, brushSubPoints[i], rectSubPoint, formatSubPoint); legendY += 16; }*/ if (calculationOptions.AdviseAdvancedSolver) { Chart.Text = "Sequence Reconstruction was not fully successful, it is recommended that you enable more options in advanced solver (segment cooldowns, integral mana consumables, advanced constraints options)!"; } /*g.DrawLine(Pens.Aqua, new Point(maxWidth + 40, 10), new Point(maxWidth + 80, 10)); g.DrawString("Mana", fontLegend, Brushes.Black, new Point(maxWidth + 90, 2)); g.DrawLine(Pens.Red, new Point(maxWidth + 40, 26), new Point(maxWidth + 80, 26)); g.DrawString("Dps", fontLegend, Brushes.Black, new Point(maxWidth + 90, 18));*/ List<SequenceItem> sequence = calculationOptions.SequenceReconstruction.sequence; List<TimeData> manaList = new List<TimeData>(); float mana = calculations.StartingMana; int gemCount = 0; float time = 0; Color manaFill = Color.FromArgb(50, 0, 0, 255); float maxMana = calculations.BaseStats.Mana; float maxDps = 100; DateTime baseTime = new DateTime(2000, 1, 1, 0, 0, 0); manaList.Add(new TimeData() { Time = baseTime, Value = mana }); for (int i = 0; i < sequence.Count; i++) { int index = sequence[i].Index; VariableType type = sequence[i].VariableType; float duration = (float)sequence[i].Duration; Cycle cycle = sequence[i].Cycle; CastingState state = sequence[i].CastingState; if (cycle != null) { float dps = (float)cycle.GetDamagePerSecond(state.ManaAdeptBonus, 1); if (dps > maxDps) maxDps = dps; } float mps = (float)sequence[i].Mps; if (sequence[i].IsManaPotionOrGem) { float value = duration; duration = 0; if (sequence[i].VariableType == VariableType.ManaGem) { mana += (float)((1 + calculations.BaseStats.BonusManaGem) * calculations.ManaGemValue * value); gemCount++; } else if (sequence[i].VariableType == VariableType.ManaPotion) { mana += (float)((1 + calculations.BaseStats.BonusManaPotionEffectMultiplier) * calculations.ManaPotionValue * value); } if (mana < 0) mana = 0; if (mana > maxMana) { mana = maxMana; } manaList.Add(new TimeData() { Time = baseTime + TimeSpan.FromSeconds(time) + TimeSpan.FromTicks(1), Value = mana }); } else { /*if (sequence[i].IsEvocation) { switch (sequence[i].VariableType) { case VariableType.Evocation: mps = -(float)calculationOptions.Calculations.EvocationRegen; break; case VariableType.EvocationIV: mps = -(float)calculationOptions.Calculations.EvocationRegenIV; break; case VariableType.EvocationHero: mps = -(float)calculationOptions.Calculations.EvocationRegenHero; break; case VariableType.EvocationIVHero: mps = -(float)calculationOptions.Calculations.EvocationRegenIVHero; break; } }*/ float partTime = duration; if (mana - mps * duration < 0) partTime = mana / mps; else if (mana - mps * duration > maxMana) partTime = (mana - maxMana) / mps; mana -= mps * duration; if (mana < 0) mana = 0; if (mana > maxMana) { mana = maxMana; } manaList.Add(new TimeData() { Time = baseTime + TimeSpan.FromSeconds(time + partTime), Value = mana }); if (partTime < duration) { manaList.Add(new TimeData() { Time = baseTime + TimeSpan.FromSeconds(time + duration), Value = mana }); } } time += duration; } Style dateTimeAxisLabelStyle = new Style(typeof(DateTimeAxisLabel)); dateTimeAxisLabelStyle.Setters.Add(new Setter(DateTimeAxisLabel.MinutesIntervalStringFormatProperty, "{0:m:ss}")); dateTimeAxisLabelStyle.Setters.Add(new Setter(DateTimeAxisLabel.SecondsIntervalStringFormatProperty, "{0:m:ss}")); DateTimeAxis timeAxis = new DateTimeAxis() { //Title = "Time", Minimum = baseTime, Maximum = baseTime + TimeSpan.FromSeconds(calculationOptions.FightDuration), IntervalType = DateTimeIntervalType.Seconds, AxisLabelStyle = dateTimeAxisLabelStyle, Orientation = AxisOrientation.X, ShowGridLines = true, Location = AxisLocation.Top, }; Style hiddenCategoryLabelStyle = new Style(typeof(AxisLabel)); hiddenCategoryLabelStyle.Setters.Add(new Setter(NumericAxisLabel.VisibilityProperty, Visibility.Collapsed)); CategoryAxis categoryAxis = new CategoryAxis() { AxisLabelStyle = hiddenCategoryLabelStyle, Orientation = AxisOrientation.Y, MajorTickMarkStyle = null, }; int barCount = 0; for (int cooldown = 0; cooldown < cooldownList.Count; cooldown++) { List<TimeIntervalData> data = new List<TimeIntervalData>(); //blendSubPoint = new System.Drawing.Drawing2D.ColorBlend(3); //blendSubPoint.Colors = new Color[] { colorSubPointsA[cooldown], colorSubPointsB[cooldown], colorSubPointsA[cooldown] }; //blendSubPoint.Positions = new float[] { 0f, 0.5f, 1f }; bool on = false; float timeOn = 0.0f; time = 0; for (int i = 0; i < sequence.Count; i++) { float duration = (float)sequence[i].Duration; if (sequence[i].IsManaPotionOrGem) duration = 0; if (on && !sequence[i].CastingState.EffectsActive(cooldownList[cooldown]) && !sequence[i].IsManaPotionOrGem) { on = false; if (time > timeOn) { data.Add(new TimeIntervalData() { Start = baseTime + TimeSpan.FromSeconds(timeOn), End = baseTime + TimeSpan.FromSeconds(time), Category = cooldownList[cooldown].Name }); } } else if (!on && sequence[i].CastingState.EffectsActive(cooldownList[cooldown])) { on = true; timeOn = time; } time += duration; } if (on) { if (time - timeOn > 0) { data.Add(new TimeIntervalData() { Start = baseTime + TimeSpan.FromSeconds(timeOn), End = baseTime + TimeSpan.FromSeconds(time), Category = cooldownList[cooldown].Name }); } } if (data.Count > 0) { barCount++; Style timeIntervalStyle = new Style(typeof(TimeIntervalDataPoint)); timeIntervalStyle.Setters.Add(new Setter(TimeIntervalDataPoint.BackgroundProperty, new SolidColorBrush(cooldownList[cooldown].Color))); Chart.Series.Add(new TimeIntervalSeries() { Title = cooldownList[cooldown].Name, ItemsSource = data, IndependentValuePath = "Category", DependentValuePath = "End", StartTimePath = "Start", EndTimePath = "End", DataPointStyle = timeIntervalStyle, DependentRangeAxis = timeAxis, IndependentAxis = categoryAxis }); } } if (calculationOptions.DisplaySegmentCooldowns && calculationOptions.BossHandler) { foreach (var buffState in calculationOptions.Character.BossOptions.BuffStates) { if (buffState.Chance > 0 && buffState.Stats.BonusDamageMultiplier > 0) { List<TimeIntervalData> data = new List<TimeIntervalData>(); foreach (var phase in buffState.PhaseTimes) { data.Add(new TimeIntervalData() { Start = baseTime + TimeSpan.FromSeconds(phase.Value[0]), End = baseTime + TimeSpan.FromSeconds(phase.Value[1]), Category = buffState.Name }); } if (data.Count > 0) { barCount++; Style timeIntervalStyle = new Style(typeof(TimeIntervalDataPoint)); timeIntervalStyle.Setters.Add(new Setter(TimeIntervalDataPoint.BackgroundProperty, new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)))); Chart.Series.Add(new TimeIntervalSeries() { Title = buffState.Name, ItemsSource = data, IndependentValuePath = "Category", DependentValuePath = "End", StartTimePath = "Start", EndTimePath = "End", DataPointStyle = timeIntervalStyle, DependentRangeAxis = timeAxis, IndependentAxis = categoryAxis }); } } } } Style hiddenNumericLabelStyle = new Style(typeof(NumericAxisLabel)); hiddenNumericLabelStyle.Setters.Add(new Setter(NumericAxisLabel.VisibilityProperty, Visibility.Collapsed)); Chart.Series.Add(new AreaSeries() { Title = "Mana", ItemsSource = manaList, IndependentValuePath = "Time", DependentValuePath = "Value", DataPointStyle = (Style)Resources["ManaStyle"], Background = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF)), DependentRangeAxis = new OffsetLinearAxis() { Minimum = 0, Offset = barCount * 10.0, Orientation = AxisOrientation.Y, AxisLabelStyle = hiddenNumericLabelStyle, MajorTickMarkStyle = null, MinorTickMarkStyle = null, }, IndependentAxis = timeAxis, LegendItemStyle = null, }); maxDps *= 1.1f; List<TimeData> list = new List<TimeData>(); time = 0.0f; for (int i = 0; i < sequence.Count; i++) { int index = sequence[i].Index; VariableType type = sequence[i].VariableType; float duration = (float)sequence[i].Duration; Cycle cycle = sequence[i].Cycle; CastingState state = sequence[i].CastingState; float mps = (float)sequence[i].Mps; if (sequence[i].IsManaPotionOrGem) duration = 0; float dps = 0; if (cycle != null) { dps = (float)cycle.DamagePerSecond; } if (duration > 0) { if (calculations.ManaAdeptBonus > 0) { for (int t = 1; t < 10; t++) { DateTime timet = baseTime + TimeSpan.FromSeconds(time + 0.1f * t * duration); if (cycle != null) { dps = (float)cycle.GetDamagePerSecond(calculations.ManaAdeptBonus, GetManaAtTime(manaList, timet) / maxMana); } // apply state multipliers if (calculationOptions.DisplaySegmentCooldowns) { dps *= calculationOptions.GetDamageMultiplier(time, time + duration); } list.Add(new TimeData() { Time = timet, Value = dps }); } } else { // apply state multipliers if (calculationOptions.DisplaySegmentCooldowns) { dps *= calculationOptions.GetDamageMultiplier(time, time + duration); } list.Add(new TimeData() { Time = baseTime + TimeSpan.FromSeconds(time + 0.1f * duration), Value = dps }); list.Add(new TimeData() { Time = baseTime + TimeSpan.FromSeconds(time + 0.9f * duration), Value = dps }); } } time += duration; } Chart.Series.Add(new LineSeries() { Title = "Dps", ItemsSource = list, IndependentValuePath = "Time", DependentValuePath = "Value", DataPointStyle = (Style)Resources["DpsStyle"], DependentRangeAxis = new OffsetLinearAxis() { Offset = barCount * 10.0, Minimum = 0, Orientation = AxisOrientation.Y, AxisLabelStyle = hiddenNumericLabelStyle, MajorTickMarkStyle = null, MinorTickMarkStyle = null, }, IndependentAxis = timeAxis, }); if (zeroLineCanvas == null) { zeroLineCanvas = new ZeroLineCanvas(categoryAxis); zeroLineCanvas.BarCount = barCount; } else { zeroLineCanvas.BarCount = barCount; zeroLineCanvas.Axis = categoryAxis; } ISeriesHost host = (ISeriesHost)Chart; if (!host.BackgroundElements.Contains(zeroLineCanvas)) { host.BackgroundElements.Add(zeroLineCanvas); } } }