// // Create chart // private void createChart(RazorChartViewer viewer) { // 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 }; string[] labels = { "Mon", "Tue", "Wed", "Thur", "Fri" }; // Create a XYChart object of size 540 x 375 pixels XYChart c = new XYChart(540, 375); // Add a title to the chart using 18pt Times Bold Italic font c.addTitle("Average Weekly Network Load", "Times New Roman Bold Italic", 18); // Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a vertical gradient // color from light blue (f9f9ff) to blue (6666ff) as background. Set border and grid lines // to white (ffffff). c.setPlotArea(50, 55, 440, 280, c.linearGradientColor(0, 55, 0, 335, 0xf9f9ff, 0x6666ff), -1, 0xffffff, 0xffffff); // Add a legend box at (50, 28) using horizontal layout. Use 10pt Arial Bold as font, with // transparent background. c.addLegend(50, 28, false, "Arial Bold", 10).setBackground(Chart.Transparent); // Set the x axis labels c.xAxis().setLabels(labels); // Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5); // Set axis label style to 8pt Arial Bold c.xAxis().setLabelStyle("Arial Bold", 8); c.yAxis().setLabelStyle("Arial Bold", 8); // Set axis line width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // Add axis title c.yAxis().setTitle("Throughput (MBytes Per Hour)"); // Add a multi-bar layer with 3 data sets BarLayer layer = c.addBarLayer2(Chart.Side); layer.addDataSet(data0, 0xff0000, "Server #1"); layer.addDataSet(data1, 0x00ff00, "Server #2"); layer.addDataSet(data2, 0xff8800, "Server #3"); // Set bar border to transparent. Use glass lighting effect with light direction from left. layer.setBorderColor(Chart.Transparent, Chart.glassEffect(Chart.NormalGlare, Chart.Left)); // Configure the bars within a group to touch each others (no gap) layer.setBarGap(0.2, Chart.TouchBar); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Output Javascript chart model to the browser to suppport tracking cursor viewer.ChartModel = c.getJsChartModel(); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // Data for the chart double[] data0 = { 100, 125, 245, 147, 67, 96, 160, 145, 97, 167, 220, 125 }; double[] data1 = { 85, 156, 179, 211, 123, 225, 127, 99, 111, 260, 175, 156 }; double[] data2 = { 97, 87, 56, 267, 157, 157, 67, 156, 77, 87, 197, 87 }; string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" }; // Create a XYChart object of size 560 x 280 pixels. XYChart c = new XYChart(560, 280); // Add a title to the chart using 14pt Arial Bold Italic font c.addTitle(" Average Weekly Network Load", "Arial Bold Italic", 14); // Set the plotarea at (50, 50) and of 500 x 200 pixels in size. Use alternating light grey // (f8f8f8) / white (ffffff) background. Set border to transparent and use grey (CCCCCC) // dotted lines as horizontal and vertical grid lines c.setPlotArea(50, 50, 500, 200, 0xffffff, 0xf8f8f8, Chart.Transparent, c.dashLineColor( 0xcccccc, Chart.DotLine), c.dashLineColor(0xcccccc, Chart.DotLine)); // Add a legend box at (50, 22) using horizontal layout. Use 10 pt Arial Bold Italic font, // with transparent background c.addLegend(50, 22, false, "Arial Bold Italic", 10).setBackground(Chart.Transparent); // Set the x axis labels c.xAxis().setLabels(labels); // Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5); // Add axis title c.yAxis().setTitle("Throughput (MBytes Per Hour)"); // Set axis line width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // Add a multi-bar layer with 3 data sets BarLayer layer = c.addBarLayer2(Chart.Side); layer.addDataSet(data0, 0xff0000, "Server #1"); layer.addDataSet(data1, 0x00ff00, "Server #2"); layer.addDataSet(data2, 0x0000ff, "Server #3"); // Set bar shape to circular (cylinder) layer.setBarShape(Chart.CircleShape); // Configure the bars within a group to touch each others (no gap) layer.setBarGap(0.2, Chart.TouchBar); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='{dataSetName} on {xLabel}: {value} MBytes/hour'"); }
//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 bar chart double[] data0 = { 100, 125, 245, 147 }; double[] data1 = { 85, 156, 179, 211 }; double[] data2 = { 97, 87, 56, 267 }; string[] labels = { "1st Quarter", "2nd Quarter", "3rd Quarter", "4th Quarter" }; // Create a XYChart object of size 600 x 350 pixels XYChart c = new XYChart(600, 350); // Add a title to the chart using 14 pts Arial Bold Italic font c.addTitle("Annual Product Revenue", "Arial Bold Italic", 14); // Set the plot area at (50, 60) and of size 500 x 240. Use two // alternative background colors (f8f8f8 and ffffff) c.setPlotArea(50, 60, 500, 240, 0xf8f8f8, 0xffffff); // Add a legend box at (55, 22) using horizontal layout, with transparent // background c.addLegend(55, 22, false).setBackground(Chart.Transparent); // Set the x axis labels c.xAxis().setLabels(labels); // Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5); // Add a multi-bar layer with 3 data sets and 9 pixels 3D depth BarLayer layer = c.addBarLayer2(Chart.Side, 9); layer.addDataSet(data0, -1, "Product A"); layer.addDataSet(data1, -1, "Product B"); layer.addDataSet(data2, -1, "Product C"); // Set data set 1 to use a bar shape of a 6-pointed star layer.setBarShape(Chart.StarShape(6), 0); // Set data set 2 to use a bar shapre of a 6-sided polygon layer.setBarShape(Chart.PolygonShape(6), 1); // Set data set 3 to use an X bar shape layer.setBarShape(Chart.Cross2Shape(), 2); // Add a title to the y-axis c.yAxis().setTitle("Revenue (USD in millions)"); // Add a title to the x axis c.xAxis().setTitle("Year 2005"); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName}: {xLabel} Revenue = {value} millions'"); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // The data for the bar chart double[] data = { -6.3, 2.3, 0.7, -3.4, 2.2, -2.9, -0.1, -0.1, 3.3, 6.2, 4.3, 1.6 }; // The labels for the bar chart string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; // Create a XYChart object of size 500 x 320 pixels XYChart c = new XYChart(500, 320); // Add a title to the chart using Arial Bold Italic font c.addTitle("Productivity Change - Year 2005", "Arial Bold Italic"); // Set the plotarea at (50, 30) and of size 400 x 250 pixels c.setPlotArea(50, 30, 400, 250); // Add a bar layer to the chart using the Overlay data combine method BarLayer layer = c.addBarLayer2(Chart.Overlay); // Select positive data and add it as data set with blue (6666ff) color layer.addDataSet(new ArrayMath(data).selectGEZ(null, Chart.NoValue).result(), 0x6666ff); // Select negative data and add it as data set with orange (ff6600) color layer.addDataSet(new ArrayMath(data).selectLTZ(null, Chart.NoValue).result(), 0xff6600); // Add labels to the top of the bar using 8 pt Arial Bold font. The font color is configured // to be red (0xcc3300) below zero, and blue (0x3333ff) above zero. layer.setAggregateLabelStyle("Arial Bold", 8, layer.yZoneColor(0, 0xcc3300, 0x3333ff)); // Set the labels on the x axis and use Arial Bold as the label font c.xAxis().setLabels(labels).setFontStyle("Arial Bold"); // Draw the y axis on the right of the plot area c.setYAxisOnRight(true); // Use Arial Bold as the y axis label font c.yAxis().setLabelStyle("Arial Bold"); // Add a title to the y axis c.yAxis().setTitle("Percentage"); // Add a light blue (0xccccff) zone for positive part of the plot area c.yAxis().addZone(0, 9999, 0xccccff); // Add a pink (0xffffcc) zone for negative part of the plot area c.yAxis().addZone(-9999, 0, 0xffcccc); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='{xLabel}: {value}%'"); }
// Thread th; // bool _IsKey = true; // int icount = 0; #region Function //private void addUC() //{ // Smart_FTY.UC.UC_DWMY ucMenu = new UC.UC_DWMY(5); // pnMenu.Controls.Add(ucMenu); // ucMenu.OnDWMYClick += mnBtnClick; //} //private void mnBtnClick(string ButtonCap, string ButtonCD) //{ // switch (ButtonCap) // { // case "btnClose": // this.Close(); // break; // } //} #region Chart public void createChart(WinChartViewer viewer, int per) { Chart.setLicenseCode("DEVP-2LSU-B4LX-YCTY-2DF2-77EE"); double[] d0 = new double[DayOfMonth]; double[] d1 = new double[DayOfMonth]; double[] d2 = new double[DayOfMonth]; // The data for the bar chart // Create a XYChart object of size 580 x 280 pixels XYChart c = new XYChart(1900, 500); // Set the plot area at (50, 50) and of size 500 x 200. Use two // alternative background colors (f8f8f8 and ffffff) c.setPlotArea(50, 50, 1720, 400, 0xf8f8f8, 0xffffff); // Add a legend box at (50, 25) using horizontal layout. Use 8pts Arial // as font, with transparent background. c.addLegend(c.getWidth() - 120, 25, false, "Calibri Bold", 18).setBackground(Chart.Transparent); // Set the x axis labels c.xAxis().setLabels(labels); // Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5); c.xAxis().setLabelStyle("Calibri Bold", 12); c.yAxis().setLabelStyle("Calibri Bold", 12); // Add a multi-bar layer with 3 data sets BarLayer layer = c.addBarLayer2(Chart.Side); ArrayMath am0 = new ArrayMath(data0); ArrayMath am1 = new ArrayMath(data1); ArrayMath am2 = new ArrayMath(data2); c.yAxis().setLinearScale(0, am2.max()); d0 = am0.mul(percentage / 100.0).result(); d1 = am1.mul(percentage / 100.0).result(); d2 = am2.mul(percentage / 100.0).result(); layer.addDataSet(d0, 0xff8080, "1 Color"); layer.addDataSet(d1, 0x008800, "2 Color"); layer.addDataSet(d2, 0x8080ff, "Total"); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='Day:{xLabel} - {value} prs'"); }
//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 bar chart double[] data0 = { 100, 125, 156, 147, 87, 124, 178, 109, 140, 106, 192, 122 }; double[] data1 = { 122, 156, 179, 211, 198, 177, 160, 220, 190, 188, 220, 270 }; double[] data2 = { 167, 190, 213, 267, 250, 320, 212, 199, 245, 267, 240, 310 }; string[] labels = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" }; // Create a XYChart object of size 580 x 280 pixels XYChart c = new XYChart(580, 280); // Add a title to the chart using 14 pts Arial Bold Italic font c.addTitle("Product Revenue For Last 3 Years", "Arial Bold Italic", 14); // Set the plot area at (50, 50) and of size 500 x 200. Use two // alternative background colors (f8f8f8 and ffffff) c.setPlotArea(50, 50, 500, 200, 0xf8f8f8, 0xffffff); // Add a legend box at (50, 25) using horizontal layout. Use 8pts Arial // as font, with transparent background. c.addLegend(50, 25, false, "Arial", 8).setBackground(Chart.Transparent); // Set the x axis labels c.xAxis().setLabels(labels); // Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5); // Add a multi-bar layer with 3 data sets BarLayer layer = c.addBarLayer2(Chart.Side); layer.addDataSet(data0, 0xff8080, "Year 2003"); layer.addDataSet(data1, 0x80ff80, "Year 2004"); layer.addDataSet(data2, 0x8080ff, "Year 2005"); // Set 50% overlap between bars layer.setOverlapRatio(0.5); // Add a title to the y-axis c.yAxis().setTitle("Revenue (USD in millions)"); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{xLabel} Revenue on {dataSetName}: {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 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 XYChart c = new XYChart(500, 320); // Set the plotarea at (100, 40) and of size 280 x 240 pixels c.setPlotArea(100, 40, 280, 240); // Add a legend box at (400, 100) c.addLegend(400, 100); // Add a title to the chart using 14 points Times Bold Itatic font c.addTitle("Weekday Network Load", "Times New Roman Bold Italic", 14); // Add a title to the y axis. Draw the title upright (font angle = 0) c.yAxis().setTitle("Average\nWorkload\n(MBytes\nPer Hour)").setFontAngle( 0); // Set the labels on the x axis c.xAxis().setLabels(labels); // Add a stacked bar layer and set the layer 3D depth to 8 pixels BarLayer layer = c.addBarLayer2(Chart.Stack, 8); // Add the three data sets to the bar layer layer.addDataSet(data0, 0xff8080, "Server # 1"); layer.addDataSet(data1, 0x80ff80, "Server # 2"); layer.addDataSet(data2, 0x8080ff, "Server # 3"); // Enable bar label for the whole bar layer.setAggregateLabelStyle(); // Enable bar label for each segment of the stacked bar layer.setDataLabelStyle(); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} on {xLabel}: {value} MBytes/hour'"); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // 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 }; string[] labels = { "Mon", "Tue", "Wed", "Thu", "Fri" }; // Create a XYChart object of size 400 x 240 pixels XYChart c = new XYChart(400, 240); // Add a title to the chart using 10 pt Arial font c.addTitle(" Average Weekday Network Load", "", 10); // Set the plot area at (50, 25) and of size 320 x 180. Use two alternative background colors // (0xffffc0 and 0xffffe0) c.setPlotArea(50, 25, 320, 180, 0xffffc0, 0xffffe0); // Add a legend box at (55, 18) using horizontal layout. Use 8 pt Arial font, with // transparent background c.addLegend(55, 18, false, "", 8).setBackground(Chart.Transparent); // Add a title to the y-axis c.yAxis().setTitle("Throughput (MBytes Per Hour)"); // Reserve 20 pixels at the top of the y-axis for the legend box c.yAxis().setTopMargin(20); // Set the x axis labels c.xAxis().setLabels(labels); // Add a multi-bar layer with 3 data sets and 3 pixels 3D depth BarLayer layer = c.addBarLayer2(Chart.Side, 3); layer.addDataSet(data0, 0xff8080, "Server #1"); layer.addDataSet(data1, 0x80ff80, "Server #2"); layer.addDataSet(data2, 0x8080ff, "Server #3"); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='{dataSetName} on {xLabel}: {value} MBytes/hour'"); }
// // 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 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}%)'"); }
/// <summary> /// Pecs the area count XSSD. /// </summary> /// <param name="dt"></param> /// <param name="name"></param> /// <returns></returns> private void PecAreaCountXssd(DataTable dt, string name) { try { string[] sdlxms = { "40KM/H以下", "40-50KM/H", "50-60KM/H", "60-70KM/H", "70-80KM/H", "80-90KM/H", "90-100KM/H", "100-110KM/H", "110-120KM/H", "120KM/H 以上" }; string[] sdlx = { "000400", "040050", "050060", "060070", "070080", "080090", "090100", "100110", "110120", "120000" }; double[] dxcl = new double[10]; double[] xxcl = new double[10]; double[] gacl = new double[10]; double[] qtcl = new double[10]; for (int i = 0; i < sdlx.Length; i++) { System.Data.DataRow[] drs = dt.Select(@"sdlx = '" + sdlx[i] + "'"); if (drs != null && drs.Length > 0) { for (int j = 0; j < drs.Length; j++) { dxcl[i] = dxcl[i] + double.Parse(drs[j]["dxcl"].ToString()); xxcl[i] = xxcl[i] + double.Parse(drs[j]["xxcl"].ToString()); gacl[i] = gacl[i] + double.Parse(drs[j]["gacl"].ToString()); qtcl[i] = qtcl[i] + double.Parse(drs[j]["qtcl"].ToString()); } } else { dxcl[i] = 0; xxcl[i] = 0; gacl[i] = 0; qtcl[i] = 0; } } double dc = 0; double xc = 0; double ga = 0; double qt = 0; for (int i = 0; i < dt.Rows.Count; i++) { dc = dc + double.Parse(dt.Rows[i]["dxcl"].ToString()); xc = xc + double.Parse(dt.Rows[i]["xxcl"].ToString()); ga = ga + double.Parse(dt.Rows[i]["gacl"].ToString()); qt = qt + double.Parse(dt.Rows[i]["qtcl"].ToString()); } string msg = "共计大型车辆:" + dc.ToString() + "条,小型车辆:" + xc.ToString() + "条,公安车辆:" + ga.ToString() + "条,其它车辆" + qt.ToString() + "条"; XYChart c = new XYChart(960, 500); c.addTitle("区间行驶速度数据统计图表" + name, "Times New Roman Bold", 15).setBackground(Chart.metalColor(0x8888ff)); c.addText(110, 475, msg); c.setBackground(Chart.metalColor(0xccccff), 0x000000, 1); c.addLegend(55, 45, false, "", 8).setBackground(Chart.Transparent); c.setPlotArea(80, 80, 800, 360, 0xffffc0, 0xffffe0); c.yAxis().setTitle("通过车辆"); c.yAxis().setTopMargin(20); c.xAxis().setLabels(sdlxms); BarLayer layer = c.addBarLayer2(Chart.Side, 3); layer.addDataSet(dxcl, 0xff8080, "大型车辆"); layer.addDataSet(xxcl, 0x80ff80, "小型车辆"); layer.addDataSet(gacl, 0xff80ff, "公安车辆"); layer.addDataSet(qtcl, 0x8080ff, "其它类型"); layer.set3D(10); layer.setBarShape(Chart.CircleShape); WebChartViewer2.Image = c.makeWebImage(Chart.PNG); WebChartViewer2.ImageMap = c.getHTMLImageMap("", "", "title='{dataSetName} on {xLabel}: {value} 辆'"); this.WebChartViewer2.Visible = true; pnlXssdData.Render(this.WebChartViewer2, RenderMode.Auto); } catch (Exception ex) { ILog.WriteErrorLog(ex); logManager.InsertLogError("PeccancyAreaQuery.aspx-PecAreaCountXssd", ex.Message + ";" + ex.StackTrace, "PecAreaCountXssd has an exception"); } }
private void createMultiBarChart() { int offset = 10; MultiBarChartData data = (MultiBarChartData)this.chartData; this.Label = data.Title; // Create a XYChart object. Use a 2 pixel 3D border. XYChart c = new XYChart(this.chartPanel.Size.Width, this.chartPanel.Size.Height, 0xeeeeff, -1, 2); // Set the plotarea c.setPlotArea(offset, offset, this.chartPanel.Size.Width - (2 * offset), this.chartPanel.Size.Height - (2 * offset), 0xffffff, -1, -1, 0xcccccc, 0xcccccc); // Add a multi-bar chart layer using the given data ChartDirector.BarLayer layer = c.addBarLayer2(ChartDirector.Chart.Side, data.BarLayers.Length); foreach (BarLayer barLayer in data.BarLayers) { layer.addDataSet(barLayer.Data, -1, barLayer.Label); } // Set the labels on the x axis to null => no labels c.yAxis().setLabelFormat(null); // output the chart this.chartPanel.Image = c.makeImage(); }
private void LoadChart(DataTable dtCuocGoiTheoNgay) { if (dtCuocGoiTheoNgay.Rows.Count > 0) { double[] arrCuocGoiTaxi = new double[dtCuocGoiTheoNgay.Rows.Count]; double[] arrCuocGoiDonDuocKhach = new double[dtCuocGoiTheoNgay.Rows.Count]; double[] arrCuocGoiTruotHoan = new double[dtCuocGoiTheoNgay.Rows.Count]; double[] arrCuocGoiKhongxe = new double[dtCuocGoiTheoNgay.Rows.Count]; double[] arrCuocGoiMoiGioi = new double[dtCuocGoiTheoNgay.Rows.Count]; double[] arrCuocGoiVangLai = new double[dtCuocGoiTheoNgay.Rows.Count]; DateTime[] lableVertical = new DateTime[dtCuocGoiTheoNgay.Rows.Count]; int MaxCuocGoi = 0; int i = 0; foreach (DataRow dr in dtCuocGoiTheoNgay.Rows) { //Ngay, TongCuocGoiTaxi,CuocGoiDonDuoc,CuocGoiTruotHoan ,CuocGoiKhongXe,CuocGoiMoiGioi,CuocGoiVangLai arrCuocGoiTaxi[i] = (int)dr["TongCuocGoiTaxi"]; arrCuocGoiDonDuocKhach[i] = (int)dr["CuocGoiDonDuoc"]; arrCuocGoiTruotHoan[i] = (int)dr["CuocGoiTruotHoan"]; arrCuocGoiKhongxe[i] = (int)dr["CuocGoiKhongXe"]; arrCuocGoiMoiGioi[i] = (int)dr["CuocGoiMoiGioi"]; arrCuocGoiVangLai[i] = (int)dr["CuocGoiVangLai"]; lableVertical[i] = DateTime.Parse(dr["Ngay"].ToString().Substring(0, 10)); if (MaxCuocGoi < (int)dr["TongCuocGoiTaxi"]) { MaxCuocGoi = (int)dr["TongCuocGoiTaxi"]; } i++; } // Create an XYChart object of size 600 x 300 pixels, with a light blue // (EEEEFF) background, black border, 1 pxiel 3D border effect and // rounded corners 490, 363 XYChart c = new XYChart(490, 363, 0xeeeeff, 0x000000, 1); c.setRoundedFrame(); // Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white // background. Turn on both horizontal and vertical grid lines with light // grey color (0xcccccc) c.setPlotArea(50, 40, 430, 280, 0xffffff, -1, -1, 0xcccccc, 0xcccccc); // c.setAntiAlias(); // Add a legend box at (50, 30) (top of the chart) with horizontal // layout. Use 9 pts Arial Bold font. Set the background and border color // to Transparent. c.addLegend(50, 30, false, "Arial Bold", 9).setBackground( Chart.Transparent); // Add a title box to the chart using 15 pts Times Bold Italic font, on a // light blue (CCCCFF) background with glass effect. white (0xffffff) on // a dark red (0x800000) background, with a 1 pixel 3D border. c.addTitle("Biểu đồ cuộc gọi taxi ", "Times New Roman Bold Italic", 15).setBackground(0xccccff, 0x000000, Chart.glassEffect()); // Add a title to the y axis c.yAxis().setTitle("Số cuộc gọi"); //c.yAxis().setLabels(lableVertical); // Set the labels on the x axis. c.xAxis().setTitle("Ngày"); // c.addStepLineLayer(); c.xAxis().setLabels(lableVertical, "{value|dd/mm}"); // c.xAxis() // Display 1 out of 3 labels on the x-axis. // c.xAxis().setLabelStep(3); // Add a title to the x axis // c.xAxis().setTitle("Jun 12, 2006"); // Add a line layer to the chart //LineLayer layer = c.addLineLayer2(); BarLayer layer = c.addBarLayer2(Chart.Stack, 8); // Set the default line width to 2 pixels //layer.setLineWidth(2); // Add the three data sets to the line layer. For demo purpose, we use a // dash line color for the last line // layer.addDataSet(arrCuocGoiTaxi , 0xff0000, "Gọi taxi"); layer.addDataSet(arrCuocGoiDonDuocKhach, 0x00eea0, "Đón được"); layer.addDataSet(arrCuocGoiTruotHoan, 0x333303, "Trượt hoãn"); layer.addDataSet(arrCuocGoiKhongxe, 0x88ff0f, "Không xe"); //layer.addDataSet(arrCuocGoiMoiGioi, 0xaa00ff, "Môi giới"); // layer.addDataSet(arrCuocGoiVangLai, 0xcc00ff, "Vãng lai"); // Enable bar label for the whole bar layer.setAggregateLabelStyle(); // Enable bar label for each segment of the stacked bar layer.setDataLabelStyle(); // output the chart viewer.Image = c.makeImage(); viewer.Image.Save(Configuration.GetReportPath() + "\\BieuDo1.jpg"); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{dataSetName}] Ngày {xLabel}: {value} Cuộc gọi'"); } }
public override void UpdateVisualization() { List<string>[] chartLabels = null; double[] dataArray = null; Image img = new Image(); List<string> xLabels = new List<string>(); // Get the Factor Labels chartLabels = GetConfigDisplayLabels(); if (chartLabels == null) { return; } for (int i = 0; i < chartLabels[0].Count; i++) { xLabels.Add(chartLabels[0][i]); } // Obtain grid if ((configDisplayPanel.Children == null) || (configDisplayPanel.Children.Count != 1) || (!(configDisplayPanel.Children[0] is Grid))) { return; } Grid grid = configDisplayPanel.Children[0] as Grid; // Clear the grid images List<UIElement> removalList = new List<UIElement>(); foreach (UIElement child in grid.Children) { if (child is Image) { removalList.Add(child); } } if (removalList.Count > 0) { foreach (UIElement child in removalList) { grid.Children.Remove(child); } } // Create the Stacked Histogram XYChart c = new XYChart(configDisplay.Width, configDisplay.Height); //c.setPlotArea(150, 50, configDisplay.Width - 200, configDisplay.Height - 100); c.setPlotArea(50, 50, configDisplay.Width - 100, configDisplay.Height - 175); //c.addLegend(20, 20); c.xAxis().setLabels(xLabels.ToArray()); // Add a stacked bar layer and set the layer 3D depth to 8 pixels BarLayer layer = c.addBarLayer2(Chart.Stack, 8); // Enable bar label for the whole bar layer.setAggregateLabelStyle(); // Enable bar label for each segment of the stacked bar layer.setDataLabelStyle(); for (int i = 0; i < chartLabels[1].Count; i++) { if (GetConfigDisplayData(i, ref dataArray)) { layer.addDataSet(dataArray, (int) barcodeColors[i], chartLabels[1][i]); } } // Generate an image of the chart System.Drawing.Image imgWinForms = c.makeImage(); BitmapImage bi = new BitmapImage(); bi.BeginInit(); MemoryStream ms = new MemoryStream(); // Save to a memory stream... imgWinForms.Save(ms, ImageFormat.Bmp); // Rewind the stream... ms.Seek(0, SeekOrigin.Begin); // Tell the WPF image to use this stream... bi.StreamSource = ms; bi.EndInit(); img.Source = bi; img.Stretch = Stretch.Uniform; Grid.SetColumn(img, 0); Grid.SetRow(img, 2); grid.Children.Add(img); }
/// <summary> /// Pecs the area count WFXW. /// </summary> /// <param name="dt"></param> /// <param name="name"></param> /// <returns></returns> private void PecAreaCountWfxw(DataTable dt, string name) { try { string[] wfxwms = { "正常车辆", "超速低于50%", "超速50-70%", "超速70-100%", "超速100%以上" }; string[] wfxw = { "0", "13031", "17215", "17216", "17217" }; double[] dxcl = new double[5]; double[] xxcl = new double[5]; double[] gacl = new double[5]; double[] qtcl = new double[5]; for (int i = 0; i < wfxw.Length; i++) { System.Data.DataRow[] drs = dt.Select(@"wfxw = '" + wfxw[i] + "'"); if (drs != null && drs.Length > 0) { for (int j = 0; j < drs.Length; j++) { dxcl[i] = dxcl[i] + double.Parse(drs[j]["dxcl"].ToString()); xxcl[i] = xxcl[i] + double.Parse(drs[j]["xxcl"].ToString()); gacl[i] = qtcl[i] + double.Parse(drs[j]["gacl"].ToString()); qtcl[i] = qtcl[i] + double.Parse(drs[j]["qtcl"].ToString()); } } else { dxcl[i] = 0; xxcl[i] = 0; gacl[i] = 0; qtcl[i] = 0; } } double dc = 0; double xc = 0; double ga = 0; double qt = 0; for (int i = 0; i < dt.Rows.Count; i++) { dc = dc + double.Parse(dt.Rows[i]["dxcl"].ToString()); xc = xc + double.Parse(dt.Rows[i]["xxcl"].ToString()); ga = ga + double.Parse(dt.Rows[i]["gacl"].ToString()); qt = qt + double.Parse(dt.Rows[i]["qtcl"].ToString()); } string msg = "共计大型车辆:" + dc.ToString() + "条,小型车辆:" + xc.ToString() + "条,公安车辆:" + ga.ToString() + "条,其它车辆" + qt.ToString() + "条"; XYChart c = new XYChart(800, 500); c.addTitle("区间违法行为数据统计图表" + name, "Times New Roman Bold", 15).setBackground(Chart.metalColor(0x8888ff)); c.addText(110, 475, msg); c.setBackground(Chart.metalColor(0xccccff), 0x000000, 1); c.addLegend(55, 45, false, "", 8).setBackground(Chart.Transparent); c.setPlotArea(80, 80, 640, 360, 0xffffc0, 0xffffe0); c.yAxis().setTitle("通过车辆"); c.yAxis().setTopMargin(20); c.xAxis().setLabels(wfxwms); BarLayer layer = c.addBarLayer2(Chart.Side, 3); layer.addDataSet(dxcl, 0xff8080, "大型车辆"); layer.addDataSet(xxcl, 0x80ff80, "小型车辆"); layer.addDataSet(gacl, 0xff80ff, "公安车辆"); layer.addDataSet(qtcl, 0x8080ff, "其它类型"); layer.set3D(10); layer.setBarShape(Chart.CircleShape); WebChartViewer1.Image = c.makeWebImage(Chart.PNG); WebChartViewer1.ImageMap = c.getHTMLImageMap("", "", "title='{dataSetName} on {xLabel}: {value} 辆'"); this.WebChartViewer1.Visible = true; pnlWfxwData.Render(this.WebChartViewer1, RenderMode.Auto); } catch (Exception ex) { ILog.WriteErrorLog(ex); logManager.InsertLogError("PeccancyAreaQuery.aspx-PecAreaCountWfxw", ex.Message + ";" + ex.StackTrace, "PecAreaCountWfxw has an exception"); } }
//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 bar chart double[] data0 = { 100, 125, 245, 147, 67 }; double[] data1 = { 85, 156, 179, 211, 123 }; double[] data2 = { 97, 87, 56, 267, 157 }; string[] labels = { "Mon", "Tue", "Wed", "Thur", "Fri" }; // Create a XYChart object of size 540 x 375 pixels XYChart c = new XYChart(540, 375); // Add a title to the chart using 18 pts Times Bold Italic font c.addTitle("Average Weekly Network Load", "Times New Roman Bold Italic", 18); // Set the plotarea at (50, 55) and of 440 x 280 pixels in size. Use a // vertical gradient color from light red (ffdddd) to dark red (880000) // as background. Set border and grid lines to white (ffffff). c.setPlotArea(50, 55, 440, 280, c.linearGradientColor(0, 55, 0, 335, 0xffdddd, 0x880000), -1, 0xffffff, 0xffffff); // Add a legend box at (50, 25) using horizontal layout. Use 10pts Arial // Bold as font, with transparent background. c.addLegend(50, 25, false, "Arial Bold", 10).setBackground( Chart.Transparent); // Set the x axis labels c.xAxis().setLabels(labels); // Draw the ticks between label positions (instead of at label positions) c.xAxis().setTickOffset(0.5); // Set axis label style to 8pts Arial Bold c.xAxis().setLabelStyle("Arial Bold", 8); c.yAxis().setLabelStyle("Arial Bold", 8); // Set axis line width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // Add axis title c.yAxis().setTitle("Throughput (MBytes Per Hour)"); // Add a multi-bar layer with 3 data sets and 4 pixels 3D depth BarLayer layer = c.addBarLayer2(Chart.Side, 4); layer.addDataSet(data0, 0xffff00, "Server #1"); layer.addDataSet(data1, 0x00ff00, "Server #2"); layer.addDataSet(data2, 0x9999ff, "Server #3"); // Set bar border to transparent. Use soft lighting effect with light // direction from top. layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Top)); // Configure the bars within a group to touch each others (no gap) layer.setBarGap(0.2, Chart.TouchBar); // Output the chart viewer.Image = c.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} on {xLabel}: {value} MBytes/hour'"); }
private void LoadChart(DataTable dtCuocGoiTheoCa) { try { if (dtCuocGoiTheoCa.Rows.Count > 0) { double[] arrCuocGoiTaxi = new double[dtCuocGoiTheoCa.Rows.Count]; double[] arrCuocGoiDonDuocKhach = new double[dtCuocGoiTheoCa.Rows.Count]; double[] arrCuocGoiTruotHoan = new double[dtCuocGoiTheoCa.Rows.Count]; double[] arrCuocGoiKhongxe = new double[dtCuocGoiTheoCa.Rows.Count]; double[] arrCuocGoiMoiGioi = new double[dtCuocGoiTheoCa.Rows.Count]; double[] arrCuocGoiVangLai = new double[dtCuocGoiTheoCa.Rows.Count]; string[] lableVertical = new string[dtCuocGoiTheoCa.Rows.Count]; int MaxCuocGoi = 0; int i = 0; foreach (DataRow dr in dtCuocGoiTheoCa.Rows) { // Ca , Tu, Den,TongTaxi,TongGoiLai,TOngKhieuNai,TongGoiKhac,Tong,TongGoiNho,TongDonDuoc,PhanTramDonDuoc, TongTruotHoan,, // TongKhongXe,PhanTramKhongXe, TongKhongXacDinh , PhanTramKhongXacDinh, TongCuocTaxiMoiGioi if (dr["TongTaxi"] != null && dr["TongTaxi"].ToString().Length > 0) { arrCuocGoiTaxi[i] = Convert.ToInt32(dr["TongTaxi"].ToString()); } else { arrCuocGoiTaxi[i] = 0; } if (dr["TongDonDuoc"] != null && dr["TongDonDuoc"].ToString().Length > 0) { arrCuocGoiDonDuocKhach[i] = (int)dr["TongDonDuoc"]; } else { arrCuocGoiDonDuocKhach[i] = 0; } if (dr["TongTruotHoan"] != null && dr["TongTruotHoan"].ToString().Length > 0) { arrCuocGoiTruotHoan[i] = (int)dr["TongTruotHoan"]; } else { arrCuocGoiTruotHoan[i] = 0; } if (dr["TongKhongXe"] != null && dr["TongKhongXe"].ToString().Length > 0) { arrCuocGoiKhongxe[i] = (int)dr["TongKhongXe"]; } else { arrCuocGoiKhongxe[i] = 0; } if (dr["TongCuocTaxiMoiGioi"] != null && dr["TongCuocTaxiMoiGioi"].ToString().Length > 0) { arrCuocGoiMoiGioi[i] = (int)dr["TongCuocTaxiMoiGioi"]; } else { arrCuocGoiMoiGioi[i] = 0; } arrCuocGoiVangLai[i] = arrCuocGoiTaxi[i] - arrCuocGoiMoiGioi[i]; lableVertical[i] = "Ca " + dr["Ca"].ToString(); i++; } // Create an XYChart object of size 600 x 300 pixels, with a light blue // (EEEEFF) background, black border, 1 pxiel 3D border effect and // rounded corners 438, 306 XYChart c = new XYChart(438, 306, 0xeeeeff, 0x000000, 1); c.setRoundedFrame(); // Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white // background. Turn on both horizontal and vertical grid lines with light // grey color (0xcccccc) c.setPlotArea(50, 40, 380, 225, 0xffffff, -1, -1, 0xcccccc, 0xcccccc); // c.setAntiAlias(); // Add a legend box at (50, 30) (top of the chart) with horizontal // layout. Use 9 pts Arial Bold font. Set the background and border color // to Transparent. c.addLegend(50, 30, false, "Arial Bold", 9).setBackground(Chart.Transparent); // Add a title box to the chart using 15 pts Times Bold Italic font, on a // light blue (CCCCFF) background with glass effect. white (0xffffff) on // a dark red (0x800000) background, with a 1 pixel 3D border. c.addTitle("Biểu đồ cuộc gọi taxi theo ca", "Times New Roman Bold Italic", 15).setBackground(0xccccff, 0x000000, Chart.glassEffect()); // Add a title to the y axis c.yAxis().setTitle("Số cuộc gọi"); //c.yAxis().setLabels(lableVertical); // Set the labels on the x axis. c.xAxis().setTitle("Ngày " + string.Format("{0:dd/MM/yyyy}", calTuNgay.Value)); // c.addStepLineLayer(); c.xAxis().setLabels(lableVertical); // c.xAxis() // Display 1 out of 3 labels on the x-axis. // c.xAxis().setLabelStep(3); // Add a title to the x axis // c.xAxis().setTitle("Jun 12, 2006"); // Add a line layer to the chart //LineLayer layer = c.addLineLayer2(); BarLayer layer = c.addBarLayer2(Chart.Stack, 8); // Set the default line width to 2 pixels //layer.setLineWidth(2); // Add the three data sets to the line layer. For demo purpose, we use a // dash line color for the last line // layer.addDataSet(arrCuocGoiTaxi , 0xff0000, "Gọi taxi"); layer.addDataSet(arrCuocGoiDonDuocKhach, 0x008800, "Đón được"); layer.addDataSet(arrCuocGoiTruotHoan, c.dashLineColor(0x3333ff, Chart.DashLine), "Trượt hoãn"); layer.addDataSet(arrCuocGoiKhongxe, 0xff00ff, "Không xe"); //layer.addDataSet(arrCuocGoiMoiGioi, 0xaa00ff, "Môi giới"); // layer.addDataSet(arrCuocGoiVangLai, 0xcc00ff, "Vãng lai"); // Enable bar label for the whole bar layer.setAggregateLabelStyle(); // Enable bar label for each segment of the stacked bar layer.setDataLabelStyle(); // output the chart ChartVungKieu1.Image = c.makeImage(); // ChartVungKieu1.Image.Save(Configuration.GetReportPath() + "\\BieuDo1.jpg"); //include tool tip for the chart ChartVungKieu1.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{dataSetName}] {xLabel}: {value} Cuộc gọi'"); } } catch (Exception ex) { } }
//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, 125, 245, 147, 67 }; double[] data1 = { 85, 156, 179, 211, 123 }; double[] data2 = { 97, 87, 56, 267, 157 }; string[] labels = { "Mon Jun 4", "Tue Jun 5", "Wed Jun 6", "Thu Jun 7", "Fri Jun 8" }; // Create a XYChart object of size 540 x 350 pixels XYChart c = new XYChart(540, 350); // Set the plot area to start at (120, 40) and of size 280 x 240 pixels c.setPlotArea(120, 40, 280, 240); // Add a title to the chart using 20pt Times Bold Italic (timesbi.ttf) font and using a // deep blue color (0x000080) c.addTitle("Weekly Server Load", "Times New Roman Bold Italic", 20, 0x000080); // Add a legend box at (420, 100) (right of plot area) using 12pt Times Bold font. Sets // the background of the legend box to light grey 0xd0d0d0 with a 1 pixel 3D border. c.addLegend(420, 100, true, "Times New Roman Bold", 12).setBackground(0xd0d0d0, 0xd0d0d0, 1); // Add a title to the y-axis using 12pt Arial Bold/deep blue (0x000080) font. Set the // background to yellow (0xffff00) with a 2 pixel 3D border. c.yAxis().setTitle("Throughput (per hour)", "Arial Bold", 12, 0x000080).setBackground( 0xffff00, 0xffff00, 2); // Use 10pt Arial Bold/orange (0xcc6600) font for the y axis labels c.yAxis().setLabelStyle("Arial Bold", 10, 0xcc6600); // Set the axis label format to "nnn MBytes" c.yAxis().setLabelFormat("{value} MBytes"); // Use 10pt Arial Bold/green (0x008000) font for the x axis labels. Set the label angle // to 45 degrees. c.xAxis().setLabelStyle("Arial Bold", 10, 0x008000).setFontAngle(45); // Set the labels on the x axis. c.xAxis().setLabels(labels); // Add a 3D stack bar layer with a 3D depth of 5 pixels BarLayer layer = c.addBarLayer2(Chart.Stack, 5); // Use Arial Italic as the default data label font in the bars layer.setDataLabelStyle("Arial Italic"); // Use 10pt Times Bold Italic (timesbi.ttf) as the aggregate label font. Set the // background to flesh (0xffcc66) color with a 1 pixel 3D border. layer.setAggregateLabelStyle("Times New Roman Bold Italic", 10).setBackground(0xffcc66, Chart.Transparent, 1); // Add the first data set to the stacked bar layer layer.addDataSet(data0, -1, "Server #1"); // Add the second data set to the stacked bar layer layer.addDataSet(data1, -1, "Server #2"); // Add the third data set to the stacked bar layer, and set its data label font to Arial // Bold Italic. ChartDirector.TextBox textbox = layer.addDataSet(data2, -1, "Server #3" ).setDataLabelStyle("Arial Bold Italic"); // Set the data label font color for the third data set to yellow (0xffff00) textbox.setFontColor(0xffff00); // Set the data label background color to the same color as the bar segment, with a 1 // pixel 3D border. textbox.setBackground(Chart.SameAsMainColor, Chart.Transparent, 1); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} on {xLabel}: {value} MBytes/hour'"); }
//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 line chart double[] data0 = { 410, 420, 500, 590 }; double[] data1 = { 500, 370, 680, 850 }; string[] labels = { "Q1", "Q2", "Q3", "Q4" }; // Create a XYChart object of size 600 x 400 pixels XYChart c = new XYChart(600, 400); // Add a title to the chart using 18pt 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 - // 150) 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() - 150, c.linearGradientColor(0, 55, 0, 55 + c.getHeight() - 150, 0xaaccff, 0xf9fcff), -1, -1, c.dashLineColor(unchecked ((int)0xaa000000), Chart.DotLine), -1); // Set y-axis title using 12 points Arial Bold Italic font, and set its position 10 // pixels from the axis. c.yAxis().setTitle("Revenue (USD millions)", "Arial Bold Italic", 12); c.yAxis().setTitlePos(Chart.Left, 10); // Set y-axis label style to 10 points Arial Bold and axis color to transparent c.yAxis().setLabelStyle("Arial Bold", 10); 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 bar layer to the chart with side layout BarLayer layer = c.addBarLayer2(Chart.Side); // Add two data sets to the bar layer layer.addDataSet(data0, 0xff6600, "FY 2007"); layer.addDataSet(data1, 0x0088ff, "FY 2008"); // Use soft lighting effect with light direction from the left layer.setBorderColor(Chart.Transparent, Chart.softLighting(Chart.Left)); // 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 left/right margins to 5 pixels and top/bottom margins to 3 pixels. // Set the default font size to 10 points ChartDirector.TextBox cellStyle = table.getStyle(); cellStyle.setMargin2(5, 5, 4, 3); cellStyle.setFontSize(10); // Set the first row to use Arial Bold font, with a light grey (eeeeee) background. ChartDirector.TextBox firstRowStyle = table.getRowStyle(0); firstRowStyle.setFontStyle("Arial Bold"); firstRowStyle.setBackground(0xeeeeee, Chart.LineColor); // // 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 2nd row to light grey // (eeeeee). table.appendRow(); table.appendRow().setBackground(0xeeeeee, Chart.LineColor); table.appendRow(); // Put the values of the 2 data series in the first 2 rows. Put the percentage // differences in the 3rd row. for (int i = 0; i < data0.Length; ++i) { table.setText(i, 1, (data0[i]).ToString()); table.setText(i, 2, (data1[i]).ToString()); double percentageDiff = 100.0 * (data1[i] - data0[i]) / data0[i]; // Use red or green color depending on whether the difference is positive or // negative string formatString = "<*color=008800*>+{value|1}%"; if (percentageDiff < 0) { formatString = "<*color=cc0000*>{value|1}%"; } table.setText(i, 3, c.formatValue(percentageDiff, formatString)); } // Insert a column on the left for the legend icons using Arial Bold font. table.insertCol(0).setFontStyle("Arial Bold"); // The top cell is set to transparent, so it is invisible table.getCell(0, 0).setBackground(Chart.Transparent, Chart.Transparent); // The next 2 cells are set to the legend icons and names of the 2 data series table.setText(0, 1, layer.getLegendIcon(0) + " FY 2007"); table.setText(0, 2, layer.getLegendIcon(1) + " FY 2008"); // The last cell is set to "Change" table.setText(0, 3, "Change"); // Append a column on the right for the total values. table.appendCol(); // Put "Total" in the top cell as the heading of this column table.setText(table.getColCount() - 1, 0, "Total"); // The next two cells are the total of the data series double total0 = new ArrayMath(data0).sum(); double total1 = new ArrayMath(data1).sum(); table.setText(table.getColCount() - 1, 1, (total0).ToString()); table.setText(table.getColCount() - 1, 2, (total1).ToString()); // The last cell is the percentage differences of the total double totalPercentageDiff = (total1 - total0) / total0 * 100; // Use red or green color depending on whether the difference is positive or negative string totalFormatString = "<*color=008800*>+{value|1}%"; if (totalPercentageDiff < 0) { totalFormatString = "<*color=cc0000*>{value|1}%"; } table.setText(table.getColCount() - 1, 3, c.formatValue(totalPercentageDiff, totalFormatString)); // // We now demonstrate how to adjust the plot area positions, to allow space for the // newly inserted left and right columns in the table. // // We layout the axis first in order to get the axis metrics (including table metrics) c.layoutAxes(); // If the first column is wider than the left y-axis, we need to reserve for some left // margin to ensure the first column stays within the chart. int leftMargin = 0; if (table.getColWidth(0) > c.yAxis().getThickness()) { leftMargin = table.getColWidth(0) - c.yAxis().getThickness(); } // Similarly, we need to reserve some right margin for the last column int rightMargin = table.getColWidth(table.getColCount() - 1); // Adjust the plot area size, such that the bounding box (inclusive of axes) using the // given left and right margin, plus 2 more pixels. Put the plot area 10 pixels below // the title and use 2 pixels as the bottom margin. from the left, right and bottom // edge, and is just under the legend box. c.packPlotArea(leftMargin + 2, title.getHeight() + 10, c.getWidth() - 3 - rightMargin, c.getHeight() - 3); // After determining the exact plot area position, we may adjust title position so that // it is centered relative to the plot area (instead of the chart) 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='Revenue in {xLabel} {dataSetName}: US$ {value}M'"); }
//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 bar chart double[] data0 = { 100, 115, 165, 107, 67 }; double[] data1 = { 85, 106, 129, 161, 123 }; double[] data2 = { 67, 87, 86, 167, 157 }; // The labels for the bar chart string[] labels = { "Mon", "Tue", "Wed", "Thu", "Fri" }; // Create a XYChart object of size 600 x 360 pixels XYChart c = new XYChart(600, 360); // Set default text color to dark grey (0x333333) c.setColor(Chart.TextColor, 0x333333); // Set the plotarea at (70, 20) and of size 400 x 300 pixels, with transparent // background and border and light grey (0xcccccc) horizontal grid lines c.setPlotArea(70, 20, 400, 300, Chart.Transparent, -1, Chart.Transparent, 0xcccccc); // Add a legend box at (480, 20) using vertical layout and 12pt Arial font. Set // background and border to transparent and key icon border to the same as the fill // color. LegendBox b = c.addLegend(480, 20, true, "Arial", 12); b.setBackground(Chart.Transparent, Chart.Transparent); b.setKeyBorder(Chart.SameAsMainColor); // 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); // Add a stacked bar layer BarLayer layer = c.addBarLayer2(Chart.Stack); // Add the three data sets to the bar layer layer.addDataSet(data0, 0xaaccee, "Server # 1"); layer.addDataSet(data1, 0xbbdd88, "Server # 2"); layer.addDataSet(data2, 0xeeaa66, "Server # 3"); // Set the bar border to transparent layer.setBorderColor(Chart.Transparent); // Enable labelling for the entire bar and use 12pt Arial font layer.setAggregateLabelStyle("Arial", 12); // Enable labelling for the bar segments and use 12pt Arial font with center alignment layer.setDataLabelStyle("Arial", 10).setAlignment(Chart.Center); // For a vertical stacked bar with positive data, the first data set is at the bottom. // For the legend box, by default, the first entry at the top. We can reverse the legend // order to make the legend box consistent with the stacked bar. layer.setLegendOrder(Chart.ReverseLegend); // Set the labels on the x axis. c.xAxis().setLabels(labels); // For the automatic y-axis labels, set the minimum spacing to 40 pixels. c.yAxis().setTickDensity(40); // Add a title to the y axis using dark grey (0x555555) 14pt Arial Bold font c.yAxis().setTitle("Y-Axis Title Placeholder", "Arial Bold", 14, 0x555555); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} on {xLabel}: {value} MBytes/hour'"); }
private void buildMultiBarChart() { int topMargin = 30; int bottomnMargin = 60; int leftMargin = 50; int rightMargin = 150; MultiBarChartData data = (MultiBarChartData)this.chartData; this.Text = data.Title; XYChart barChart = new XYChart(this.chartPanel.Size.Width, this.chartPanel.Size.Height, 0xeeeeff, -1, 2); barChart.setPlotArea(leftMargin, topMargin, this.chartPanel.Size.Width - (leftMargin + rightMargin), this.chartPanel.Size.Height - (topMargin + bottomnMargin), 0xffffff, -1, -1, 0xcccccc, 0xcccccc); barChart.addTitle(data.Title); barChart.addLegend(Size.Width - (rightMargin - 5), topMargin, true, "Arial Bold", 9).setBackground( ChartDirector.Chart.Transparent); // Set the labels on the x axis. barChart.xAxis().setLabels(data.XLabels); // Add a multi-bar chart layer using the given data ChartDirector.BarLayer layer = barChart.addBarLayer2(ChartDirector.Chart.Side, data.BarLayers.Length); foreach (BarLayer barLayer in data.BarLayers) { layer.addDataSet(barLayer.Data, -1, barLayer.Label); } // output the chart this.chartPanel.Image = barChart.makeImage(); }