How do I hand-write code to generate a Composite chart?

Source: Internet
Author: User

The previous blog article introduced the entire process of creating columnlinechart using the chart wizard. columnlinechart belongs to a simple chart. You can create a composite chart using similar wizard steps. For more information, see chart_creating_a_composite_chart_using_the _ chart_wizard.

Since you can customize the composite chart through the wizard, you can use the code writing method to generate the composite chart! For more information about this process, see chart_creating_a_composite_chart_in code_part.
However, if your English is not good enough or you need some guidance, please refer to this Section. This article describes how to generate a conforming chart using handwritten code, in the meantime, the attribute settings are commented out based on my understanding. If you still don't understand it, we recommend that you try to modify the attribute value and then generate a chart. The specific implementation code is as follows, you only need to copy it and add it in the page_load event, and then drag an ultrachart to the page.
// Define the data source and set the series according to its convenience
Datatable dt = new datatable ();
DT. Columns. Add ("col1", typeof (INT ));
DT. Columns. Add ("col2", typeof (INT ));
DT. Columns. Add ("col3", typeof (INT ));
Dt. Columns. Add ("col4", typeof (string ));
Dt. Rows. Add (new object [] {2, 14, 12, "H1 "});
Dt. Rows. Add (new Object [] {0, 11, 10, "H2 "});
Dt. Rows. Add (new Object [] {1, 9, 11, "H3 "});
Dt. Rows. Add (new Object [] {0, 10, 11, "H4 "});
Dt. Rows. Add (new Object [] {4, 12, 9, "H5 "});
Dt. Rows. Add (new Object [] {1, 11, 10, "H6 "});
Dt. Rows. Add (new Object [] {1, 8, 7, "H7 "});
Dt. Rows. Add (new Object [] {5, 10, 10, "H8 "});

// The following describes how to generate a Composite:

// Step 1: Set the UltraChart1 chart to Composite
This. UltraChart1.ChartType = ChartType. Composite;

// Step 2: Create a chart area ChartArea and add a chart area in the UltraChart1 chart combination.
ChartArea area = new ChartArea ();
This. UltraChart1.CompositeChart. ChartAreas. Add (area );

// Step 3: Create the X, X2, and Y axes and add them to the chart area.
// Create the X axis, which is required for Composite ColumnChart
AxisItem xAxisColumn = new AxisItem ();
XAxisColumn. OrientationType = AxisNumber. X_Axis;
XAxisColumn. DataType = AxisDataType. String;
XAxisColumn. SetLabelAxisType = Infragistics. UltraChart. Core. Layers. SetLabelAxisType. GroupBySeries;
XAxisColumn. Labels. ItemFormat = AxisItemLabelFormat. ItemLabel;
XAxisColumn. Extent = 20;
// Create the Y axis. Both ColumnChart and LineChart of Composite are required.
AxisItem yAxis = new AxisItem ();
YAxis. OrientationType = AxisNumber. Y_Axis;
YAxis. DataType = AxisDataType. Numeric;
YAxis. Labels. ItemFormat = AxisItemLabelFormat. DataValue;
YAxis. RangeType = AxisRangeType. Custom;
YAxis. RangeMin = 0;
YAxis. RangeMax = 20;
YAxis. Extent = 20;
// Create the X2 axis. The LineChart of Composite is required.
AxisItem xAxisLine = new AxisItem ();
XAxisLine. OrientationType = AxisNumber. X2_Axis;
XAxisLine. DataType = AxisDataType. String;
XAxisLine. SetLabelAxisType = Infragistics. UltraChart. Core. Layers. SetLabelAxisType. ContinuousData;
XAxisLine. Labels. ItemFormat = AxisItemLabelFormat. ItemLabel;
XAxisLine. Extent = 20;
// Add the axis to the drawing Area
Area. Axes. Add (xAxisColumn );
Area. Axes. Add (xAxisLine );
Area. Axes. Add (yAxis );

// Step 4: create a number of consecutive curve point instances and set their values
// Generate a series for ColumnChart
NumericSeries seriesColumn = new NumericSeries ();
// Data tag Value
SeriesColumn. Label = "";
SeriesColumn. Data. DataSource = dt;
// Tag information displayed online
SeriesColumn. Data. LabelColumn = "col4 ";
// Value to be displayed on the chart
SeriesColumn. Data. ValueColumn = "col2 ";
SeriesColumn. DataBind ();
// Generate a series for ColumnChart
NumericSeries seriesColumn2 = new NumericSeries ();
// Data tag Value
SeriesColumn2.Label = "B ";
SeriesColumn2.Data. DataSource = dt;
// Tag information displayed online
SeriesColumn2.Data. LabelColumn = "col4 ";
// Value to be displayed on the chart
SeriesColumn2.Data. ValueColumn = "col3 ";
SeriesColumn2.DataBind ();
// Generate a series for LineChart
NumericSeries seriesLine = new NumericSeries ();
SeriesLine. Data. DataSource = dt;
// Tag information displayed online
SeriesLine. Data. LabelColumn = "col4 ";
// Value to be displayed on the chart
SeriesLine. Data. ValueColumn = "col1 ";
SeriesLine. DataBind ();
This. UltraChart1.Series. Add (seriesLine );
This. UltraChart1.Series. Add (seriesColumn );
This. UltraChart1.Series. Add (seriesColumn2 );

// Step 5: Create a chart style (appearance) and add it to the layers set
// The Chart style of ColumnChart
ChartLayerAppearance ColumnLayer = new ChartLayerAppearance ();
ColumnLayer. AxisX = xAxisColumn;
ColumnLayer. AxisY = yAxis;
ColumnLayer. ChartArea = area;
// Set the chart type and ColumnChart bar chart
ColumnLayer. ChartType = ChartType. ColumnChart;
ColumnLayer. Series. Add (seriesColumn );
ColumnLayer. Series. Add (seriesColumn2 );
// LineChart chart Style
ChartLayerAppearance LineLayer = new ChartLayerAppearance ();
LineLayer. AxisX = xAxisLine;
LineLayer. AxisY = yAxis;
LineLayer. ChartArea = area;
// Set the chart type and LineChart
LineLayer. ChartType = ChartType. LineChart;
LineLayer. Series. Add (seriesLine );
This. UltraChart1.CompositeChart. ChartLayers. Add (ColumnLayer );
This. UltraChart1.CompositeChart. ChartLayers. Add (LineLayer );

The Composite Chart generated based on the above Code is as follows:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.