Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
630
Unable to format dates on X Axis on composite chart
posted

I am simply trying to format the dates on my X Axis and it won't do it.  It can't be this hard...

Here is the code, simply create a form and throw a chart control on it named "Chart", then paste in the code.  I am using the <ITEM_LABEL:MM/dd/yyyy>, but it just ignores it.

How can I format the dates?

Thanks!

------------------------------

Imports Infragistics.UltraChart.Shared.Styles
Imports Infragistics.UltraChart.Resources.Appearance
Imports Infragistics.UltraChart.Core.Layers

Public Class LineChart

    Private dt As DataTable

    Private Sub LineChart_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        BuildDataTable1()

        ' Change Chart type to "composite"
        Chart.ChartType = ChartType.Composite
        Chart.Data.ZeroAligned = True

        ' Add a Chart Area
        Dim myChartArea As New ChartArea()

        myChartArea.Bounds = New Rectangle(20, 10, 75, 80)
        myChartArea.BoundsMeasureType = MeasureType.Percentage

        Chart.CompositeChart.ChartAreas.Add(myChartArea)

        ' Add the Axis to the chart
        Dim axisX As New AxisItem()
        axisX.OrientationType = AxisNumber.X_Axis
        axisX.DataType = AxisDataType.String
        axisX.SetLabelAxisType = SetLabelAxisType.ContinuousData
        axisX.Labels.ItemFormat = AxisItemLabelFormat.ItemLabel
        axisX.Labels.ItemFormatString = "<ITEM_LABEL:MM/dd/yyyy>"
        axisX.Labels.Layout.Padding = 30
        axisX.Labels.Orientation = TextOrientation.Custom
        axisX.Labels.OrientationAngle = 45
        axisX.Labels.Layout.Behavior = AxisLabelLayoutBehaviors.UseCollection

        Dim axisY As New AxisItem()
        axisY.OrientationType = AxisNumber.Y_Axis
        axisY.DataType = AxisDataType.Numeric
        axisY.Labels.ItemFormatString = "<DATA_VALUE:###,###,##0.# ->"
        axisY.Labels.HorizontalAlign = StringAlignment.Far

        myChartArea.Axes.Add(axisX)
        myChartArea.Axes.Add(axisY)

        ' Add the series data
        Dim series1 As New NumericSeries()
        series1.Label = "Walmart"
        series1.Data.DataSource = dt
        series1.Data.LabelColumn = "MONTH"
        series1.Data.ValueColumn = "WALMART"
        Chart.CompositeChart.Series.Add(series1)

        Dim series2 As New NumericSeries()
        series2.Label = "Target"
        series2.Data.DataSource = dt
        series2.Data.LabelColumn = "MONTH"
        series2.Data.ValueColumn = "TARGET"
        Chart.CompositeChart.Series.Add(series2)

        Dim series3 As New NumericSeries()
        series3.Label = "CVS"
        series3.Data.DataSource = dt
        series3.Data.LabelColumn = "MONTH"
        series3.Data.ValueColumn = "CVS"
        Chart.CompositeChart.Series.Add(series3)

        ' Add a Chart Layer
        Dim ChartLayer As New ChartLayerAppearance()

        ChartLayer.ChartType = ChartType.LineChart

        ChartLayer.ChartArea = myChartArea
        ChartLayer.AxisX = axisX
        ChartLayer.AxisY = axisY
        ChartLayer.Series.Add(series1)
        ChartLayer.Series.Add(series2)
        ChartLayer.Series.Add(series3)
        Chart.CompositeChart.ChartLayers.Add(ChartLayer)

        ' Add a Legend
        Dim myLegend As New CompositeLegend()
        myLegend.ChartLayers.Add(ChartLayer)
        myLegend.Bounds = New Rectangle(0, 10, 20, 25)
        myLegend.BoundsMeasureType = MeasureType.Percentage
        myLegend.PE.ElementType = PaintElementType.Gradient
        myLegend.PE.FillGradientStyle = GradientStyle.Circular
        myLegend.PE.Fill = Color.Cornsilk
        myLegend.PE.FillStopColor = Color.White
        myLegend.Border.CornerRadius = 10
        myLegend.Border.Thickness = 0
        Chart.CompositeChart.Legends.Add(myLegend)

   End Sub

    Private Sub BuildDataTable1()

        Dim dc As DataColumn = Nothing
        Dim dr As DataRow = Nothing

        dt = New DataTable

        dc = New DataColumn("MONTH", GetType(System.DateTime))
        dt.Columns.Add(dc)
        dc = New DataColumn("WALMART", GetType(System.Decimal))
        dt.Columns.Add(dc)
        dc = New DataColumn("TARGET", GetType(System.Decimal))
        dt.Columns.Add(dc)
        dc = New DataColumn("CVS", GetType(System.Decimal))
        dt.Columns.Add(dc)

        dr = dt.NewRow
        dr.Item("MONTH") = New DateTime(2011, 1, 1)
        dr.Item("WALMART") = 120000
        dr.Item("TARGET") = 100000
        dr.Item("CVS") = 77000
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr.Item("MONTH") = New DateTime(2011, 2, 1)
        dr.Item("WALMART") = 55000
        dr.Item("TARGET") = 75000
        dr.Item("CVS") = 90000
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr.Item("MONTH") = New DateTime(2011, 3, 1)
        dr.Item("WALMART") = 20000
        dr.Item("TARGET") = 25000
        dr.Item("CVS") = 35000
        dt.Rows.Add(dr)

        dr = dt.NewRow
        dr.Item("MONTH") = New DateTime(2011, 4, 1)
        dr.Item("WALMART") = 150000
        dr.Item("TARGET") = 175000
        dr.Item("CVS") = 180000
        dt.Rows.Add(dr)

    End Sub

End Class