This section provides step-by-step instructions for building a simple Bar Chart. The graph shows the information as a simple bar chart with one y-axis that represents the numeric values for each product price and the x-axis values provide the spacing between the points and display the label attached to each data point.
The following chart illustration is shown before you begin creating the chart:
To create a Bar Chart at design time
This topic walks you through the steps for creating a simple bar chart using the Chart Properties designer. In this topic you will learn how to set the specific chart type, modify the data series, add data to the chart, and annotate the axes all at design-time in a few simple steps.
This task assumes you have already added the C1Chart control to the form.
The first step in configuring a chart through the smart tag wizard is to select a gallery type from the wealth of chart types available. From basic chart types like Bar and Lines to more complex charts like Polar and Surface, C1Chart allows you to deal with any data visualization needed.
A warning will appear to remind you that you must add data to the new series.
A preview image of the updated chart appears in the lower left pane of the Chart Properties designer.
Next we will annotate the x-axes and y-axes. We will use the value labels annotation for the x axes. For more information on the value labels annotation, see the Value Labels Annotation topic.
A Labels button appears.
To create a Bar chart programmatically
A simple Bar chart can be created programmatically using the following steps:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Imports C1.Win.C1Chart; |
To write code in C#
C# |
Copy Code
|
---|---|
using C1.Win.C1Chart; |
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Clear previous data C1Chart1.ChartGroups(0).ChartData.SeriesList.Clear() ' Add Data Dim ProductNames() As String = {"Hand Mixer", "Stand Mixer", "Can Opener", "Toaster" ,"Blender" ,"Food Processor" ,"Slow Cooker" ,"Microwave"} Dim PriceX() As Integer = {80, 400, 20, 60, 150, 300, 130, 500} ' Create first series Dim ds1 As C1.Win.C1Chart.ChartDataSeries = _ C1Chart1.ChartGroups(0).ChartData.SeriesList.AddNewSeries() ds1.Label = "PriceX" ds1.X.CopyDataIn(ProductNames) ds1.Y.CopyDataIn(PriceX) ' Set chart type c1Chart1.ChartArea.Inverted = True c1Chart1.ChartGroups(0).ChartType = _ c1.Win.C1Chart.Chart2DTypeEnum.Bar ' Set axes titles c1Chart1.ChartArea.AxisX.Text = "Kitchen Electronics" c1Chart1.ChartArea.AxisY.Text = "Price" ' Set format for the Y-axis annotation c1Chart1.ChartArea.AxisY.AnnoFormat = FormatEnum.NumericCurrency End Sub |
To write code in C#
C# |
Copy Code
|
---|---|
private void Form1_Load(object sender, EventArgs e) { // Clear previous data c1Chart1.ChartGroups[0].ChartData.SeriesList.Clear(); // Add Data string[] ProductNames = { "Hand Mixer", "Stand Mixer", "Can Opener", "Toaster" ,"Blender" ,"Food Processor" ,"Slow Cooker" ,"Microwave"}; int[] PriceX = { 80, 400, 20, 60, 150, 300, 130, 500 }; // create single series for product price C1.Win.C1Chart.ChartDataSeries ds1 = c1Chart1.ChartGroups[0].ChartData.SeriesList.AddNewSeries(); ds1.Label = "Price X"; //Use the CopyDataIn method of the ChartDataArray object to copy the X and Y value data into the data series ds1.X.CopyDataIn(ProductNames); ds1.Y.CopyDataIn(PriceX); // Set chart type c1Chart1.ChartArea.Inverted = true; c1Chart1.ChartGroups[0].ChartType = C1.Win.C1Chart.Chart2DTypeEnum.Bar; // Set axes titles c1Chart1.ChartArea.AxisX.Text = "Kitchen Electronics"; c1Chart1.ChartArea.AxisY.Text = "Price"; //Set format for the Y-axis annotation c1Chart1.ChartArea.AxisY.AnnoFormat = FormatEnum.NumericCurrency; } |