private void Form1_Load(object sender, EventArgs e)
{
string[] cities = { "Chicago", "New York" };
List<CityDataItem> data = GetTemperatureData(cities, true, 7, true);
this.flexChart1.AxisY.Min = data.Select(x => x.Data.Min(y => y.LowTemp)).Min();
this.flexChart1.AxisY.Max = data.Select(x => x.Data.Max(y => y.HighTemp)).Max();
foreach (var dataItem in data)
{
Series series = new Series()
{
Binding = "HighTemp",
BindingX = "Date",
Name = dataItem.Name,
DataSource = dataItem.Data,
};
series.SymbolRendering += Series_SymbolRendering;
this.flexChart1.Series.Add(series);
}
this.flexChart1.DataLabel.Content = "{seriesName}";
this.flexChart1.DataLabel.Position = LabelPosition.Bottom;
this.flexChart1.LabelRendering += FlexChart1_LabelRendering;
this.flexChart1.Header.Content = "Weather Report : Monthly Temperatures";
this.flexChart1.AxisY.Format = "0 °F";
this.flexChart1.Options.ClusterSize = new ElementSize { SizeType = ElementSizeType.Percentage, Value = columnWidthPercentage * 100 };
this.flexChart1.DataLabel.Overlapping = LabelOverlapping.Show;
}
private void FlexChart1_LabelRendering(object sender, RenderDataLabelEventArgs e)
{
var temp = (Temperature)e.Item;
e.Text = string.Format("{0:0}:{1:0}", temp.LowTemp, temp.HighTemp);
}
private void Series_SymbolRendering(object sender, RenderSymbolEventArgs e)
{
e.Cancel = true;
Temperature temperature = (Temperature)e.Item;
var width = this.flexChart1.PlotRect.Width / ((List<Temperature>)this.flexChart1.Series[0].DataSource).Count * columnWidthPercentage / this.flexChart1.Series.Count;
var bottom = 0d;
bottom = this.flexChart1.AxisY.Convert(temperature.LowTemp);
e.Engine.DrawRect(e.Point.X - width / 2 - 2, e.Point.Y, width - 4, bottom - e.Point.Y);
}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim cities As String() = {"Chicago", "New York"}
Dim data As List(Of CityDataItem) = GetTemperatureData(cities, True, 7, True)
'AddressOf Me.flexChart1.AxisY.Min = data.[Select](Function(x) x.Data.Min(Function(y) y.LowTemp)).Min()
'AddressOf Me.flexChart1.AxisY.Max = data.[Select](Function(x) x.Data.Max(Function(y) y.HighTemp)).Max()
For Each dataItem As CityDataItem In data
Dim series As New Series() With {
.Binding = "HighTemp",
.BindingX = "Date",
.Name = dataItem.Name,
.DataSource = dataItem.Data
}
AddHandler series.SymbolRendering, AddressOf Series_SymbolRendering
Me.flexChart1.Series.Add(series)
Next
Me.flexChart1.DataLabel.Content = "{seriesName}"
Me.flexChart1.DataLabel.Position = LabelPosition.Bottom
AddHandler Me.flexChart1.LabelRendering, AddressOf FlexChart1_LabelRendering
Me.flexChart1.Header.Content = "Weather Report : Monthly Temperatures"
Me.flexChart1.AxisY.Format = "0 °F"
Me.flexChart1.Options.ClusterSize = New ElementSize() With {
.SizeType = ElementSizeType.Percentage,
.Value = columnWidthPercentage * 100
}
Me.flexChart1.DataLabel.Overlapping = LabelOverlapping.Show
End Sub
Private Sub FlexChart1_LabelRendering(sender As Object, e As RenderDataLabelEventArgs)
Dim temp As Temperature = DirectCast(e.Item, Temperature)
e.Text = String.Format("{0:0}:{1:0}", temp.LowTemp, temp.HighTemp)
End Sub
Private Sub Series_SymbolRendering(sender As Object, e As RenderSymbolEventArgs)
e.Cancel = True
Dim temperature As Temperature = DirectCast(e.Item, Temperature)
Dim width As Single = Me.flexChart1.PlotRect.Width / DirectCast(Me.flexChart1.Series(0).DataSource, List(Of Temperature)).Count * columnWidthPercentage / Me.flexChart1.Series.Count
Dim bottom As Double = 0.0
bottom = Me.flexChart1.AxisY.Convert(temperature.LowTemp)
e.Engine.DrawRect(e.Point.X - width / 2 - 2, e.Point.Y, width - 4, bottom - e.Point.Y)
End Sub