Table of Contents

Introduction	1
    Why Second Edition?	    1
    What’s New in Second Edition    1	
        Example Structure	1
        Auto-Implemented Properties 2	
        System.Numerics	3
        Embed JavaScript Chart Library	4
        Embed Gincker Graphics  4	
Overview    5
What this Book Includes	    6
Is this Book for You?	7
What Do You Need to Use this Book?	8
How this Book Is Organized	    8
What is Left Out	9
Use Code Examples	9
Customer Support	9

1	C# Graphics Basics	    11
    1.1	Coordinate Systems	    11
    1.1.1	Default Coordinates	    11
    1.1.2	Custom Coordinates	18
    1.1.3	Window and Viewport	22
        1.1.3.1	Zooming	22
        1.1.3.2	Panning	24
    1.2	Pen and Brush	28
        1.2.1	Pen Class	28
        1.2.2	Brush Class	29
    1.3	Basic Graphics Shapes	29
        1.3.1	Points	30
        1.3.2	Lines and Curves	30
        1.3.3	Rectangles, Ellipses, and Arcs	32
        1.3.4	Polygons	34
1.4	Color	38
    1.4.1	System Colors	39
    1.4.2	Custom Color Map	42
    1.4.3	Color Map with LinearGradientBrush	50
    1.4.4	Color Shading	55

2	2D Matrices and Transformations	63
    2.1	Basics of Matrices and Transformations	63
        2.1.1	Scaling	63
        2.1.2	Reflection	64
        2.1.3	Rotation	65
        2.1.4	Translation	66
    2.2	Homogeneous Coordinates	66
        2.2.1	Translation in Homogeneous Coordinates	66
        2.2.2	Scaling in Homogeneous Coordinates	67
        2.2.3	Rotation in in Homogeneous Coordinates	68
        2.2.4	Combining Transformations	69
    2.3	Matrix Class and Transformation	69
        2.3.1	Matrix Definition in C#	70
        2.3.2	Matrix Operations in C#	72
        2.3.3	Matrix Transformations in C#	75
    2.4	Object Transformations in C#	80
        2.4.1	Basic Transformations#	81
        2.4.2	Combining Transformations in C##	89
        2.4.3	Transformation on Multiple Objects in C#	94
        2.4.4	Text Transformation	99
        2.4.5	Transformations in Graphics Class	102

3	2D Line Charts	107
    3.1	Your First Simple Line Chart	107
        3.1.1	Basic Elements of 2D Line Charts	107
        3.1.2	A Simple 2D Line Chart	108
        3.1.3	How It Works	111
        3.1.4	Change Chart Position	111
    3.2	Create Line Charts Using List	112
        3.2.1	Chart Style	112
        3.2.2	LineStyle Class	114
        3.2.3	Data Series	114
        3.2.4	Data Collection	115
        3.2.5	Test Example	117
    3.3	Gridlines and Labels	119
        3.3.1	Modify ChartStyle Class	119
            3.3.1.1	Gridlines and Ticks	125
            3.3.1.2	Labels and Title	125
        3.3.2	Modify Form Class	126
        3.3.3	Test Example	127
    3.4	Legends	128
        3.4.1	Legend Class	128
        3.4.2	Legend Layout	132
        3.4.3	Test Legend	132
    3.5	Symbols	135
        3.5.1	Define Symbols	135
        3.5.2	Symbol Style Class	136
        3.5.3	Modify LineStyle Class	139
        3.5.4	Modify DataSeries Class	140
        3.5.5	Modify DataCollection Class	141
        3.5.6	Modify Legend Class	142
        3.5.7	Test Symbols	143
    3.6	Line Charts with Two Y-Axes	146
        3.6.1	Why Two Y-Axes	146
        3.6.2	Modify ChartStyle Class	147
        3.6.3	Modify DataSeries Class	153
        3.6.4	Modify DataCollection Class	154
        3.6.5	Test Y2-Axis	156
    3.7	Sub-Charts	159
        3.7.1	Layout of Sub-Charts	159
        3.7.2	SubChart Class	160
        3.7.3	Modify ChartStyle Class	161
        3.7.4	Test Sub-Charts	162

4	Specialized 2D Charts	169
    4.1	Bar Charts	169
        4.1.1	Implementation	169
            4.1.1.1	ChartStyle Class	170
            4.1.1.2	BarStyle Class	176
            4.1.1.3	DataSeries Class	176
            4.1.1.4	DataCollection Class	177
        4.1.2	Test Bar Charts	181
        4.1.3	Group Bar Charts	186
        4.1.4	Overlay Bar Charts	188
        4.1.5	Stacked Bar Charts	190
        4.1.6	Bar Charts with Color Map	191
    4.2	Stair-Step Charts	195
        4.2.1	Implementation	196
        4.2.2	Test Stair-Step Charts	198
        4.3	Stem Charts	200
        4.3.1	Implementation	201
        4.3.2	Test Stem Charts	202
    4.4	Charts with Error Bars	204
        4.4.1	Implementation	204
        4.4.2	Test Error-Bar Charts	206
    4.5	Pie Charts	207
        4.5.1	Implementation	208
            4.5.1.1	ChartStyle Class	208
            4.5.1.2	DataSeries Class	209
            4.5.1.3	Legend Class	211
        4.5.2	Test Pie Charts	213
    4.6	Area Charts	216
        4.6.1	Implementation	216
        4.6.2	Test Area Charts	218
    4.7	Polar Charts	220
        4.7.1	Implementation	220
            4.7.1.1	ChartStyle Class	220
            4.7.1.2	DataCollection Class	223
            4.7.1.3	Legend Class	224
        4.7.2	Test Polar Charts	226
    4.8	Stock Charts	230
        4.8.1	Stock Data from Yahoo Finance API	230
        4.8.2	Implementation	232
        4.8.3	Hi-Lo Chart	234
        4.8.4	Hi-Lo-Open-Close Chart	237
        4.8.5	Candlestick Chart	237

5	3D Matrices and Transformations	239
    5.1	Basics of 3D Matrices and Transformations	239
        5.1.1	3D Vector and Matrix Operations	239
            5.1.1.1	Vector4	240
            5.1.1.2	Matrix4x4	240
        5.1.2	Scaling	241
        5.1.3	Reflection	245
        5.1.4	Translation	246
        5.1.5	Rotation	247
    5.2	Parallel Projections	248
        5.2.1	Orthographic Projections	250
            5.2.1.1	Multi-view Projections	250
            5.2.1.2	Axonometric Projections	251
            5.2.1.3	Orthographic Projections in C#	255
        5.2.2	Oblique Projections	265
            5.2.2.1	Cavalier Projections	266
            5.2.2.2	Cabinet Projections	267
            5.2.2.3	Oblique Projections in C#	267
    5.3	Perspective Projections	272
        5.3.1	One-Point Projections	273
        5.3.2	Two-Point Projections	274
        5.3.3	Three-Point Projections	274
        5.3.4	Perspective Projection Matrix	275
        5.3.5	Perspective Projection in C#	276
    5.4	Special Coordinate Systems in 3D	281
        5.4.1	Cylindrical Coordinate System	281
        5.4.2	Spherical Coordinates	285
        5.4.3	Euler Angles	288
        5.4.4	Azimuth-Elevation View	291

6	3D Charts	299
    6.1	3D chart Basics	299
        6.1.1	3D Chart Style	299
        6.1.2	Point3D Method	301
        6.1.3	Coordinate Axes	303
        6.1.4	Gridlines	308
        6.1.5	Labels	311
        6.1.6	Test 3D Coordinate System	316
    6.2	3D Line Charts	318
        6.2.1	Implementation	319        
        6.2.2	Test 3D Line Chart	321
    6.3	3D Chart Package	324
        6.3.1	ChartStyle2D Class	324
        6.3.2	DataSeries Class	328
        6.3.3	ChartFunctions class	330
        6.3.4	DrawChart Class	333
    6.4	Surface Charts	338
        6.4.1	Mesh Charts	338
        6.4.2	Curtain Charts	347
        6.4.3	Water Fall Charts	349
        6.4.4	Surface Charts	353
        6.4.5	Heat-Map Charts	360
    6.5	Contour Charts	365
        6.5.1	Algorithm	365
        6.5.2	Implementation	366
        6.5.3	Test Contour Charts	369
        6.5.4	Filled Contour Charts	371
    6.6	Combination Charts	372
        6.6.1	Heat-Map Charts in 3D	372
        6.6.2	Contour Charts in 3D	373
        6.6.3	Mesh-Contour Charts	377
        6.6.4	Surface-Contour Charts	378
        6.6.5	Surface-Filled Contour Charts	379
    6.7	3D Bar Charts	380
        6.7.1	Implementation	380
        6.7.2	Test 3D Bar Charts	386
    6.8	Slice Charts	389
        6.8.1	Implementation	390
        6.8.2	Test Slice Charts	392

7	Charts and User Controls	395
    7.1	User Control Basics	395
        7.1.1	Design Time Support	396
        7.1.2	Event Handling	399
    7.2	User Control for 2D Charts	399
        7.2.1	Create User Control	399
        7.2.2	Use TypeConverter	400
        7.2.3	ChartStyle Class	404
        7.2.4	Legend Class	420
        7.2.5	Chart2D Class	425
        7.2.6	Test User Control	429
    7.3	User Control for 3D Charts	438
        7.3.1	ChartStyle Class	439
        7.3.2	Chart3D Class	461
        7.4	Test Chart3D User Control	464
        7.4.1	3D Line Charts	464
        7.4.2	Surface Charts	465
        7.4.3	Contour Charts	468
        7.4.4	Combination Charts	469
        7.4.5	3D Bar Charts	471
        7.4.6	Slice Charts	472

8	Embed JavaScript Charts	474
    8.1	Line Charts	474
        8.1.1	Simple Line Charts	475
        8.1.2	Multiple-Line Charts	478
        8.1.3	Line Charts with Two Y-Axes	480
    8.2	Specialized 2D Charts	484
        8.2.1	Area Charts	484
        8.2.2	Bar Charts	488
        8.2.3	Pie Charts	493
        8.2.4	Polar Charts	497

9	Embed Gincker Graphics	503
    9.1	WebView Control	503
        9.1.1	Install WebView	503
        9.1.2	Use WebView for WinForms	504
    9.2	Introduction to Gincker Graphics	505
        9.2.1	Main Features	505
        9.2.2	Output from Gincker Graphics	506
        9.2.3	Templates for Charts and Graphics	506
        9.2.4	Embed Gincker Graphics within WinForms	507
        9.2.5	Create User Account	509
    9.3	Get Started	509
        9.3.1	Select Template	509
        9.3.2	Layout Window	509
        9.3.3	Input Panel	510
        9.3.4	Chart Area	512
        9.3.5	Customization Panel	512
    9.4	2D Charts	515
        9.4.1	2D Multiple-Line Charts	515
        9.4.2	2D Parametric Charts	517
        9.4.3	Polar Charts	519
        9.4.4	Contour Charts	521
    9.5	3D Charts	524
        9.5.1	3D Line Charts	524
        9.5.2	3D Parametric Surfaces	525
        9.5.3	3D Parametric Shapes	528
        9.5.4	3D Extruded Surfaces	530
        9.5.5	3D Shapes of Revolution	531
        9.5.6	3D Tubes	533
    9.6	Complex-Variable Charts	534
        9.6.1	3D Complex Charts	534
        9.6.2	Complex Heatmap Charts	537
        9.6.3	Domain-Coloring Charts	540
        9.6.4	Iterated-Function Charts	543

Index	547