//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WPFChartViewer viewer, int chartIndex) { // The data for the chart double[] data0 = { 100, 100, 100, 100, 100 }; double[] data1 = { 90, 85, 85, 80, 70 }; double[] data2 = { 80, 65, 65, 75, 45 }; // The labels for the chart string[] labels = { "Population<*br*><*font=Arial*>6 millions", "GDP<*br*><*font=Arial*>120 billions", "Export<*br*><*font=Arial*>25 billions", "Import<*br*><*font=Arial*>24 billions", "Investments<*br*><*font=Arial*>20 billions" }; // Create a PolarChart object of size 480 x 460 pixels. Set background color to silver, // with 1 pixel 3D border effect PolarChart c = new PolarChart(480, 460, Chart.silverColor(), 0x000000, 1); // Add a title to the chart using 15pt Times Bold Italic font. The title text is white // (ffffff) on a deep green (008000) background c.addTitle("Economic Growth", "Times New Roman Bold Italic", 15, 0xffffff ).setBackground(0x008000); // Set plot area center at (240, 270), with 150 pixels radius c.setPlotArea(240, 270, 150); // Use 1 pixel width semi-transparent black (c0000000) lines as grid lines c.setGridColor(unchecked ((int)0xc0000000), 1, unchecked ((int)0xc0000000), 1); // Add a legend box at top-center of plot area (240, 35) using horizontal layout. Use // 10pt Arial Bold font, with silver background and 1 pixel 3D border effect. LegendBox b = c.addLegend(240, 35, false, "Arial Bold", 10); b.setAlignment(Chart.TopCenter); b.setBackground(Chart.silverColor(), Chart.Transparent, 1); // Add area layers of different colors to represent the data c.addAreaLayer(data0, 0xcc8880, "Year 2004"); c.addAreaLayer(data1, 0xffd080, "Year 1994"); c.addAreaLayer(data2, 0xa0bce0, "Year 1984"); // Set the labels to the angular axis as spokes. c.angularAxis().setLabels(labels); // Set radial axis from 0 - 100 with a tick every 20 units c.radialAxis().setLinearScale(0, 100, 20); // Just show the radial axis as a grid line. Hide the axis labels by setting the label // color to Transparent c.radialAxis().setColors(unchecked ((int)0xc0000000), Chart.Transparent); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='Current {label}: {value}% in {dataSetName}'"); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // Data for the chart double[] data0 = { 5, 3, 10, 4, 3, 5, 2, 5 }; double[] data1 = { 12, 6, 17, 6, 7, 9, 4, 7 }; double[] data2 = { 17, 7, 22, 7, 18, 13, 5, 11 }; double[] angles = { 0, 45, 90, 135, 180, 225, 270, 315 }; string[] labels = { "North", "North\nEast", "East", "South\nEast", "South", "South\nWest", "West", "North\nWest" }; // Create a PolarChart object of size 460 x 500 pixels, with a grey // (e0e0e0) background and a 1 pixel 3D border PolarChart c = new PolarChart(460, 500, 0xe0e0e0, 0x000000, 1); // Add a title to the chart at the top left corner using 15pts Arial Bold // Italic font. Use white text on deep blue background. c.addTitle("Wind Direction", "Arial Bold Italic", 15, 0xffffff ).setBackground(0x000080); LegendBox legendBox = c.addLegend(230, 35, false, "Arial Bold", 9); legendBox.setAlignment(Chart.TopCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent, 1); legendBox.addKey("5 m/s or above", 0xff3333); legendBox.addKey("1 - 5 m/s", 0x33ff33); legendBox.addKey("less than 1 m/s", 0x3333ff); // Set plot area center at (230, 280) with radius 180 pixels and white // background c.setPlotArea(230, 280, 180, 0xffffff); // Set the grid style to circular grid c.setGridStyle(false); // Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale2(0, 360, labels); for (int i = 0; i < angles.Length; ++i) { c.angularAxis().addZone(angles[i] - 10, angles[i] + 10, 0, data0[i], 0x3333ff, 0); c.angularAxis().addZone(angles[i] - 10, angles[i] + 10, data0[i], data1[i], 0x33ff33, 0); c.angularAxis().addZone(angles[i] - 10, angles[i] + 10, data1[i], data2[i], 0xff3333, 0); } // Add an Transparent invisible layer to ensure the axis is auto-scaled // using the data c.addLineLayer(data2, Chart.Transparent); // Output the chart viewer.Image = c.makeImage(); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // Data for the chart double[] data0 = { 5, 3, 10, 4, 3, 5, 2, 5 }; double[] data1 = { 12, 6, 17, 6, 7, 9, 4, 7 }; double[] data2 = { 17, 7, 22, 7, 18, 13, 5, 11 }; string[] labels = { "North", "North<*br*>East", "East", "South<*br*>East", "South", "South<*br*>West", "West", "North<*br*>West" }; // Create a PolarChart object of size 460 x 500 pixels, with a grey // (e0e0e0) background and 1 pixel 3D border PolarChart c = new PolarChart(460, 500, 0xe0e0e0, 0x000000, 1); // Add a title to the chart at the top left corner using 15pts Arial Bold // Italic font. Use a wood pattern as the title background. c.addTitle("Polar Area Chart Demo", "Arial Bold Italic", 15 ).setBackground(c.patternColor("wood.png")); // Set center of plot area at (230, 280) with radius 180 pixels, and // white (ffffff) background. c.setPlotArea(230, 280, 180, 0xffffff); // Set the grid style to circular grid c.setGridStyle(false); // Add a legend box at top-center of plot area (230, 35) using horizontal // layout. Use 10 pts Arial Bold font, with 1 pixel 3D border effect. LegendBox b = c.addLegend(230, 35, false, "Arial Bold", 9); b.setAlignment(Chart.TopCenter); b.setBackground(Chart.Transparent, Chart.Transparent, 1); // Set angular axis using the given labels c.angularAxis().setLabels(labels); // Specify the label format for the radial axis c.radialAxis().setLabelFormat("{value}%"); // Set radial axis label background to semi-transparent grey (40cccccc) c.radialAxis().setLabelStyle().setBackground(0x40cccccc, 0); // Add the data as area layers c.addAreaLayer(data2, -1, "5 m/s or above"); c.addAreaLayer(data1, -1, "1 - 5 m/s"); c.addAreaLayer(data0, -1, "less than 1 m/s"); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{label}] {dataSetName}: {value}%'"); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // The data for the chart double[] data0 = { 90, 60, 85, 75, 55 }; double[] data1 = { 60, 80, 70, 80, 85 }; // The labels for the chart string[] labels = { "Speed", "Reliability", "Comfort", "Safety", "Efficiency" }; // Create a PolarChart object of size 480 x 380 pixels. Set background // color to gold, with 1 pixel 3D border effect PolarChart c = new PolarChart(480, 380, Chart.goldColor(), 0x000000, 1); // Add a title to the chart using 15 pts Times Bold Italic font. The // title text is white (ffffff) on a deep blue (000080) background c.addTitle("Space Travel Vehicles Compared", "Times New Roman Bold Italic", 15, 0xffffff).setBackground(0x000080); // Set plot area center at (240, 210), with 150 pixels radius, and a // white (ffffff) background. c.setPlotArea(240, 210, 150, 0xffffff); // Add a legend box at top right corner (470, 35) using 10 pts Arial Bold // font. Set the background to silver, with 1 pixel 3D border effect. LegendBox b = c.addLegend(470, 35, true, "Arial Bold", 10); b.setAlignment(Chart.TopRight); b.setBackground(Chart.silverColor(), Chart.Transparent, 1); // Add an area layer to the chart using semi-transparent blue // (0x806666cc). Add a blue (0x6666cc) line layer using the same data // with 3 pixel line width to highlight the border of the area. c.addAreaLayer(data0, unchecked ((int)0x806666cc), "Model Saturn"); c.addLineLayer(data0, 0x6666cc).setLineWidth(3); // Add an area layer to the chart using semi-transparent red // (0x80cc6666). Add a red (0xcc6666) line layer using the same data with // 3 pixel line width to highlight the border of the area. c.addAreaLayer(data1, unchecked ((int)0x80cc6666), "Model Jupiter"); c.addLineLayer(data1, 0xcc6666).setLineWidth(3); // Set the labels to the angular axis as spokes. c.angularAxis().setLabels(labels); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{dataSetName}] {label}: score = {value}'"); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // Sample data for the Box-Whisker chart. Represents the minimum, 1st // quartile, medium, 3rd quartile and maximum values of some quantities double[] Q0Data = { 40, 45, 40, 30, 20, 50, 25, 44 }; double[] Q1Data = { 55, 60, 50, 40, 38, 60, 51, 60 }; double[] Q2Data = { 62, 70, 60, 50, 48, 70, 62, 70 }; double[] Q3Data = { 70, 80, 65, 60, 53, 78, 69, 76 }; double[] Q4Data = { 80, 90, 75, 70, 60, 85, 80, 84 }; // The labels for the chart string[] labels = { "Group A", "Group B", "Group C", "Group D", "Group E", "Group F", "Group G", "Group H" }; // Create a XYChart object of size 550 x 250 pixels XYChart c = new XYChart(550, 275); // Set the plotarea at (50, 25) and of size 450 x 200 pixels. Enable both // horizontal and vertical grids by setting their colors to grey // (0xc0c0c0) c.setPlotArea(50, 50, 450, 200).setGridColor(0xc0c0c0, 0xc0c0c0); // Add a title to the chart c.addTitle("Computer Vision Test Scores"); // Set the labels on the x axis and the font to Arial Bold c.xAxis().setLabels(labels).setFontStyle("Arial Bold"); // Set the font for the y axis labels to Arial Bold c.yAxis().setLabelStyle("Arial Bold"); // Add a Box Whisker layer using light blue 0x9999ff as the fill color // and blue (0xcc) as the line color. Set the line width to 2 pixels c.addBoxLayer(Q4Data, Q3Data, 0x00ff00, "Top 25%"); c.addBoxLayer(Q3Data, Q2Data, 0x9999ff, "25% - 50%"); c.addBoxLayer(Q2Data, Q1Data, 0xffff00, "50% - 75%"); c.addBoxLayer(Q1Data, Q0Data, 0xff0000, "Bottom 25%"); // Add legend box at top center above the plot area using 10 pts Arial // Bold Font LegendBox b = c.addLegend(50 + 225, 22, false, "Arial Bold", 10); b.setAlignment(Chart.TopCenter); b.setBackground(Chart.Transparent); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{xLabel} ({dataSetName}): {bottom} to {top} points'"); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // The data for the chart double[] data = { 51, 15, 51, 40, 17, 87, 94, 21, 35, 88, 50, 60 }; // The labels for the chart string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" }; // Create a PolarChart object of size 400 x 420 pixels PolarChart c = new PolarChart(400, 420); // Set background color to a 2 pixel pattern color, with a black border // and 1 pixel 3D border effect c.setBackground(c.patternColor(new int[] { 0xffffff, 0xe0e0e0 }, 2), 0, 1); // Add a title to the chart using 16 pts Arial Bold Italic font. The // title text is white (0xffffff) on 2 pixel pattern background c.addTitle("Chemical Concentration", "Arial Bold Italic", 16, 0xffffff ).setBackground(c.patternColor(new int[] { 0x000000, 0x000080 }, 2)); // Set center of plot area at (200, 240) with radius 145 pixels. Set // background color to blue (9999ff) c.setPlotArea(200, 240, 145, 0x9999ff); // Color the region between radius = 40 to 80 as green (99ff99) c.radialAxis().addZone(40, 80, 0x99ff99); // Color the region with radius > 80 as red (ff9999) c.radialAxis().addZone(80, 999, 0xff9999); // Set the grid style to circular grid c.setGridStyle(false); // Set the radial axis label format c.radialAxis().setLabelFormat("{value} ppm"); // Use semi-transparent (40ffffff) label background so as not to block // the data c.radialAxis().setLabelStyle().setBackground(0x40ffffff, 0x40000000); // Add a legend box at (200, 30) top center aligned, using 9 pts Arial // Bold font. with a black border. LegendBox legendBox = c.addLegend(200, 30, false, "Arial Bold", 9); legendBox.setAlignment(Chart.TopCenter); // Add legend keys to represent the red/green/blue zones legendBox.addKey("Under-Absorp", 0x9999ff); legendBox.addKey("Normal", 0x99ff99); legendBox.addKey("Over-Absorp", 0xff9999); // Add a blue (000080) spline line layer with line width set to 3 pixels // and using yellow (ffff00) circles to represent the data points PolarSplineLineLayer layer = c.addSplineLineLayer(data, 0x000080); layer.setLineWidth(3); layer.setDataSymbol(Chart.CircleShape, 11, 0xffff00); // Set the labels to the angular axis as spokes. c.angularAxis().setLabels(labels); // Output the chart viewer.Image = c.makeImage(); // Include tool tip for the chart. viewer.ImageMap = layer.getHTMLImageMap("clickable", "", "title='Concentration on {label}: {value} ppm'"); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // the names of the tasks string[] labels = { "Market Research", "Define Specifications", "Overall Archiecture", "Project Planning", "Detail Design", "Software Development", "Test Plan", "Testing and QA", "User Documentation" }; // the planned start dates and end dates for the tasks DateTime[] startDate = { new DateTime(2004, 8, 16), new DateTime(2004, 8, 30), new DateTime(2004, 9, 13), new DateTime(2004, 9, 20), new DateTime(2004, 9, 27), new DateTime(2004, 10, 4), new DateTime( 2004, 10, 25), new DateTime(2004, 11, 1), new DateTime(2004, 11, 8) }; DateTime[] endDate = { new DateTime(2004, 8, 30), new DateTime(2004, 9, 13 ), new DateTime(2004, 9, 27), new DateTime(2004, 10, 4), new DateTime(2004, 10, 11), new DateTime(2004, 11, 8), new DateTime( 2004, 11, 8), new DateTime(2004, 11,22), new DateTime(2004, 11, 22) } ; // the actual start dates and end dates for the tasks up to now DateTime[] actualStartDate = { new DateTime(2004, 8, 16), new DateTime( 2004, 8, 27), new DateTime(2004,9, 9), new DateTime(2004, 9, 18), new DateTime(2004, 9, 22) }; DateTime[] actualEndDate = { new DateTime(2004, 8, 27), new DateTime(2004, 9, 9), new DateTime(2004, 9,27), new DateTime(2004, 10, 2), new DateTime(2004, 10, 8) }; // Create a XYChart object of size 620 x 280 pixels. Set background color // to light green (ccffcc) with 1 pixel 3D border effect. XYChart c = new XYChart(620, 280, 0xccffcc, 0x000000, 1); // Add a title to the chart using 15 points Times Bold Itatic font, with // white (ffffff) text on a dark green (0x6000) background c.addTitle("Mutli-Layer Gantt Chart Demo", "Times New Roman Bold Italic", 15, 0xffffff).setBackground(0x006000); // Set the plotarea at (140, 55) and of size 460 x 200 pixels. Use // alternative white/grey background. Enable both horizontal and vertical // grids by setting their colors to grey (c0c0c0). Set vertical major // grid (represents month boundaries) 2 pixels in width c.setPlotArea(140, 55, 460, 200, 0xffffff, 0xeeeeee, Chart.LineColor, 0xc0c0c0, 0xc0c0c0).setGridWidth(2, 1, 1, 1); // swap the x and y axes to create a horziontal box-whisker chart c.swapXY(); // Set the y-axis scale to be date scale from Aug 16, 2004 to Nov 22, // 2004, with ticks every 7 days (1 week) c.yAxis().setDateScale(new DateTime(2004, 8, 16), new DateTime(2004, 11, 22), 86400 * 7); // Add a red (ff0000) dash line to represent the current day c.yAxis().addMark(Chart.CTime(new DateTime(2004, 10, 8)), c.dashLineColor(0xff0000, Chart.DashLine)); // Set multi-style axis label formatting. Month labels are in Arial Bold // font in "mmm d" format. Weekly labels just show the day of month and // use minor tick (by using '-' as first character of format string). c.yAxis().setMultiFormat(Chart.StartOfMonthFilter(), "<*font=Arial Bold*>{value|mmm d}", Chart.StartOfDayFilter(), "-{value|d}"); // Set the y-axis to shown on the top (right + swapXY = top) c.setYAxisOnRight(); // Set the labels on the x axis c.xAxis().setLabels(labels); // Reverse the x-axis scale so that it points downwards. c.xAxis().setReverse(); // Set the horizontal ticks and grid lines to be between the bars c.xAxis().setTickOffset(0.5); // Use blue (0000aa) as the color for the planned schedule int plannedColor = 0x0000aa; // Use a red hash pattern as the color for the actual dates. The pattern // is created as a 4 x 4 bitmap defined in memory as an array of colors. int actualColor = c.patternColor(new int[] { 0xffffff, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xffffff }, 4); // Add a box whisker layer to represent the actual dates. We add the // actual dates layer first, so it will be the top layer. BoxWhiskerLayer actualLayer = c.addBoxLayer(Chart.CTime(actualStartDate), Chart.CTime(actualEndDate), actualColor, "Actual"); // Set the bar height to 8 pixels so they will not block the bottom bar actualLayer.setDataWidth(8); // Add a box-whisker layer to represent the planned schedule date c.addBoxLayer(Chart.CTime(startDate), Chart.CTime(endDate), plannedColor, "Planned").setBorderColor(Chart.SameAsMainColor); // Add a legend box on the top right corner (595, 60) of the plot area // with 8 pt Arial Bold font. Use a semi-transparent grey (80808080) // background. LegendBox b = c.addLegend(595, 60, false, "Arial Bold", 8); b.setAlignment(Chart.TopRight); b.setBackground(unchecked ((int)0x80808080), -1, 2); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{xLabel} ({dataSetName}): {top|mmm dd, yyyy} to " + "{bottom|mmm dd, yyyy}'"); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // The data for the chart double[] data0 = { 90, 25, 40, 55, 68, 44, 79, 85, 50 }; double[] angles0 = { 15, 60, 110, 180, 230, 260, 260, 310, 340 }; double[] data1 = { 80, 91, 66, 80, 92, 87 }; double[] angles1 = { 40, 65, 88, 110, 150, 200 }; // Create a PolarChart object of size 460 x 500 pixels, with a grey (e0e0e0) background and 1 // pixel 3D border PolarChart c = new PolarChart(460, 500, 0xe0e0e0, 0x000000, 1); // Add a title to the chart at the top left corner using 15pt Arial Bold Italic font. Use a // wood pattern as the title background. c.addTitle("Polar Line Chart Demo", "Arial Bold Italic", 15).setBackground(c.patternColor( Url.Content("~/Content/wood.png"))); // Set center of plot area at (230, 280) with radius 180 pixels, and white (ffffff) // background. c.setPlotArea(230, 280, 180, 0xffffff); // Set the grid style to circular grid, with grids below the chart layers c.setGridStyle(false, false); // Add a legend box at top-center of plot area (230, 35) using horizontal layout. Use 10pt // Arial Bold font, with 1 pixel 3D border effect. LegendBox b = c.addLegend(230, 35, false, "Arial Bold", 9); b.setAlignment(Chart.TopCenter); b.setBackground(Chart.Transparent, Chart.Transparent, 1); // Set angular axis as 0 - 360, with a spoke every 30 units c.angularAxis().setLinearScale(0, 360, 30); // Add a blue (0xff) line layer to the chart using (data0, angle0) PolarLineLayer layer0 = c.addLineLayer(data0, 0x0000ff, "Close Loop Line"); layer0.setAngles(angles0); // Set the line width to 2 pixels layer0.setLineWidth(2); // Use 11 pixel triangle symbols for the data points layer0.setDataSymbol(Chart.TriangleSymbol, 11); // Enable data label and set its format layer0.setDataLabelFormat("({value},{angle})"); // Set the data label text box with light blue (0x9999ff) backgruond color and 1 pixel 3D // border effect layer0.setDataLabelStyle().setBackground(0x9999ff, Chart.Transparent, 1); // Add a red (0xff0000) line layer to the chart using (data1, angle1) PolarLineLayer layer1 = c.addLineLayer(data1, 0xff0000, "Open Loop Line"); layer1.setAngles(angles1); // Set the line width to 2 pixels layer1.setLineWidth(2); // Use 11 pixel diamond symbols for the data points layer1.setDataSymbol(Chart.DiamondSymbol, 11); // Set the line to open loop layer1.setCloseLoop(false); // Enable data label and set its format layer1.setDataLabelFormat("({value},{angle})"); // Set the data label text box with light red (0xff9999) backgruond color and 1 pixel 3D // border effect layer1.setDataLabelStyle().setBackground(0xff9999, Chart.Transparent, 1); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='[{dataSetName}] ({radius}, {angle})'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, int chartIndex) { // The data for the line chart double[] data0 = { 70, 73, 80, 90, 95, 93, 82, 77, 82, 101, 111, 115 }; double[] data1 = { 90, 96, 89, 77, 82, 96, 109, 109, 99, 108, 96, 91 }; double[] data2 = { 58, 34, 25, 49, 64, 10, 16, 40, 25, 49, 40, 22 }; // The labels for the line chart string[] labels = { "2008-01", "2008-02", "2008-03", "2008-04", "2008-05", "2008-06", "2008-07", "2008-08", "2008-09", "2008-10", "2008-11", "2008-12" }; // Create a XYChart object of size 450 x 450 pixels XYChart c = new XYChart(450, 450); // Add a title to the chart using 15pt Arial Italic font. ChartDirector.TextBox title = c.addTitle("Inter-line Coloring", "Arial Italic", 15); // Add a legend box where the top-center is anchored to the horizontal center of the // chart, just under the title. Use horizontal layout and 10 points Arial Bold font, and // transparent background and border. Use line style legend key. LegendBox legendBox = c.addLegend(c.getWidth() / 2, title.getHeight(), false, "Arial Bold Italic", 10); legendBox.setBackground(Chart.Transparent, Chart.Transparent); legendBox.setAlignment(Chart.TopCenter); legendBox.setLineStyleKey(); // Tentatively set the plotarea at (70, 65) and of (chart_width - 100) x (chart_height - // 110) in size. Use light grey (c0c0c0) border and horizontal and vertical grid lines. PlotArea plotArea = c.setPlotArea(70, 65, c.getWidth() - 100, c.getHeight() - 110, -1, -1, 0xc0c0c0, 0xc0c0c0, -1); // Add a title to the y axis using 12pt Arial Bold Italic font c.yAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12); // Add a title to the x axis using 12pt Arial Bold Italic font c.xAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12); // Set the axes line width to 3 pixels c.xAxis().setWidth(3); c.yAxis().setWidth(3); // Set the labels on the x axis. c.xAxis().setLabels(labels); // Use 8 points Arial rotated by 90 degrees as the x-axis label font c.xAxis().setLabelStyle("Arial", 8, Chart.TextColor, 90); // Add a spline curve to the chart SplineLayer layer0 = c.addSplineLayer(data0, 0xff0000, "Data Set 0"); layer0.setLineWidth(2); // Add a normal line to the chart LineLayer layer1 = c.addLineLayer(data1, 0x008800, "Data Set 1"); layer1.setLineWidth(2); // Color the region between the above spline curve and normal line. Use the // semi-transparent red (80ff000000) if the spline curve is higher than the normal line, // otherwise use semi-transparent green (80008800) c.addInterLineLayer(layer0.getLine(), layer1.getLine(), unchecked ((int)0x80ff0000), unchecked ((int)0x80008800)); // Add another normal line to the chart LineLayer layer2 = c.addLineLayer(data2, 0x0000ff, "Data Set 2"); layer2.setLineWidth(2); // Add a horizontal mark line to the chart at y = 40 Mark mark = c.yAxis().addMark(40, -1, "Threshold"); mark.setLineWidth(2); // Set the mark line to purple (880088) dash line. Use white (ffffff) for the mark // label. mark.setMarkColor(c.dashLineColor(0x880088), 0xffffff); // Put the mark label at the left side of the mark, with a purple (880088) background. mark.setAlignment(Chart.Left); mark.setBackground(0x880088); // Color the region between the above normal line and mark line. Use the // semi-transparent blue (800000ff) if the normal line is higher than the mark line, // otherwise use semi-transparent purple (80880088) c.addInterLineLayer(layer2.getLine(), mark.getLine(), unchecked ((int)0x800000ff), unchecked ((int)0x80880088)); // Layout the legend box, so we can get its height c.layoutLegend(); // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10 // pixels from the left edge, just under the legend box, 25 pixels from the right edge, // and 10 pixels from the bottom edge. c.packPlotArea(10, legendBox.getTopY() + legendBox.getHeight(), c.getWidth() - 25, c.getHeight() - 10); // After determining the exact plot area position, we may adjust the legend box and the // title positions so that they are centered relative to the plot area (instead of the // chart) legendBox.setPos(plotArea.getLeftX() + (plotArea.getWidth() - legendBox.getWidth()) / 2, legendBox.getTopY()); title.setPos(plotArea.getLeftX() + (plotArea.getWidth() - title.getWidth()) / 2, title.getTopY()); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} in {xLabel}: {value}'"); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // The data for the pie chart double[] data = { 25, 18, 15, 12, 8, 30, 35 }; // The labels for the pie chart string[] labels = { "Labor", "Licenses", "Taxes", "Legal", "Insurance", "Facilities", "Production" }; // Create a PieChart object of size 600 x 320 pixels. Set background // color to brushed silver, with a 2 pixel 3D border. Use rounded corners // of 20 pixels radius. PieChart c = new PieChart(600, 320, Chart.brushedSilverColor(), Chart.Transparent, 2); c.setRoundedFrame(0xffffff, 20); // Add a title using 18 pts Times New Roman Bold Italic font. #Set // top/bottom margins to 8 pixels. ChartDirector.TextBox title = c.addTitle("Donut Chart Demonstration", "Times New Roman Bold Italic", 18); title.setMargin2(0, 0, 8, 8); // Add a 2 pixels wide separator line just under the title c.addLine(10, title.getHeight(), c.getWidth() - 11, title.getHeight(), Chart.LineColor, 2); // Set donut center at (160, 175), and outer/inner radii as 110/55 pixels c.setDonutSize(160, 175, 110, 55); // Set the pie data and the pie labels c.setData(data, labels); // Use ring shading effect for the sectors c.setSectorStyle(Chart.RingShading); // Use the side label layout method, with the labels positioned 16 pixels // from the donut bounding box c.setLabelLayout(Chart.SideLayout, 16); // Show only the sector number as the sector label c.setLabelFormat("{={sector}+1}"); // Set the sector label style to Arial Bold 10pt, with a dark grey // (444444) border c.setLabelStyle("Arial Bold", 10).setBackground(Chart.Transparent, 0x444444); // Add a legend box, with the center of the left side anchored at (330, // 175), and using 10 pts Arial Bold Italic font LegendBox b = c.addLegend(330, 175, true, "Arial Bold Italic", 10); b.setAlignment(Chart.Left); // Set the legend box border to dark grey (444444), and with rounded // conerns b.setBackground(Chart.Transparent, 0x444444); b.setRoundedCorners(); // Set the legend box margin to 16 pixels, and the extra line spacing // between the legend entries as 5 pixels b.setMargin(16); b.setKeySpacing(0, 5); // Set the legend text to show the sector number, followed by a 120 // pixels wide block showing the sector label, and a 40 pixels wide block // showing the percentage b.setText( "<*block,valign=top*>{={sector}+1}.<*advanceTo=22*>" + "<*block,width=120*>{label}<*/*><*block,width=40,halign=right*>" + "{percent}<*/*>%"); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{label}: US${value}K ({percent}%)'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WPFChartViewer viewer, int chartIndex) { // The data for the chart double[] data = { 5.1, 1.5, 5.1, 4.0, 1.7, 8.7, 9.4, 2.1, 3.5, 8.8, 5.0, 6.0 }; // The labels for the chart string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" }; // Create a PolarChart object of size 400 x 420 pixels. with a metallic blue (9999ff) // background color and 1 pixel 3D border PolarChart c = new PolarChart(400, 420, Chart.metalColor(0x9999ff), 0x000000, 1); // Add a title to the chart using 16pt Arial Bold Italic font. The title text is white // (0xffffff) on deep blue (000080) background c.addTitle("Chemical Concentration", "Arial Bold Italic", 16, 0xffffff).setBackground( 0x000080); // Set center of plot area at (200, 240) with radius 145 pixels. Set background color to // green (0x33ff33) c.setPlotArea(200, 240, 145, 0x33ff33); // Set the labels to the angular axis c.angularAxis().setLabels(labels); // Color the sector between label index = 5.5 to 7.5 as red (ff3333) zone c.angularAxis().addZone(5.5, 7.5, 0xff3333); // Color the sector between label index = 4.5 to 5.5, and also between 7.5 to 8.5, as // yellow (ff3333) zones c.angularAxis().addZone(4.5, 5.5, 0xffff00); c.angularAxis().addZone(7.5, 8.5, 0xffff00); // Set the grid style to circular grid c.setGridStyle(false); // Use semi-transparent (40ffffff) label background so as not to block the data c.radialAxis().setLabelStyle().setBackground(0x40ffffff, 0x40000000); // Add a legend box at (200, 30) top center aligned, using 9pt Arial Bold font. with a // black border. LegendBox legendBox = c.addLegend(200, 30, false, "Arial Bold", 9); legendBox.setAlignment(Chart.TopCenter); // Add legend keys to represent the red/yellow/green zones legendBox.addKey("Very Dry", 0xff3333); legendBox.addKey("Critical", 0xffff00); legendBox.addKey("Moderate", 0x33ff33); // Add a blue (0x80) line layer with line width set to 3 pixels and use purple (ff00ff) // cross symbols for the data points PolarLineLayer layer = c.addLineLayer(data, 0x000080); layer.setLineWidth(3); layer.setDataSymbol(Chart.Cross2Shape(), 15, 0xff00ff); // Output the chart viewer.Chart = c; // Include tool tip for the chart. viewer.ImageMap = layer.getHTMLImageMap("clickable", "", "title='Concentration on {label}: {value} ppm'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, int chartIndex) { // The data for the chart double[] data0 = { 42, 49, Chart.NoValue, 38, 64, 56, 29, 41, 44, 57 }; double[] data1 = { 65, 75, 47, 34, 42, 49, 73, Chart.NoValue, 90, 69, 66, 78 }; double[] data2 = { Chart.NoValue, Chart.NoValue, 25, 28, 38, 20, 22, Chart.NoValue, 25, 33, 30, 24 }; string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; // Create a XYChart object of size 600 x 360 pixels. Set background color to brushed // silver, with a 2 pixel 3D border. Use rounded corners. XYChart c = new XYChart(600, 360, Chart.brushedSilverColor(), Chart.Transparent, 2); c.setRoundedFrame(); // Add a title using 18pt Times New Roman Bold Italic font. #Set top/bottom margins to 6 // pixels. ChartDirector.TextBox title = c.addTitle("Product Line Global Revenue", "Times New Roman Bold Italic", 18); title.setMargin2(0, 0, 6, 6); // Add a separator line just under the title c.addLine(10, title.getHeight(), c.getWidth() - 11, title.getHeight(), Chart.LineColor); // Add a legend box where the top-center is anchored to the horizontal center of the // chart, just under the title. Use horizontal layout and 10 points Arial Bold font, and // transparent background and border. LegendBox legendBox = c.addLegend(c.getWidth() / 2, title.getHeight(), false, "Arial Bold", 10); legendBox.setAlignment(Chart.TopCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Tentatively set the plotarea at (70, 75) and of 460 x 240 pixels in size. Use // transparent border and black (000000) grid lines c.setPlotArea(70, 75, 460, 240, -1, -1, Chart.Transparent, 0x000000, -1); // Set the x axis labels c.xAxis().setLabels(labels); // Show the same scale on the left and right y-axes c.syncYAxis(); // Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will use this as the // guideline when putting ticks on the y-axis. c.yAxis().setTickDensity(30); // Set all axes to transparent c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); c.yAxis2().setColors(Chart.Transparent); // Set the x-axis margins to 15 pixels, so that the horizontal grid lines can extend // beyond the leftmost and rightmost vertical grid lines c.xAxis().setMargin(15, 15); // Set axis label style to 8pt Arial Bold c.xAxis().setLabelStyle("Arial Bold", 8); c.yAxis().setLabelStyle("Arial Bold", 8); c.yAxis2().setLabelStyle("Arial Bold", 8); // Add axis title using 10pt Arial Bold Italic font c.yAxis().setTitle("Revenue in USD millions", "Arial Bold Italic", 10); c.yAxis2().setTitle("Revenue in USD millions", "Arial Bold Italic", 10); // Add the first line. The missing data will be represented as gaps in the line (the // default behaviour) LineLayer layer0 = c.addLineLayer2(); layer0.addDataSet(data0, 0xff0000, "Quantum Computer").setDataSymbol( Chart.GlassSphere2Shape, 11); layer0.setLineWidth(3); // Add the second line. The missing data will be represented by using dash lines to // bridge the gap LineLayer layer1 = c.addLineLayer2(); layer1.addDataSet(data1, 0x00ff00, "Atom Synthesizer").setDataSymbol( Chart.GlassSphere2Shape, 11); layer1.setLineWidth(3); layer1.setGapColor(c.dashLineColor(0x00ff00)); // Add the third line. The missing data will be ignored - just join the gap with the // original line style. LineLayer layer2 = c.addLineLayer2(); layer2.addDataSet(data2, 0xff6600, "Proton Cannon").setDataSymbol( Chart.GlassSphere2Shape, 11); layer2.setLineWidth(3); layer2.setGapColor(Chart.SameAsMainColor); // layout the legend so we can get the height of the legend box c.layoutLegend(); // Adjust the plot area size, such that the bounding box (inclusive of axes) is 15 // pixels from the left edge, just under the legend box, 16 pixels from the right edge, // and 25 pixels from the bottom edge. c.packPlotArea(15, legendBox.getTopY() + legendBox.getHeight(), c.getWidth() - 16, c.getHeight() - 25); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='Revenue of {dataSetName} in {xLabel}: US$ {value}M'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WPFChartViewer viewer, int chartIndex) { // The x coordinates for the 2 scatter groups DateTime[] dataX = { new DateTime(2011, 9, 1), new DateTime(2011, 9, 2), new DateTime( 2011, 9, 3), new DateTime(2011, 9, 4), new DateTime(2011, 9,5), new DateTime(2011, 9, 6), new DateTime(2011, 9, 7), new DateTime(2011,9, 8),new DateTime(2011,9, 9), new DateTime(2011, 9, 10), new DateTime(2011, 9, 11) }; // The y and z coordinates for the first scatter group double[] dataY0 = { 0.4, 0.2, 0.5, 0.4, 0.7, 1.3, 1.1, 1.0, 0.6, 0.4, 0.5 }; double[] dataZ0 = { 43, 38, 33, 23.4, 28, 36, 34, 47, 53, 45, 40 }; // The y and z coordinates for the second scatter group double[] dataY1 = { 1.4, 1.0, 1.8, 1.9, 1.5, 1.0, 0.6, 0.7, 1.2, 1.7, 1.5 }; double[] dataZ1 = { 46, 41, 33, 37, 28, 29, 34, 37, 41, 52, 50 }; // Instead of displaying numeric values, labels are used for the y-axis string[] labelsY = { "Low", "Medium", "High" }; // Create a ThreeDScatterChart object of size 760 x 520 pixels ThreeDScatterChart c = new ThreeDScatterChart(760, 520); // Add a title to the chart using 18 points Arial font c.addTitle("3D Scatter Chart Axis Types", "Arial", 18); // Set the center of the plot region at (385, 270), and set width x depth x height to // 480 x 240 x 240 pixels c.setPlotRegion(385, 270, 480, 240, 240); // Set the elevation and rotation angles to 30 and -10 degrees c.setViewAngle(30, -10); // Add a legend box at (380, 40) with horizontal layout. Use 9pt Arial Bold font. LegendBox b = c.addLegend(380, 40, false, "Arial Bold", 9); b.setAlignment(Chart.TopCenter); b.setRoundedCorners(); // Add a scatter group to the chart using 13 pixels red (ff0000) glass sphere symbols, // with dotted drop lines ThreeDScatterGroup g0 = c.addScatterGroup(Chart.CTime(dataX), dataY0, dataZ0, "Alpha Series", Chart.GlassSphere2Shape, 13, 0xff0000); g0.setDropLine(c.dashLineColor(Chart.SameAsMainColor, Chart.DotLine)); // Add a scatter group to the chart using 13 pixels blue (00cc00) cross symbols, with // dotted drop lines ThreeDScatterGroup g1 = c.addScatterGroup(Chart.CTime(dataX), dataY1, dataZ1, "Beta Series", Chart.Cross2Shape(), 13, 0x00cc00); g1.setDropLine(c.dashLineColor(Chart.SameAsMainColor, Chart.DotLine)); // Set x-axis tick density to 50 pixels. ChartDirector auto-scaling will use this as the // guideline when putting ticks on the x-axis. c.xAxis().setTickDensity(50); // Set the y-axis labels c.yAxis().setLabels(labelsY); // Set label style to Arial bold for all axes c.xAxis().setLabelStyle("Arial Bold"); c.yAxis().setLabelStyle("Arial Bold"); c.zAxis().setLabelStyle("Arial Bold"); // Set the x, y and z axis titles using deep blue (000088) 15 points Arial font c.xAxis().setTitle("Date/Time Axis", "Arial Italic", 15, 0x000088); c.yAxis().setTitle("Label\nBased\nAxis", "Arial Italic", 15, 0x000088); c.zAxis().setTitle("Numeric Axis", "Arial Italic", 15, 0x000088); // Output the chart viewer.Chart = c; }
// // Draw the main chart // private void drawChart(RazorChartViewer viewer) { // // For simplicity, in this demo, the data arrays are filled with hard coded data. In a real // application, you may use a database or other data source to load up the arrays, and only // visible data (data within the view port) need to be loaded. // double[] dataX0 = { 10, 15, 6, -12, 14, -8, 13, -3, 16, 12, 10.5, -7, 3, -10, -5, 2, 5 }; double[] dataY0 = { 130, 150, 80, 110, -110, -105, -130, -15, -170, 125, 125, 60, 25, 150, 150, 15, 120 }; double[] dataX1 = { 6, 7, -4, 3.5, 7, 8, -9, -10, -12, 11, 8, -3, -2, 8, 4, -15, 15 }; double[] dataY1 = { 65, -40, -40, 45, -70, -80, 80, 10, -100, 105, 60, 50, 20, 170, -25, 50, 75 }; double[] dataX2 = { -10, -12, 11, 8, 6, 12, -4, 3.5, 7, 8, -9, 3, -13, 16, -7.5, -10, -15 }; double[] dataY2 = { 65, -80, -40, 45, -70, -80, 80, 90, -100, 105, 60, -75, -150, -40, 120, -50, -30 }; // Create an XYChart object 500 x 480 pixels in size, with light blue (c0c0ff) background XYChart c = new XYChart(500, 480, 0xc0c0ff); // Set the plotarea at (50, 40) and of size 400 x 400 pixels. Use light grey (c0c0c0) // horizontal and vertical grid lines. Set 4 quadrant coloring, where the colors alternate // between lighter and deeper grey (dddddd/eeeeee). c.setPlotArea(50, 40, 400, 400, -1, -1, -1, 0xc0c0c0, 0xc0c0c0).set4QBgColor(0xdddddd, 0xeeeeee, 0xdddddd, 0xeeeeee, 0x000000); // As the data can lie outside the plotarea in a zoomed chart, we need enable clipping c.setClipping(); // Set 4 quadrant mode, with both x and y axes symetrical around the origin c.setAxisAtOrigin(Chart.XYAxisAtOrigin, Chart.XAxisSymmetric + Chart.YAxisSymmetric); // Add a legend box at (450, 40) (top right corner of the chart) with vertical layout and 8pt // Arial Bold font. Set the background color to semi-transparent grey (40dddddd). LegendBox legendBox = c.addLegend(450, 40, true, "Arial Bold", 8); legendBox.setAlignment(Chart.TopRight); legendBox.setBackground(0x40dddddd); // Add titles to axes c.xAxis().setTitle("Alpha Index"); c.yAxis().setTitle("Beta Index"); // Set axes line width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // The default ChartDirector settings has a denser y-axis grid spacing and less-dense x-axis // grid spacing. In this demo, we want the tick spacing to be symmetrical. We use around 40 // pixels between major ticks and 20 pixels between minor ticks. c.xAxis().setTickDensity(40, 20); c.yAxis().setTickDensity(40, 20); // // In this example, we represent the data by scatter points. You may modify the code below to // use other layer types (lines, areas, etc). // // Add scatter layer, using 11 pixels red (ff33333) X shape symbols c.addScatterLayer(dataX0, dataY0, "Group A", Chart.Cross2Shape(), 11, 0xff3333); // Add scatter layer, using 11 pixels green (33ff33) circle symbols c.addScatterLayer(dataX1, dataY1, "Group B", Chart.CircleShape, 11, 0x33ff33); // Add scatter layer, using 11 pixels blue (3333ff) triangle symbols c.addScatterLayer(dataX2, dataY2, "Group C", Chart.TriangleSymbol, 11, 0x3333ff); // // In this example, we have not explicitly configured the full x and y range. In this case, // the first time syncLinearAxisWithViewPort is called, ChartDirector will auto-scale the // axis and assume the resulting range is the full range. In subsequent calls, ChartDirector // will set the axis range based on the view port and the full range. // viewer.syncLinearAxisWithViewPort("x", c.xAxis()); viewer.syncLinearAxisWithViewPort("y", c.yAxis()); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='[{dataSetName}] Alpha = {x|G}, Beta = {value|G}'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, int chartIndex) { // The data for the bars and the marks double[] barData = { 100, 125, 245, 147, 67, 96, 160, 145, 97, 167, 220, 125 }; double[] markData = { 85, 156, 220, 120, 80, 110, 140, 130, 111, 180, 175, 100 }; // The labels for the bar chart string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" }; // Create a XYChart object of size 480 x 360 pixels. Use a vertical gradient color from // pale blue (e8f0f8) to sky blue (aaccff) spanning half the chart height as background. // Set border to blue (88aaee). Use rounded corners. Enable soft drop shadow. XYChart c = new XYChart(480, 360); c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight() / 2, 0xe8f0f8, 0xaaccff), 0x88aaee); c.setRoundedFrame(); c.setDropShadow(); // Add a title to the chart using 15 points Arial Italic font. Set top/bottom margins to // 12 pixels. ChartDirector.TextBox title = c.addTitle("Bars with Marks Demonstration", "Arial Italic", 15); title.setMargin2(0, 0, 12, 12); // Tentatively set the plotarea to 50 pixels from the left edge to allow for the y-axis, // and to just under the title. Set the width to 65 pixels less than the chart width, // and the height to reserve 90 pixels at the bottom for the x-axis and the legend box. // Use pale blue (e8f0f8) background, transparent border, and grey (888888) dotted // horizontal grid lines. c.setPlotArea(50, title.getHeight(), c.getWidth() - 65, c.getHeight() - title.getHeight( ) - 90, 0xe8f0f8, -1, Chart.Transparent, c.dashLineColor(0x888888, Chart.DotLine)); // Add a legend box where the bottom-center is anchored to the 15 pixels above the // bottom-center of the chart. Use horizontal layout and 8 points Arial font. LegendBox legendBox = c.addLegend(c.getWidth() / 2, c.getHeight() - 15, false, "Arial", 8); legendBox.setAlignment(Chart.BottomCenter); // Set the legend box background and border to pale blue (e8f0f8) and bluish grey // (445566) legendBox.setBackground(0xe8f0f8, 0x445566); // Use rounded corners of 5 pixel radius for the legend box legendBox.setRoundedCorners(5); // Use line style legend key legendBox.setLineStyleKey(); // Set axes to transparent c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); // Set the labels on the x axis c.xAxis().setLabels(labels); // Add a box-whisker layer with just the middle mark visible for the marks. Use red // (ff0000) color for the mark, with a line width of 2 pixels and 10% horizontal gap BoxWhiskerLayer markLayer = c.addBoxWhiskerLayer(null, null, null, null, markData, -1, 0xff0000); markLayer.setLineWidth(2); markLayer.setDataGap(0.1); // Add the legend key for the mark line legendBox.addKey("Target", 0xff0000, 2); // Tool tip for the mark layer markLayer.setHTMLImageMap("", "", "title='Target at {xLabel}: {med}'"); // Add a blue (0066cc) bar layer using the given data. BarLayer barLayer = c.addBarLayer(barData, 0x0066cc, "Actual"); // Use soft lighting effect for the bars with light direction from left. barLayer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Left)); // Tool tip for the bar layer barLayer.setHTMLImageMap("", "", "title='{dataSetName} at {xLabel}: {value}'"); // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10 // pixels from the left edge, just below the title, 15 pixels from the right edge, and // 10 pixels above the legend box. c.packPlotArea(10, title.getHeight(), c.getWidth() - 15, c.layoutLegend().getTopY() - 10 ); // Output the chart viewer.Chart = c; // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable"); }
// // Draw the chart and display it in the given viewer // private void drawChart(WPFChartViewer viewer) { // Create an XYChart object 500 x 480 pixels in size, with the same background color // as the container XYChart c = new XYChart(500, 480, 0xccccff); // Set the plotarea at (50, 40) and of size 400 x 400 pixels. Use light grey (c0c0c0) // horizontal and vertical grid lines. Set 4 quadrant coloring, where the colors of // the quadrants alternate between lighter and deeper grey (dddddd/eeeeee). c.setPlotArea(50, 40, 400, 400, -1, -1, -1, 0xc0c0c0, 0xc0c0c0 ).set4QBgColor(0xdddddd, 0xeeeeee, 0xdddddd, 0xeeeeee, 0x000000); // Enable clipping mode to clip the part of the data that is outside the plot area. c.setClipping(); // Set 4 quadrant mode, with both x and y axes symetrical around the origin c.setAxisAtOrigin(Chart.XYAxisAtOrigin, Chart.XAxisSymmetric + Chart.YAxisSymmetric); // Add a legend box at (450, 40) (top right corner of the chart) with vertical layout // and 8 pts Arial Bold font. Set the background color to semi-transparent grey. LegendBox b = c.addLegend(450, 40, true, "Arial Bold", 8); b.setAlignment(Chart.TopRight); b.setBackground(0x40dddddd); // Add a titles to axes c.xAxis().setTitle("Alpha Index"); c.yAxis().setTitle("Beta Index"); // Set axes width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // The default ChartDirector settings has a denser y-axis grid spacing and less-dense // x-axis grid spacing. In this demo, we want the tick spacing to be symmetrical. // We use around 50 pixels between major ticks and 25 pixels between minor ticks. c.xAxis().setTickDensity(50, 25); c.yAxis().setTickDensity(50, 25); // // In this example, we represent the data by scatter points. If you want to represent // the data by somethings else (lines, bars, areas, floating boxes, etc), just modify // the code below to use the layer type of your choice. // // Add scatter layer, using 11 pixels red (ff33333) X shape symbols c.addScatterLayer(dataX0, dataY0, "Group A", Chart.Cross2Shape(), 11, 0xff3333); // Add scatter layer, using 11 pixels green (33ff33) circle symbols c.addScatterLayer(dataX1, dataY1, "Group B", Chart.CircleShape, 11, 0x33ff33); // Add scatter layer, using 11 pixels blue (3333ff) triangle symbols c.addScatterLayer(dataX2, dataY2, "Group C", Chart.TriangleSymbol, 11, 0x3333ff); // // In this example, we have not explicitly configured the full x and y range. In this case, the // first time syncLinearAxisWithViewPort is called, ChartDirector will auto-scale the axis and // assume the resulting range is the full range. In subsequent calls, ChartDirector will set the // axis range based on the view port and the full range. // viewer.syncLinearAxisWithViewPort("x", c.xAxis()); viewer.syncLinearAxisWithViewPort("y", c.yAxis()); // We need to update the track line too. If the mouse is moving on the chart (eg. if // the user drags the mouse on the chart to scroll it), the track line will be updated // in the MouseMovePlotArea event. Otherwise, we need to update the track line here. if ((!viewer.IsInMouseMoveEvent) && viewer.IsMouseOnPlotArea) { crossHair(c, viewer.PlotAreaMouseX, viewer.PlotAreaMouseY); } // Set the chart image to the ChartViewer viewer.Chart = c; }
// // Draw the chart // private void drawChart(WPFChartViewer viewer) { // Have not started collecting data ??? if (currentIndex <= 0) { return; } // The start time is equal to the latest time minus the time range of the chart double startTime = timeStamps[currentIndex - 1] - timeRange; int startIndex = (int)Math.Ceiling(Chart.bSearch(timeStamps, 0, currentIndex, startTime) - 0.1); // For a sweep chart, if the line goes beyond the right border, it will wrap back to // the left. We need to determine the wrap position (the right border). double wrapTime = Math.Floor(startTime / timeRange + 1) * timeRange; double wrapIndex = Chart.bSearch(timeStamps, 0, currentIndex, wrapTime); int wrapIndexA = (int)Math.Ceiling(wrapIndex); int wrapIndexB = (int)Math.Floor(wrapIndex); // The data arrays and the colors and names of the data series var allArrays = new[] { timeStamps, channel1, channel2 }; int[] colors = { 0xff0000, 0x00cc00 }; string[] names = { "Channel 1", "Channel 2" }; // Split all data arrays into two parts A and B at the wrap position. The B part is the // part that is wrapped back to the left. var allArraysA = new double[allArrays.Length][]; var allArraysB = new double[allArrays.Length][]; for (int i = 0; i < allArrays.Length; ++i) { allArraysA[i] = (double[])Chart.arraySlice(allArrays[i], startIndex, wrapIndexA - startIndex + 1); allArraysB[i] = (double[])Chart.arraySlice(allArrays[i], wrapIndexB, currentIndex - wrapIndexB); } // Normalize the plotted timeStamps (the first element of allArrays) to start from 0 for (int i = 0; i < allArraysA[0].Length; ++i) { allArraysA[0][i] -= wrapTime - timeRange; } for (int i = 0; i < allArraysB[0].Length; ++i) { allArraysB[0][i] -= wrapTime; } // // Now we have prepared all the data and can plot the chart. // //================================================================================ // Configure overall chart appearance. //================================================================================ // Create an XYChart object the same size as WPFChartViewer, with a minimum of 300 x 150 XYChart c = new XYChart(Math.Max(300, (int)viewer.ActualWidth), Math.Max(150, (int)viewer.ActualHeight)); // Set the plotarea at (0, 0) with width 1 pixel less than chart width, and height 20 pixels // less than chart height. Use a vertical gradient from light blue (f0f6ff) to sky blue (a0c0ff) // as background. Set border to transparent and grid lines to white (ffffff). c.setPlotArea(0, 0, c.getWidth() - 1, c.getHeight() - 20, c.linearGradientColor(0, 0, 0, c.getHeight() - 20, 0xf0f6ff, 0xa0c0ff), -1, Chart.Transparent, 0xffffff, 0xffffff); // In our code, we can overdraw the line slightly, so we clip it to the plot area. c.setClipping(); // Add a legend box at the right side using horizontal layout. Use 10pt Arial Bold as font. Set // the background and border color to Transparent and use line style legend key. LegendBox b = c.addLegend(c.getWidth() - 1, 10, false, "Arial Bold", 10); b.setBackground(Chart.Transparent); b.setAlignment(Chart.Right); b.setLineStyleKey(); // Set the x and y axis stems to transparent and the label font to 10pt Arial c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); c.xAxis().setLabelStyle("Arial", 10); c.yAxis().setLabelStyle("Arial", 10, 0x336699); // Configure the y-axis label to be inside the plot area and above the horizontal grid lines c.yAxis().setLabelGap(-1); c.yAxis().setMargin(20); c.yAxis().setLabelAlignment(1); // Configure the x-axis labels to be to the left of the vertical grid lines c.xAxis().setLabelAlignment(1); //================================================================================ // Add data to chart //================================================================================ // Draw the lines, which consists of A segments and B segments (the wrapped segments) foreach (var dataArrays in new[] { allArraysA, allArraysB }) { LineLayer layer = c.addLineLayer2(); layer.setLineWidth(2); layer.setFastLineMode(); // The first element of dataArrays is the timeStamp, and the rest are the data. layer.setXData(dataArrays[0]); for (int i = 1; i < dataArrays.Length; ++i) { layer.addDataSet(dataArrays[i], colors[i - 1], names[i - 1]); } // Disable legend entries for the B lines to avoid duplication with the A lines if (dataArrays == allArraysB) { layer.setLegend(Chart.NoLegend); } } // The B segments contain the latest data. We add a vertical line at the latest position. int lastIndex = allArraysB[0].Length - 1; Mark m = c.xAxis().addMark(allArraysB[0][lastIndex], -1); m.setMarkColor(0x0000ff, Chart.Transparent, Chart.Transparent); m.setDrawOnTop(false); // We also add a symbol and a label for each data series at the latest position for (int i = 1; i < allArraysB.Length; ++i) { // Add the symbol Layer layer = c.addScatterLayer(new double[] { allArraysB[0][lastIndex] }, new double[] { allArraysB[i][lastIndex] }, "", Chart.CircleSymbol, 9, colors[i - 1], colors[i - 1]); layer.moveFront(); // Add the label string label = "<*font,bgColor=" + colors[i - 1].ToString("x") + "*> {value|P4} <*/font*>"; layer.setDataLabelFormat(label); // The label style ChartDirector.TextBox t = layer.setDataLabelStyle("Arial Bold", 10, 0xffffff); bool isOnLeft = allArraysB[0][lastIndex] <= timeRange / 2; t.setAlignment(isOnLeft ? Chart.Left : Chart.Right); t.setMargin(isOnLeft ? 5 : 0, isOnLeft ? 0 : 5, 0, 0); } //================================================================================ // Configure axis scale and labelling //================================================================================ c.xAxis().setLinearScale(0, timeRange); // For the automatic axis labels, set the minimum spacing to 75/40 pixels for the x/y axis. c.xAxis().setTickDensity(75); c.yAxis().setTickDensity(40); // Set the auto-scale margin to 0.05, and the zero affinity to 0.6 c.yAxis().setAutoScale(0.05, 0.05, 0.6); //================================================================================ // Output the chart //================================================================================ viewer.Chart = c; }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, int chartIndex) { // The XY data of the first data series double[] dataX0 = { 10, 35, 17, 4, 22, 29, 45, 52, 63, 39 }; double[] dataY0 = { 2.0, 3.2, 2.7, 1.2, 2.8, 2.9, 3.1, 3.0, 2.3, 3.3 }; // The XY data of the second data series double[] dataX1 = { 30, 35, 17, 4, 22, 59, 43, 52, 63, 39 }; double[] dataY1 = { 1.0, 1.3, 0.7, 0.6, 0.8, 3.0, 1.8, 2.3, 3.4, 1.5 }; // The XY data of the third data series double[] dataX2 = { 28, 35, 15, 10, 22, 60, 46, 64, 39 }; double[] dataY2 = { 2.0, 2.2, 1.2, 0.4, 1.8, 2.7, 2.4, 2.8, 2.4 }; // Create a XYChart object of size 540 x 480 pixels XYChart c = new XYChart(540, 480); // Set the plotarea at (70, 65) and of size 400 x 350 pixels, with white background and // a light grey border (0xc0c0c0). Turn on both horizontal and vertical grid lines with // light grey color (0xc0c0c0) c.setPlotArea(70, 65, 400, 350, 0xffffff, -1, 0xc0c0c0, 0xc0c0c0, -1); // Add a legend box with the top center point anchored at (270, 30). Use horizontal // layout. Use 10pt Arial Bold Italic font. Set the background and border color to // Transparent. LegendBox legendBox = c.addLegend(270, 30, false, "Arial Bold Italic", 10); legendBox.setAlignment(Chart.TopCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Add a title to the chart using 18 point Times Bold Itatic font. c.addTitle("Parametric Curve Fitting", "Times New Roman Bold Italic", 18); // Add titles to the axes using 12pt Arial Bold Italic font c.yAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12); c.xAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 12); // Set the axes line width to 3 pixels c.yAxis().setWidth(3); c.xAxis().setWidth(3); // Add a scatter layer using (dataX0, dataY0) c.addScatterLayer(dataX0, dataY0, "Polynomial", Chart.GlassSphere2Shape, 11, 0xff0000); // Add a degree 2 polynomial trend line layer for (dataX0, dataY0) TrendLayer trend0 = c.addTrendLayer2(dataX0, dataY0, 0xff0000); trend0.setLineWidth(3); trend0.setRegressionType(Chart.PolynomialRegression(2)); trend0.setHTMLImageMap("{disable}"); // Add a scatter layer for (dataX1, dataY1) c.addScatterLayer(dataX1, dataY1, "Exponential", Chart.GlassSphere2Shape, 11, 0x00aa00); // Add an exponential trend line layer for (dataX1, dataY1) TrendLayer trend1 = c.addTrendLayer2(dataX1, dataY1, 0x00aa00); trend1.setLineWidth(3); trend1.setRegressionType(Chart.ExponentialRegression); trend1.setHTMLImageMap("{disable}"); // Add a scatter layer using (dataX2, dataY2) c.addScatterLayer(dataX2, dataY2, "Logarithmic", Chart.GlassSphere2Shape, 11, 0x0000ff); // Add a logarithmic trend line layer for (dataX2, dataY2) TrendLayer trend2 = c.addTrendLayer2(dataX2, dataY2, 0x0000ff); trend2.setLineWidth(3); trend2.setRegressionType(Chart.LogarithmicRegression); trend2.setHTMLImageMap("{disable}"); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{dataSetName}] ({x}, {value})'"); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // The data for the bar chart double[] data0 = { 44, 55, 100 }; double[] data1 = { 97, 87, 167 }; double[] data2 = { 156, 78, 147 }; double[] data3 = { 125, 118, 211 }; // The labels for the bar chart. The labels contains embedded images as icons. string[] labels = { "<*img=service.png*><*br*>Service", "<*img=software.png*><*br*>Software", "<*img=computer.png*><*br*>Hardware" }; // Create a XYChart object of size 600 x 350 pixels, using 0xe0e0ff as the background color, // 0xccccff as the border color, with 1 pixel 3D border effect. XYChart c = new XYChart(600, 350, 0xe0e0ff, 0xccccff, 1); //Set default directory for loading images c.setSearchPath(Url.Content("~/Content")); // Add a title to the chart using 14 points Times Bold Itatic font and light blue (0x9999ff) // as the background color c.addTitle("Business Results 2001 vs 2002", "Times New Roman Bold Italic", 14).setBackground( 0x9999ff); // Set the plotarea at (60, 45) and of size 500 x 210 pixels, using white (0xffffff) as the // background c.setPlotArea(60, 45, 500, 210, 0xffffff); // Swap the x and y axes to create a horizontal bar chart c.swapXY(); // Add a title to the y axis using 11 pt Times Bold Italic as font c.yAxis().setTitle("Revenue (millions)", "Times New Roman Bold Italic", 11); // Set the labels on the x axis c.xAxis().setLabels(labels); // Disable x-axis ticks by setting the tick length to 0 c.xAxis().setTickLength(0); // Add a stacked bar layer to the chart BarLayer layer = c.addBarLayer2(Chart.Stack); // Add the first two data sets to the chart as a stacked bar group layer.addDataGroup("2001"); layer.addDataSet(data0, 0xaaaaff, "Local"); layer.addDataSet(data1, 0x6666ff, "International"); // Add the remaining data sets to the chart as another stacked bar group layer.addDataGroup("2002"); layer.addDataSet(data2, 0xffaaaa, "Local"); layer.addDataSet(data3, 0xff6666, "International"); // Set the sub-bar gap to 0, so there is no gap between stacked bars with a group layer.setBarGap(0.2, 0); // Set the bar border to transparent layer.setBorderColor(Chart.Transparent); // Set the aggregate label format layer.setAggregateLabelFormat("Year {dataGroupName}\n{value} millions"); // Set the aggregate label font to 8 point Arial Bold Italic layer.setAggregateLabelStyle("Arial Bold Italic", 8); // Reverse 20% space at the right during auto-scaling to allow space for the aggregate bar // labels c.yAxis().setAutoScale(0.2); // Add a legend box at (310, 300) using TopCenter alignment, with 2 column grid layout, and // use 8pt Arial Bold Italic as font LegendBox legendBox = c.addLegend2(310, 300, 2, "Arial Bold Italic", 8); legendBox.setAlignment(Chart.TopCenter); // Set the format of the text displayed in the legend box legendBox.setText("Year {dataGroupName} {dataSetName} Revenue"); // Set the background and border of the legend box to transparent legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='Year {dataGroupName} {dataSetName} {xLabel} Revenue: {value} millions'"); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // The data for the pie chart double[] data = { 25, 18, 15, 12, 8, 30, 35 }; // The labels for the pie chart string[] labels = { "Labor", "Licenses", "Taxes", "Legal", "Insurance", "Facilities", "Production" }; // Create a PieChart object of size 480 x 300 pixels PieChart c = new PieChart(480, 300); // Use a blue marble pattern as the background wallpaper, with a black // border, and 1 pixel 3D border effect c.setBackground(c.patternColor("marble.png"), 0x000000, 1); // Set the center of the pie at (150, 150) and the radius to 100 pixels c.setPieSize(150, 150, 100); // Add a title to the pie chart using Times Bold Italic/15 points/deep // blue (0x000080) as font, with a wood pattern as the title background c.addTitle("Project Cost Breakdown", "Times New Roman Bold Italic", 15, 0x000080).setBackground(c.patternColor("wood.png")); // Draw the pie in 3D c.set3D(); // Add a legend box using Arial Bold Italic/11 points font. Use a pink // marble pattern as the background wallpaper, with a 1 pixel 3D border. // The legend box is top-right aligned relative to the point (465, 70) LegendBox b = c.addLegend(465, 70, true, "Arial Bold Italic", 11); b.setBackground(c.patternColor("marble2.png"), Chart.Transparent, 1); b.setAlignment(Chart.TopRight); // Set the default font for all sector labels to Arial Bold/8 pts/dark // green (0x008000). c.setLabelStyle("Arial Bold", 8, 0x008000); // Set the pie data and the pie labels c.setData(data, labels); // Explode the 3rd sector c.setExplode(2, 40); // Use Arial Bold/12 pts/red as label font for the 3rd sector c.sector(2).setLabelStyle("Arial Bold", 12, 0xff0000); // Use Arial/8 pts/deep blue as label font for the 5th sector. Add a // background box using the sector fill color (SameAsMainColor), with a // black (0x000000) edge and 2 pixel 3D border. c.sector(4).setLabelStyle("Arial", 8, 0x000080).setBackground( Chart.SameAsMainColor, 0x000000, 2); // Use Arial Italic/8 pts/light red (0xff9999) as label font for the 6th // sector. Add a dark blue (0x000080) background box with a 2 pixel 3D // border. c.sector(0).setLabelStyle("Arial Italic", 8, 0xff9999).setBackground( 0x000080, Chart.Transparent, 2); // Use Times Bold Italic/8 pts/deep green (0x008000) as label font for // 7th sector. Add a yellow (0xFFFF00) background box with a black // (0x000000) edge. c.sector(6).setLabelStyle("Times New Roman Bold Italic", 8, 0x008000 ).setBackground(0xffff00, 0x000000); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{label}: US${value}K ({percent}%)'"); }
public void createChart(WinChartViewer viewer, DataTable dt_chart, string title) { try { Chart.setLicenseCode("DEVP-2LSU-B4LX-YCTY-2DF2-77EE"); double[] data = new double[dt_chart.Rows.Count]; string[] labels = new string[dt_chart.Rows.Count]; for (int i = 0; i < dt_chart.Rows.Count; i++) { data[i] = Convert.ToDouble(dt_chart.Rows[i]["RATE"].ToString()); labels[i] = dt_chart.Rows[i]["reason_tail_nm"].ToString(); } // The colors to use for the sectors int[] colors = { 0x66aaee, 0xeebb22, 0xbbbbbb, 0x8844ff, 0xdd2222, 0x009900, 0xff8040, 0xaa0023 }; // Create a PieChart object of size 600 x 320 pixels. Use a vertical // gradient color from light blue (99ccff) to white (ffffff) spanning the // top 100 pixels as background. Set border to grey (888888). Use rounded // corners. Enable soft drop shadow. PieChart c = new PieChart(690, 310); c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888); c.setRoundedFrame(); c.setDropShadow(); // Add a title using 18 pts Times New Roman Bold Italic font. Add 16 // pixels top margin to the title. c.addTitle(title, "Times New Roman Bold Italic", 18).setMargin2(0, 0, 1, 0); // Set the center of the pie at (160, 165) and the radius to 110 pixels c.setPieSize(230, 170, 140); // Draw the pie in 3D with a pie thickness of 25 pixels c.set3D(25); // Set the pie data and the pie labels c.setData(data, labels); // Set the sector colors c.setColors2(Chart.DataColor, colors); // Use local gradient shading for the sectors c.setSectorStyle(Chart.LocalGradientShading); // Use the side label layout method, with the labels positioned 16 pixels // from the pie bounding box c.setLabelLayout(Chart.Transparent, 16); // Show only the sector number as the sector label c.setLabelFormat("{percent} % "); // Set the sector label style to Arial Bold 10pt, with a dark grey // (444444) border c.setLabelStyle("Arial Bold", 10).setBackground(Chart.Transparent, 0x444444); // Add a legend box, with the center of the left side anchored at (330, // 175), and using 10 pts Arial Bold Italic font LegendBox b = new LegendBox(); b = c.addLegend(470, 150, true, "Arial Bold Italic", 12); b.setAlignment(Chart.Left); // Set the legend box border to dark grey (444444), and with rounded // conerns b.setBackground(Chart.Transparent, 0x444444); b.setRoundedCorners(); // Set the legend box margin to 16 pixels, and the extra line spacing // between the legend entries as 5 pixels b.setMargin(16); b.setKeySpacing(0, 5); // Set the legend box icon to have no border (border color same as fill // color) b.setKeyBorder(Chart.SameAsMainColor); // Set the legend text to show the sector number, followed by a 120 // pixels wide block showing the sector label, and a 40 pixels wide block // showing the percentage b.setText( "<*block,valign=top*> <*advanceTo=22*>" + "<*block,width=140*>{label}<*/*>"); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{label}: {percent} % '"); } catch { } // The data for the pie chart //dt_chart = this.select_chart_1(); }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // The data for the line chart double[] data0 = { 42, 49, 33, 38, 64, 56, 29, 41, 44, 57, 59, 42 }; double[] data1 = { 65, 75, 47, 34, 42, 49, 73, 62, 90, 69, 66, 78 }; double[] data2 = { 36, 28, 25, 28, 38, 20, 22, 30, 25, 33, 30, 24 }; string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; // Create a XYChart object of size 600 x 400 pixels XYChart c = new XYChart(600, 400); // Add a title to the chart using 18 pts Times Bold Italic font ChartDirector.TextBox title = c.addTitle("Product Line Global Revenue", "Times New Roman Bold Italic", 18); // Tentatively set the plotarea at (50, 55) and of (chart_width - 100) x // (chart_height - 120) pixels in size. Use a vertical gradient color // from sky blue (aaccff) t0 light blue (f9f9ff) as background. Set both // horizontal and vertical grid lines to dotted semi-transprent black // (aa000000). PlotArea plotArea = c.setPlotArea(50, 55, c.getWidth() - 100, c.getHeight() - 120, c.linearGradientColor(0, 55, 0, 55 + c.getHeight() - 120, 0xaaccff, 0xf9fcff), -1, -1, c.dashLineColor( unchecked ((int)0xaa000000), Chart.DotLine), -1); // Add a legend box and anchored the top center at the horizontal center // of the chart, just under the title. Use 10pts Arial Bold as font, with // transparent background and border. LegendBox legendBox = c.addLegend(c.getWidth() / 2, title.getHeight(), false, "Arial Bold", 10); legendBox.setAlignment(Chart.TopCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Set y-axis title using 10 points Arial Bold Italic font, label style // to 8 points Arial Bold, and axis color to transparent c.yAxis().setTitle("Revenue (USD millions)", "Arial Bold Italic", 10); c.yAxis().setLabelStyle("Arial Bold", 8); c.yAxis().setColors(Chart.Transparent); // Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will // use this as the guideline when putting ticks on the y-axis. c.yAxis().setTickDensity(30); // Add a line layer to the chart LineLayer layer = c.addLineLayer2(); // Set the line width to 3 pixels layer.setLineWidth(3); // Add the three data sets to the line layer, using circles, diamands and // X shapes as symbols layer.addDataSet(data0, 0xff0000, "Quantum Computer").setDataSymbol( Chart.CircleSymbol, 9); layer.addDataSet(data1, 0x00ff00, "Atom Synthesizer").setDataSymbol( Chart.DiamondSymbol, 11); layer.addDataSet(data2, 0xff6600, "Proton Cannon").setDataSymbol( Chart.Cross2Shape(), 11); // Set the x axis labels c.xAxis().setLabels(labels); // Convert the labels on the x-axis to a CDMLTable CDMLTable table = c.xAxis().makeLabelTable(); // Set the default top/bottom margins of the cells to 3 pixels table.getStyle().setMargin2(0, 0, 3, 3); // Use Arial Bold as the font for the first row table.getRowStyle(0).setFontStyle("Arial Bold"); // // We can add more information to the table. In this sample code, we add // the data series and the legend icons to the table. // // Add 3 more rows to the table. Set the background of the 1st and 3rd // rows to light grey (eeeeee). table.appendRow().setBackground(0xeeeeee, Chart.LineColor); table.appendRow(); table.appendRow().setBackground(0xeeeeee, Chart.LineColor); // Put the values of the 3 data series to the cells in the 3 rows for (int i = 0; i < data0.Length; ++i) { table.setText(i, 1, (data0[i]).ToString()); table.setText(i, 2, (data1[i]).ToString()); table.setText(i, 3, (data2[i]).ToString()); } // Insert a column on the left for the legend icons. Use 5 pixels // left/right margins and 3 pixels top/bottom margins for the cells in // this column. table.insertCol(0).setMargin2(5, 5, 3, 3); // The top cell is set to transparent, so it is invisible table.getCell(0, 0).setBackground(Chart.Transparent, Chart.Transparent); // The other 3 cells are set to the legend icons of the 3 data series table.setText(0, 1, layer.getLegendIcon(0)); table.setText(0, 2, layer.getLegendIcon(1)); table.setText(0, 3, layer.getLegendIcon(2)); // Layout legend box first, so we can get its size c.layoutLegend(); // Adjust the plot area size, such that the bounding box (inclusive of // axes) is 2 pixels from the left, right and bottom edge, and is just // under the legend box. c.packPlotArea(2, legendBox.getTopY() + legendBox.getHeight(), c.getWidth() - 3, c.getHeight() - 3); // After determining the exact plot area position, we may adjust the // legend box and the title positions so that they are centered relative // to the plot area (instead of the chart) legendBox.setPos(plotArea.getLeftX() + (plotArea.getWidth() - legendBox.getWidth()) / 2, legendBox.getTopY()); title.setPos(plotArea.getLeftX() + (plotArea.getWidth() - title.getWidth( )) / 2, title.getTopY()); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='Revenue of {dataSetName} in {xLabel}: US$ {value}M'"); }
/// <summary> /// 绘制噪声数据比较分析图 /// </summary> private void CreateChart(int line) { if (sRecorder == null) { return; } XYChart c = new XYChart(700, 360); c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888); ChartDirector.TextBox title = c.addTitle("噪声数据比较分析图", "Arial Bold", 13); title.setPos(0, 20); c.setPlotArea(80, 80, 580, 230, 0xffffff, -1, -1, c.dashLineColor( 0xaaaaaa, Chart.DotLine), -1); LegendBox legendBox = c.addLegend(350, 80, false, "Arial", 8); legendBox.setAlignment(Chart.BottomCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent); legendBox.setLineStyleKey(); legendBox.setFontSize(8); c.xAxis().setIndent(true); c.xAxis().setTitle("噪声频率(Hz)"); c.yAxis().setTitle("噪声幅度(%)"); LineLayer layer1; ChartDirector.DataSet ds; double[] dataSet; double[] da; dataSet = sRecorder.Data.Amplitude.Skip(4).ToArray(); da = sRecorder.Data.Frequency.Skip(4).ToArray(); switch (line) { case 0: layer1 = c.addLineLayer(); ds = layer1.addDataSet(dataSet, GetRandomColor(0), "记录仪" + sRecorder.ID); layer1.setLineWidth(2); layer1.setXData(da); break; case 1: layer1 = c.addSplineLayer(); ds = layer1.addDataSet(dataSet, GetRandomColor(0), "记录仪" + sRecorder.ID); layer1.setLineWidth(2); layer1.setXData(da); break; } if (eRecorder != null && sRecorder.ID != eRecorder.ID) { dataSet = eRecorder.Data.Amplitude.Skip(4).ToArray(); da = eRecorder.Data.Frequency.Skip(4).ToArray(); switch (line) { case 0: layer1 = c.addLineLayer(); ds = layer1.addDataSet(dataSet, GetRandomColor(1), "记录仪" + eRecorder.ID); layer1.setLineWidth(2); layer1.setXData(da); break; case 1: layer1 = c.addSplineLayer(); ds = layer1.addDataSet(dataSet, GetRandomColor(1), "记录仪" + eRecorder.ID); layer1.setLineWidth(2); layer1.setXData(da); break; } } c.xAxis().setLabelStep(15); c.yAxis().setDateScale(0, 120); winChartViewer1.Chart = c; winChartViewer1.ImageMap = c.getHTMLImageMap("clickable", "", "title='噪声频率: {x}Hz, \n{dataSetName}: {value}%'"); }
/// <summary> /// Draw the chart. /// </summary> private void drawChart(WinChartViewer viewer) { // Create an XYChart object 500 x 480 pixels in size, with the same background color // as the container XYChart c = new XYChart(500, 480, Chart.CColor(BackColor)); // Set the plotarea at (50, 40) and of size 400 x 400 pixels. Use light grey (c0c0c0) // horizontal and vertical grid lines. Set 4 quadrant coloring, where the colors of // the quadrants alternate between lighter and deeper grey (dddddd/eeeeee). c.setPlotArea(50, 40, 400, 400, -1, -1, -1, 0xc0c0c0, 0xc0c0c0 ).set4QBgColor(0xdddddd, 0xeeeeee, 0xdddddd, 0xeeeeee, 0x000000); // Enable clipping mode to clip the part of the data that is outside the plot area. c.setClipping(); // Set 4 quadrant mode, with both x and y axes symetrical around the origin c.setAxisAtOrigin(Chart.XYAxisAtOrigin, Chart.XAxisSymmetric + Chart.YAxisSymmetric); // Add a legend box at (450, 40) (top right corner of the chart) with vertical layout // and 8 pts Arial Bold font. Set the background color to semi-transparent grey. LegendBox legendBox = c.addLegend(450, 40, true, "arialbd.ttf", 8); legendBox.setAlignment(Chart.TopRight); legendBox.setBackground(0x40dddddd); // Add a titles to axes c.xAxis().setTitle("Alpha Index"); c.yAxis().setTitle("Beta Index"); // Set axes width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // The default ChartDirector settings has a denser y-axis grid spacing and less-dense // x-axis grid spacing. In this demo, we want the tick spacing to be symmetrical. // We use around 50 pixels between major ticks and 25 pixels between minor ticks. c.xAxis().setTickDensity(50, 25); c.yAxis().setTickDensity(50, 25); // // In this example, we represent the data by scatter points. If you want to represent // the data by somethings else (lines, bars, areas, floating boxes, etc), just modify // the code below to use the layer type of your choice. // // Add scatter layer, using 11 pixels red (ff33333) X shape symbols c.addScatterLayer(dataX0, dataY0, "Group A", Chart.Cross2Shape(), 11, 0xff3333); // Add scatter layer, using 11 pixels green (33ff33) circle symbols c.addScatterLayer(dataX1, dataY1, "Group B", Chart.CircleShape, 11, 0x33ff33); // Add scatter layer, using 11 pixels blue (3333ff) triangle symbols c.addScatterLayer(dataX2, dataY2, "Group C", Chart.TriangleSymbol, 11, 0x3333ff); if (maxX == minX) { // The axis scale has not yet been set up. So this is the first time the chart is // drawn and it is drawn with no zooming. We can use auto-scaling to determine the // axis-scales, then remember them for future use. // Explicitly auto-scale axes so we can get the axis scales c.layout(); // Save the axis scales for future use minX = c.xAxis().getMinValue(); maxX = c.xAxis().getMaxValue(); minY = c.yAxis().getMinValue(); maxY = c.yAxis().getMaxValue(); } else { // Compute the zoomed-in axis scales using the overall axis scales and ViewPort size double xScaleMin = minX + (maxX - minX) * viewer.ViewPortLeft; double xScaleMax = minX + (maxX - minX) * (viewer.ViewPortLeft + viewer.ViewPortWidth); double yScaleMin = maxY - (maxY - minY) * (viewer.ViewPortTop + viewer.ViewPortHeight); double yScaleMax = maxY - (maxY - minY) * viewer.ViewPortTop; // *** use the following formula if you are using a log scale axis *** // double xScaleMin = minX * Math.Pow(maxX / minX, viewer.ViewPortLeft); // double xScaleMax = minX * Math.Pow(maxX / minX, viewer.ViewPortLeft + // viewer.ViewPortWidth); // double yScaleMin = maxY * Math.Pow(minY / maxY, viewer.ViewPortTop + // viewer.ViewPortHeight); // double yScaleMax = maxY * Math.Pow(minY / maxY, viewer.ViewPortTop); // Set the axis scales c.xAxis().setLinearScale(xScaleMin, xScaleMax); c.xAxis().setRounding(false, false); c.yAxis().setLinearScale(yScaleMin, yScaleMax); c.yAxis().setRounding(false, false); } // Set the chart image to the WinChartViewer winChartViewer1.Chart = c; }
//Main code for creating chart. //Note: the argument img is unused because this demo only has 1 chart. public void createChart(WinChartViewer viewer, string img) { // Data for the chart double[] data0 = { 1700, 3900, 2900, 3800, 4100, 4600, 2900, 4100, 4400, 5700, 5900, 5200, 3700, 3400, 5100, 5600, 5600, 6000, 7000, 7600, 6300, 6700, 7500, 6400, 8800 }; double[] data1 = { 500, 550, 670, 990, 820, 730, 800, 720, 730, 790, 860, 800, 840, 680, 740, 890, 680, 790, 730, 770, 840, 820, 800, 840, 670 } ; double[] data2 = { 46, 68, 35, 33, 38, 20, 12, 18, 15, 23, 30, 24, 28, 15, 21, 26, 46, 42, 38, 25, 23, 32, 24, 20, 25 }; double[] data3 = { 0.84, 0.82, 0.82, 0.38, 0.25, 0.52, 0.54, 0.52, 0.38, 0.51, 0.46, 0.29, 0.5, 0.55, 0.47, 0.34, 0.52, 0.33,0.21, 0.3, 0.25, 0.15, 0.18, 0.22, 0.14 }; // Labels for the chart string[] labels = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19","20", "21", "22", "23", "24" }; // Create a XYChart object of size 600 x 360 pixels. Use a vertical // gradient color from sky blue (aaccff) to white (ffffff) as background. // Set border to grey (888888). Use rounded corners. Enable soft drop // shadow. XYChart c = new XYChart(600, 360); c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight(), 0xaaccff, 0xffffff), 0x888888); c.setRoundedFrame(); c.setDropShadow(); // Add a title box to the chart using 15 pts Arial Bold Italic font. Set // top margin to 16 pixels. ChartDirector.TextBox title = c.addTitle("Multiple Axes Demonstration", "Arial Bold Italic", 15); title.setMargin2(0, 0, 16, 0); // Set the plotarea at (100, 80) and of size 400 x 230 pixels, with white // (ffffff) background. Use grey #(aaaaa) dotted lines for both // horizontal and vertical grid lines. c.setPlotArea(100, 80, 400, 230, 0xffffff, -1, -1, c.dashLineColor( 0xaaaaaa, Chart.DotLine), -1); // Add a legend box with the bottom center anchored at (300, 80) (top // center of the plot area). Use horizontal layout, and 8 points Arial // Bold font. Set background and border to transparent. LegendBox legendBox = c.addLegend(300, 80, false, "Arial Bold", 8); legendBox.setAlignment(Chart.BottomCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Set the labels on the x axis. c.xAxis().setLabels(labels); // Display 1 out of 3 labels on the x-axis. c.xAxis().setLabelStep(3); // Add a title to the x-axis c.xAxis().setTitle("Hour of Day"); // Add a title on top of the primary (left) y axis. c.yAxis().setTitle("Power\n(Watt)").setAlignment(Chart.TopLeft2); // Set the axis, label and title colors for the primary y axis to red // (c00000) to match the first data set c.yAxis().setColors(0xcc0000, 0xcc0000, 0xcc0000); // Add a title on top of the secondary (right) y axis. c.yAxis2().setTitle("Load\n(Mbps)").setAlignment(Chart.TopRight2); // Set the axis, label and title colors for the secondary y axis to green // (00800000) to match the second data set c.yAxis2().setColors(0x008000, 0x008000, 0x008000); // Add the third y-axis at 50 pixels to the left of the plot area Axis leftAxis = c.addAxis(Chart.Left, 50); // Add a title on top of the third y axis. leftAxis.setTitle("Temp\n(C)").setAlignment(Chart.TopLeft2); // Set the axis, label and title colors for the third y axis to blue // (0000cc) to match the third data set leftAxis.setColors(0x0000cc, 0x0000cc, 0x0000cc); // Add the fouth y-axis at 50 pixels to the right of the plot area Axis rightAxis = c.addAxis(Chart.Right, 50); // Add a title on top of the fourth y axis. rightAxis.setTitle("Error\n(%)").setAlignment(Chart.TopRight2); // Set the axis, label and title colors for the fourth y axis to purple // (880088) to match the fourth data set rightAxis.setColors(0x880088, 0x880088, 0x880088); // Add a line layer to for the first data set using red (c00000) color, // with a line width of 2 pixels LineLayer layer0 = c.addLineLayer(data0, 0xcc0000, "Power"); layer0.setLineWidth(2); // Add a line layer to for the second data set using green (00c0000) // color, with a line width of 2 pixels. Bind the layer to the secondary // y-axis. LineLayer layer1 = c.addLineLayer(data1, 0x008000, "Load"); layer1.setLineWidth(2); layer1.setUseYAxis2(); // Add a line layer to for the third data set using blue (0000cc) color, // with a line width of 2 pixels. Bind the layer to the third y-axis. LineLayer layer2 = c.addLineLayer(data2, 0x0000cc, "Temperature"); layer2.setLineWidth(2); layer2.setUseYAxis(leftAxis); // Add a line layer to for the fourth data set using purple (880088) // color, with a line width of 2 pixels. Bind the layer to the fourth // y-axis. LineLayer layer3 = c.addLineLayer(data3, 0x880088, "Error Rate"); layer3.setLineWidth(2); layer3.setUseYAxis(rightAxis); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} at hour {xLabel} = {value}'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WPFChartViewer viewer, int chartIndex) { // XY points for the scatter chart double[] dataX0 = { 10, 15, 6, -12, 14, -8, 13, -13, 16, 12, 10.5 }; double[] dataY0 = { 130, 150, 80, 110, -110, -105, -130, 115, -170, 125, 125 }; double[] dataX1 = { 6, 7, -4, 3.5, 7, 8, -9, -10, -12, 11, 8 }; double[] dataY1 = { 65, -40, -40, 45, -70, -80, 80, 10, -100, 105, 60 }; double[] dataX2 = { -10, -12, 11, 8, 6, 12, -4, 3.5, 7, 8, -9 }; double[] dataY2 = { 65, -80, -40, 45, -70, -80, 80, 90, -100, 105, 60 }; // Create a XYChart object of size 600 x 300 pixels, with a light blue (ccccff) // background, a black border, and 1 pixel 3D border effect XYChart c = new XYChart(600, 480, 0xccccff, 0x000000, 1); // Add a title box to the chart using 16pt Arial Bold Italic font, with white text on // deep blue background c.addTitle("Four Quadrant Chart Demonstration", "Arial Bold Italic", 16, 0xffffff ).setBackground(0x000080); // Set the plotarea at (20, 60) and of size 560 x 360 pixels, with grey (808080) border, // and light grey (c0c0c0) horizontal and vertical grid lines. Set 4 quadrant coloring, // where the colors of the quadrants alternate between lighter and deeper grey // (dddddd/eeeeee) c.setPlotArea(20, 60, 560, 360, -1, -1, 0x808080, 0xc0c0c0, 0xc0c0c0).set4QBgColor( 0xdddddd, 0xeeeeee, 0xdddddd, 0xeeeeee); // Set 4 quadrant mode, with both x and y axes symetrical around the origin c.setAxisAtOrigin(Chart.XYAxisAtOrigin, Chart.XAxisSymmetric + Chart.YAxisSymmetric); // Add a legend box at (300, 460) (bottom center of the chart) with horizontal layout. // Use 8pt Arial Bold font. LegendBox legendBox = c.addLegend(300, 460, false, "Arial Bold", 8); legendBox.setAlignment(Chart.BottomCenter); // Set legend box background to light grey (dddddd) with a black border legendBox.setBackground(0xdddddd, 0); // Set left/right margin to 20 pixels and top/bottom margin to 5 pixels legendBox.setMargin2(20, 20, 5, 5); // Add a titles to axes c.xAxis().setTitle("Alpha Index"); c.yAxis().setTitle("Beta Index"); // Set axes width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // Add scatter layer, using 15 pixels red (ff33333) X shape symbols c.addScatterLayer(dataX0, dataY0, "Group A", Chart.Cross2Shape(), 15, 0xff3333); // Add scatter layer, using 15 pixels green (33ff33) 6-sided polygon symbols c.addScatterLayer(dataX1, dataY1, "Group B", Chart.PolygonShape(6), 15, 0x33ff33); // Add scatter layer, using 15 pixels blue (3333ff) triangle symbols c.addScatterLayer(dataX2, dataY2, "Group C", Chart.TriangleSymbol, 15, 0x3333ff); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{dataSetName}] Alpha = {x}, Beta = {value}'"); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // Data points which more unevenly spaced in time double[] data0Y = { 62, 69, 53, 58, 84, 76, 49, 61, 64, 77, 79 }; DateTime[] data0X = { new DateTime(2007, 1, 1), new DateTime(2007, 1, 2), new DateTime(2007, 1, 5), new DateTime(2007, 1, 7), new DateTime(2007, 1,10), new DateTime(2007, 1, 14), new DateTime(2007, 1, 17), new DateTime(2007, 1, 18), new DateTime(2007, 1, 19), new DateTime(2007, 1, 20), new DateTime(2007, 1, 21) }; // Data points which are evenly spaced in a certain time range double[] data1Y = { 36, 25, 28, 38, 20, 30, 27, 35, 65, 60, 40, 73, 62, 90, 75, 72 }; DateTime data1Start = new DateTime(2007, 1, 1); DateTime data1End = new DateTime(2007, 1, 16); // Data points which are evenly spaced in another time range, in which the spacing is // different from the above series double[] data2Y = { 25, 15, 30, 23, 32, 55, 45 }; DateTime data2Start = new DateTime(2007, 1, 9); DateTime data2End = new DateTime(2007, 1, 21); // Create a XYChart object of size 600 x 400 pixels. Use a vertical gradient color from light // blue (99ccff) to white (ffffff) spanning the top 100 pixels as background. Set border to // grey (888888). Use rounded corners. Enable soft drop shadow. XYChart c = new XYChart(600, 400); c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888); c.setRoundedFrame(); c.setDropShadow(); // Add a title using 18pt Times New Roman Bold Italic font. Set top margin to 16 pixels. c.addTitle("Product Line Order Backlog", "Times New Roman Bold Italic", 18).setMargin2(0, 0, 16, 0); // Set the plotarea at (60, 80) and of 510 x 275 pixels in size. Use transparent border and // dark grey (444444) dotted grid lines PlotArea plotArea = c.setPlotArea(60, 80, 510, 275, -1, -1, Chart.Transparent, c.dashLineColor(0x444444, 0x0101), -1); // Add a legend box where the top-center is anchored to the horizontal center of the plot // area at y = 45. Use horizontal layout and 10 points Arial Bold font, and transparent // background and border. LegendBox legendBox = c.addLegend(plotArea.getLeftX() + plotArea.getWidth() / 2, 45, false, "Arial Bold", 10); legendBox.setAlignment(Chart.TopCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Set x-axis tick density to 75 pixels and y-axis tick density to 30 pixels. ChartDirector // auto-scaling will use this as the guidelines when putting ticks on the x-axis and y-axis. c.yAxis().setTickDensity(30); c.xAxis().setTickDensity(75); // Set all axes to transparent c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); // Set the x-axis margins to 15 pixels, so that the horizontal grid lines can extend beyond // the leftmost and rightmost vertical grid lines c.xAxis().setMargin(15, 15); // Set axis label style to 8pt Arial Bold c.xAxis().setLabelStyle("Arial Bold", 8); c.yAxis().setLabelStyle("Arial Bold", 8); c.yAxis2().setLabelStyle("Arial Bold", 8); // Add axis title using 10pt Arial Bold Italic font c.yAxis().setTitle("Backlog in USD millions", "Arial Bold Italic", 10); // Add the first data series LineLayer layer0 = c.addLineLayer2(); layer0.addDataSet(data0Y, 0xff0000, "Quantum Computer").setDataSymbol( Chart.GlassSphere2Shape, 11); layer0.setXData(data0X); layer0.setLineWidth(3); // Add the second data series LineLayer layer1 = c.addLineLayer2(); layer1.addDataSet(data1Y, 0x00ff00, "Atom Synthesizer").setDataSymbol( Chart.GlassSphere2Shape, 11); layer1.setXData2(data1Start, data1End); layer1.setLineWidth(3); // Add the third data series LineLayer layer2 = c.addLineLayer2(); layer2.addDataSet(data2Y, 0xff6600, "Proton Cannon").setDataSymbol(Chart.GlassSphere2Shape, 11); layer2.setXData2(data2Start, data2End); layer2.setLineWidth(3); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='Backlog of {dataSetName} at {x|mm/dd/yyyy}: US$ {value}M'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WPFChartViewer viewer, int chartIndex) { // The data for the bar chart double[] data0 = { 100, 125, 245, 147, 67 }; double[] data1 = { 85, 156, 179, 211, 123 }; double[] data2 = { 97, 87, 56, 267, 157 }; // The labels for the bar chart string[] labels = { "Mon", "Tue", "Wed", "Thu", "Fri" }; // Create a XYChart object of size 500 x 320 pixels. Use a vertical gradient color from // pale blue (e8f0f8) to sky blue (aaccff) spanning half the chart height as background. // Set border to blue (88aaee). Use rounded corners. Enable soft drop shadow. XYChart c = new XYChart(500, 320); c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight() / 2, 0xe8f0f8, 0xaaccff), 0x88aaee); c.setRoundedFrame(); c.setDropShadow(); // Add a title to the chart using 15 points Arial Italic. Set top/bottom margins to 15 // pixels. ChartDirector.TextBox title = c.addTitle("Weekly Product Sales", "Arial Italic", 15); title.setMargin2(0, 0, 15, 15); // Tentatively set the plotarea to 50 pixels from the left edge, and to just under the // title. Set the width to 60% of the chart width, and the height to 50 pixels from the // bottom edge. Use pale blue (e8f0f8) background, transparent border, and grey (aaaaaa) // grid lines. c.setPlotArea(50, title.getHeight(), c.getWidth() * 6 / 10, c.getHeight() - title.getHeight() - 50, 0xe8f0f8, -1, Chart.Transparent, 0xaaaaaa); // Add a legend box where the top-right corner is anchored at 10 pixels from the right // edge, and just under the title. Use vertical layout and 8 points Arial font. LegendBox legendBox = c.addLegend(c.getWidth() - 10, title.getHeight(), true, "Arial", 8 ); legendBox.setAlignment(Chart.TopRight); // Set the legend box background and border to transparent legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Set the legend box icon size to 16 x 32 pixels to match with custom icon size legendBox.setKeySize(16, 32); // Set axes to transparent c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); // Set the labels on the x axis c.xAxis().setLabels(labels); // Add a percentage bar layer BarLayer layer = c.addBarLayer2(Chart.Percentage); // Add the three data sets to the bar layer, using icons images with labels as data set // names layer.addDataSet(data0, 0x66aaee, "<*block,valign=absmiddle*><*img=service.png*> Service<*/*>"); layer.addDataSet(data1, 0xeebb22, "<*block,valign=absmiddle*><*img=software.png*> Software<*/*>"); layer.addDataSet(data2, 0xcc88ff, "<*block,valign=absmiddle*><*img=computer.png*> Hardware<*/*>"); // Use soft lighting effect with light direction from top layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Top)); // Enable data label at the middle of the the bar layer.setDataLabelStyle().setAlignment(Chart.Center); // For a vertical stacked chart with positive data only, the last data set is always on // top. However, in a vertical legend box, the last data set is at the bottom. This can // be reversed by using the setLegend method. layer.setLegend(Chart.ReverseLegend); // Adjust the plot area size, such that the bounding box (inclusive of axes) is 15 // pixels from the left edge, just below the title, 10 pixels to the right of the legend // box, and 15 pixels from the bottom edge. c.packPlotArea(15, title.getHeight(), c.layoutLegend().getLeftX() - 10, c.getHeight() - 15); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} revenue on {xLabel}: US${value}K ({percent}%)'"); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // In this example, the data points are unevenly spaced on the x-axis double[] dataY = { 4.7, 4.7, 6.6, 2.2, 4.7, 4.0, 4.0, 5.1, 4.5, 4.5, 6.8, 4.5, 4, 2.1, 3, 2.5, 2.5, 3.1 }; DateTime[] dataX = { new DateTime(1999, 7, 1), new DateTime(2000, 1, 1), new DateTime(2000, 2, 1), new DateTime(2000, 4, 1), new DateTime(2000, 5, 8), new DateTime(2000, 7, 5), new DateTime(2001, 3, 5), new DateTime(2001, 4, 7), new DateTime(2001, 5, 9), new DateTime(2002, 2, 4), new DateTime(2002, 4, 4), new DateTime(2002, 5, 8), new DateTime(2002, 7, 7), new DateTime(2002, 8, 30), new DateTime(2003, 1, 2), new DateTime(2003, 2, 16), new DateTime(2003, 11, 6), new DateTime(2004, 1, 4) }; // Data points are assigned different symbols based on point type double[] pointType = { 0, 1, 0, 1, 2, 1, 0, 0, 1, 1, 2, 2, 1, 0, 2, 1, 2, 0 }; // Create a XYChart object of size 480 x 320 pixels. Use a vertical gradient color from pale // blue (e8f0f8) to sky blue (aaccff) spanning half the chart height as background. Set // border to blue (88aaee). Use rounded corners. Enable soft drop shadow. XYChart c = new XYChart(480, 320); c.setBackground(c.linearGradientColor(0, 0, 0, c.getHeight() / 2, 0xe8f0f8, 0xaaccff), 0x88aaee); c.setRoundedFrame(); c.setDropShadow(); // Add a title to the chart using 15 points Arial Italic font. Set top/bottom margins to 12 // pixels. ChartDirector.TextBox title = c.addTitle("Multi-Symbol Line Chart Demo", "Arial Italic", 15); title.setMargin2(0, 0, 12, 12); // Tentatively set the plotarea to 50 pixels from the left edge to allow for the y-axis, and // to just under the title. Set the width to 65 pixels less than the chart width, and the // height to reserve 90 pixels at the bottom for the x-axis and the legend box. Use pale blue // (e8f0f8) background, transparent border, and grey (888888) dotted horizontal and vertical // grid lines. c.setPlotArea(50, title.getHeight(), c.getWidth() - 65, c.getHeight() - title.getHeight() - 90, 0xe8f0f8, -1, Chart.Transparent, c.dashLineColor(0x888888, Chart.DotLine), -1); // Add a legend box where the bottom-center is anchored to the 12 pixels above the // bottom-center of the chart. Use horizontal layout and 8 points Arial font. LegendBox legendBox = c.addLegend(c.getWidth() / 2, c.getHeight() - 12, false, "Arial Bold", 8); legendBox.setAlignment(Chart.BottomCenter); // Set the legend box background and border to pale blue (e8f0f8) and bluish grey (445566) legendBox.setBackground(0xe8f0f8, 0x445566); // Use rounded corners of 5 pixel radius for the legend box legendBox.setRoundedCorners(5); // Set the y axis label format to display a percentage sign c.yAxis().setLabelFormat("{value}%"); // Set y-axis title to use 10 points Arial Bold Italic font c.yAxis().setTitle("Axis Title Placeholder", "Arial Bold Italic", 10); // Set axis labels to use Arial Bold font c.yAxis().setLabelStyle("Arial Bold"); c.xAxis().setLabelStyle("Arial Bold"); // We add the different data symbols using scatter layers. The scatter layers are added // before the line layer to make sure the data symbols stay on top of the line layer. // We select the points with pointType = 0 (the non-selected points will be set to NoValue), // and use yellow (ffff00) 15 pixels high 5 pointed star shape symbols for the points. (This // example uses both x and y coordinates. For charts that have no x explicitly coordinates, // use an empty array as dataX.) c.addScatterLayer(Chart.CTime(dataX), new ArrayMath(dataY).selectEQZ(pointType, Chart.NoValue ).result(), "Point Type 0", Chart.StarShape(5), 15, 0xffff00); // Similar to above, we select the points with pointType - 1 = 0 and use green (ff00) 13 // pixels high six-sided polygon as symbols. c.addScatterLayer(Chart.CTime(dataX), new ArrayMath(dataY).selectEQZ(new ArrayMath(pointType ).sub(1).result(), Chart.NoValue).result(), "Point Type 1", Chart.PolygonShape(6), 13, 0x00ff00); // Similar to above, we select the points with pointType - 2 = 0 and use red (ff0000) 13 // pixels high X shape as symbols. c.addScatterLayer(Chart.CTime(dataX), new ArrayMath(dataY).selectEQZ(new ArrayMath(pointType ).sub(2).result(), Chart.NoValue).result(), "Point Type 2", Chart.Cross2Shape(), 13, 0xff0000); // Finally, add a blue (0000ff) line layer with line width of 2 pixels LineLayer layer = c.addLineLayer(dataY, 0x0000ff); layer.setXData(Chart.CTime(dataX)); layer.setLineWidth(2); // Adjust the plot area size, such that the bounding box (inclusive of axes) is 10 pixels // from the left edge, just below the title, 25 pixels from the right edge, and 8 pixels // above the legend box. c.packPlotArea(10, title.getHeight(), c.getWidth() - 25, c.layoutLegend().getTopY() - 8); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='{x|mmm dd, yyyy}: {value}%'"); }
//Main code for creating chart. //Note: the argument chartIndex is unused because this demo only has 1 chart. public void createChart(WPFChartViewer viewer, int chartIndex) { // The data for the pie chart double[] data = { 21, 18, 15, 12, 8, 24 }; // The labels for the pie chart string[] labels = { "Labor", "Licenses", "Taxes", "Legal", "Facilities", "Production" }; // The colors to use for the sectors int[] colors = { 0x66aaee, 0xeebb22, 0xbbbbbb, 0x8844ff, 0xdd2222, 0x009900 }; // Create a PieChart object of size 600 x 320 pixels. Use a vertical gradient color from // light blue (99ccff) to white (ffffff) spanning the top 100 pixels as background. Set // border to grey (888888). Use rounded corners. Enable soft drop shadow. PieChart c = new PieChart(600, 320); c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888); c.setRoundedFrame(); c.setDropShadow(); // Add a title using 18pt Times New Roman Bold Italic font. Add 16 pixels top margin to // the title. c.addTitle("Pie Chart With Legend Demonstration", "Times New Roman Bold Italic", 18 ).setMargin2(0, 0, 16, 0); // Set the center of the pie at (160, 165) and the radius to 110 pixels c.setPieSize(160, 165, 110); // Draw the pie in 3D with a pie thickness of 25 pixels c.set3D(25); // Set the pie data and the pie labels c.setData(data, labels); // Set the sector colors c.setColors2(Chart.DataColor, colors); // Use local gradient shading for the sectors c.setSectorStyle(Chart.LocalGradientShading); // Use the side label layout method, with the labels positioned 16 pixels from the pie // bounding box c.setLabelLayout(Chart.SideLayout, 16); // Show only the sector number as the sector label c.setLabelFormat("{={sector}+1}"); // Set the sector label style to Arial Bold 10pt, with a dark grey (444444) border c.setLabelStyle("Arial Bold", 10).setBackground(Chart.Transparent, 0x444444); // Add a legend box, with the center of the left side anchored at (330, 175), and using // 10pt Arial Bold Italic font LegendBox b = c.addLegend(330, 175, true, "Arial Bold Italic", 10); b.setAlignment(Chart.Left); // Set the legend box border to dark grey (444444), and with rounded conerns b.setBackground(Chart.Transparent, 0x444444); b.setRoundedCorners(); // Set the legend box margin to 16 pixels, and the extra line spacing between the legend // entries as 5 pixels b.setMargin(16); b.setKeySpacing(0, 5); // Set the legend box icon to have no border (border color same as fill color) b.setKeyBorder(Chart.SameAsMainColor); // Set the legend text to show the sector number, followed by a 120 pixels wide block // showing the sector label, and a 40 pixels wide block showing the percentage b.setText( "<*block,valign=top*>{={sector}+1}.<*advanceTo=22*><*block,width=120*>{label}" + "<*/*><*block,width=40,halign=right*>{percent}<*/*>%"); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{label}: US${value}K ({percent}%)'"); }