//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}%)'"); }
//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 area chart double[] data0 = { 42, 49, 33, 38, 51, 46, 29, 41, 44, 57, 59, 52, 37, 34, 51, 56, 56, 60, 70, 76, 63, 67, 75, 64, 51 }; double[] data1 = { 50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73, 77, 84, 82, 80, 84, 98 }; double[] data2 = { 87, 89, 85, 66, 53, 39, 24, 21, 37, 56, 37, 23, 21, 33, 13, 17, 14, 23, 16, 25, 29, 30, 45, 47, 46 }; // The timestamps on the x-axis DateTime[] labels = { new DateTime(1996, 1, 1), new DateTime(1996, 4, 1), new DateTime( 1996, 7, 1), new DateTime(1996, 10, 1), new DateTime(1997, 1, 1), new DateTime(1997, 4, 1), new DateTime(1997, 7, 1), new DateTime(1997, 10, 1),new DateTime(1998,1, 1 ), new DateTime(1998, 4, 1), new DateTime(1998, 7, 1), new DateTime(1998, 10,1), new DateTime(1999, 1, 1), new DateTime(1999, 4, 1), new DateTime(1999, 7, 1), new DateTime(1999, 10, 1), new DateTime(2000, 1, 1), new DateTime(2000, 4, 1), new DateTime(2000, 7, 1), new DateTime(2000, 10, 1), new DateTime(2001, 1, 1), new DateTime(2001, 4, 1), new DateTime(2001, 7, 1), new DateTime(2001, 10, 1), new DateTime(2002, 1, 1) }; // Create a XYChart object of size 500 x 280 pixels, using 0xffffcc as background color, // with a black border, and 1 pixel 3D border effect XYChart c = new XYChart(500, 280, 0xffffcc, 0, 1); // Set the plotarea at (50, 45) and of size 320 x 200 pixels with white background. // Enable horizontal and vertical grid lines using the grey (0xc0c0c0) color. c.setPlotArea(50, 45, 320, 200, 0xffffff).setGridColor(0xc0c0c0, 0xc0c0c0); // Add a legend box at (370, 45) using vertical layout and 8 points Arial Bold font. LegendBox legendBox = c.addLegend(370, 45, true, "Arial Bold", 8); // 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); // Add a title to the chart using 14 points Times Bold Itatic font and white font color, // and 0x804020 as the background color c.addTitle("Quarterly Product Sales", "Times New Roman Bold Italic", 14, 0xffffff ).setBackground(0x804020); // Set the labels on the x axis. c.xAxis().setLabels2(labels); // Set multi-style axis label formatting. Start of year labels are displayed as yyyy. // For other labels, just show minor tick. c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "{value|yyyy}", Chart.AllPassFilter( ), "-"); // Add a percentage area layer to the chart AreaLayer layer = c.addAreaLayer2(Chart.Percentage); // Add the three data sets to the area layer, using icons images with labels as data set // names layer.addDataSet(data0, 0x40ddaa77, "<*block,valign=absmiddle*><*img=service.png*> Service<*/*>"); layer.addDataSet(data1, 0x40aadd77, "<*block,valign=absmiddle*><*img=software.png*> Software<*/*>"); layer.addDataSet(data2, 0x40aa77dd, "<*block,valign=absmiddle*><*img=computer.png*> Hardware<*/*>"); // 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); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} sales at {xLabel|yyyy} Q{=({xLabel|m}+2)/3|0}: 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 x and y coordinates of the grid double[] dataX = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; double[] dataY = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Use random numbers for the z values on the XY grid RanSeries r = new RanSeries(999); double[] dataZ = r.get2DSeries(dataX.Length, dataY.Length, -0.9, 1.15); // Create a XYChart object of size 640 x 460 pixels XYChart c = new XYChart(640, 460); // Set default text color to dark grey (0x333333) c.setColor(Chart.TextColor, 0x333333); // Set the plotarea at (30, 25) and of size 400 x 400 pixels. Use semi-transparent grey // (0xdd000000) horizontal and vertical grid lines c.setPlotArea(50, 25, 400, 400, -1, -1, Chart.Transparent, unchecked ((int)0xdd000000), -1); // Set the x and y axis stems to transparent and the label font to 12pt Arial c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); c.xAxis().setLabelStyle("Arial", 12); c.yAxis().setLabelStyle("Arial", 12); // Set the x-axis and y-axis scale c.xAxis().setLinearScale(0, 10, 1); c.yAxis().setLinearScale(0, 10, 1); // Add a contour layer using the given data ContourLayer layer = c.addContourLayer(dataX, dataY, dataZ); // Move the grid lines in front of the contour layer c.getPlotArea().moveGridBefore(layer); // Define the color scale double[] colorScale = { -0.8, 0x0066ff, -0.5, 0x66ccff, -0.3, 0x66ffff, 0, 0x88ff88, 0.4, 0x00ff00, 0.7, 0xffff00, 0.9, 0xff6600, 1.0, 0xcc0000, 1.1 }; // Apply the color scale, and specify the underflow and overflow colors for regions // exceeding the color scale layer.colorAxis().setColorScale(colorScale, 0x0000cc, 0x000000); // // Instead of displaying the color axis, we use a legend box to display the colors. This // is useful for colors that are unevenly spaced on the color axis. // // Add a legend box at (460, 25) with vertical layout, with 12pt Arial font, transparent // background and border, icon size of 15 x 15 pixels, and line spacing of 8 pixels. LegendBox b = c.addLegend(460, 25, true, "Arial", 12); b.setBackground(Chart.Transparent, Chart.Transparent); b.setKeySize(15, 15); b.setKeySpacing(0, 8); // Add the legend box entries b.addKey("> 1.1 (Critical)", 0x000000); b.addKey("1.0 to 1.1 (Alert)", 0xcc0000); b.addKey("0.9 to 1.0", 0xff6600); b.addKey("0.7 to 0.9", 0xffff00); b.addKey("0.4 to 0.7", 0x00ff00); b.addKey("0.0 to 0.4", 0x88ff88); b.addKey("-0.3 to 0.0", 0x66ffff); b.addKey("-0.5 to -0.3", 0x66ccff); b.addKey("-0.8 to -0.5", 0x0066ff); b.addKey("< -0.8", 0x0000cc); // Output the chart viewer.Chart = c; }