Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MyNS
- {
- public partial class ChartDoubleTimeControl : UserControl
- {
- private List<List<KeyValuePair<DateTime, double>>> m_DataCollection;
- private List<SolidColorBrush> m_Palette;
- private string m_LegendVisibility;
- public ChartDoubleTimeControl()
- {
- InitializeComponent();
- DataContext = this;
- m_DataCollection = null;
- m_Palette = new List<SolidColorBrush>();
- m_Palette.Add(Brushes.Green);
- m_Palette.Add(Brushes.Red);
- m_Palette.Add(Brushes.Blue);
- m_Palette.Add(Brushes.Yellow);
- m_Palette.Add(Brushes.Gray);
- m_Palette.Add(Brushes.Orange);
- }
- public string LegendVisibility
- {
- get { return m_LegendVisibility; }
- set { m_LegendVisibility = value; }
- }
- public void RefreshChart()
- {
- this.Dispatcher.Invoke((Action)(() =>
- {
- LoadChartData();
- }));
- }
- public void setDataCollection(List<List<KeyValuePair<DateTime, double>>> nDataCollection, List<string> nLegend, bool isSeries)
- {
- m_DataCollection = nDataCollection;
- if (isSeries)
- {
- for (int i = (LineChart.Series.Count - 1); i > -1; i--)
- {
- LineChart.Series.Remove(LineChart.Series[i]);
- }
- }
- LineSeries mySeries = null;
- if (!isSeries)
- {
- LegendVisibility = "0";
- }
- else
- {
- LegendVisibility = "Auto";
- }
- if (isSeries)
- {
- for (int i = 0; i < m_DataCollection.Count; i++)
- {
- if (nLegend.Count > 0)
- {
- mySeries = new LineSeries();
- mySeries.DependentValuePath = "Value";
- mySeries.IndependentValuePath = "Key";
- mySeries.ItemsSource = m_DataCollection[i];
- mySeries.Title = nLegend[i];
- Style style = new Style { TargetType = typeof(LineDataPoint) };
- style.Setters.Add(new Setter(ColumnDataPoint.BackgroundProperty, m_Palette[i]));
- mySeries.DataPointStyle = style;
- LineChart.Series.Add(mySeries);
- }
- }
- }
- else
- {
- SeriesColumn.ItemsSource = m_DataCollection[0];
- }
- }
- public void LoadChartData()
- {
- MyHelper resultHelper = new MyHelper();
- LineChart.Title = "Title";
- List<List<KeyValuePair<DateTime, double>>> DataCollection = new List<List<KeyValuePair<DateTime, double>>>();
- DataCollection.Add(new List<KeyValuePair<DateTime, double>>());
- List<string> Legend = new List<string>();
- bool isSeries = false;
- Dictionary<DateTime, double> result = resultHelper.GetPoints();
- for (int i = 0; i < result.Count; i++)
- DataCollection[0].Add(new KeyValuePair<DateTime, double>(result.ElementAt(i).Key, result.ElementAt(i).Value));
- isSeries = false;
- setDataCollection(DataCollection, Legend, isSeries);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- RefreshChart();
- }
- }
- }
Add Comment
Please, Sign In to add comment