public LegendBoxSettingsWrapper(LegendBox legendBox) { Background = new BackgroundSettingsWrapper(legendBox.Background); CornerBottomLeft = legendBox.CornerBottomLeft; CornerBottomRight = legendBox.CornerBottomRight; CornerSize = legendBox.CornerSize; CornerTopLeft = legendBox.CornerTopLeft; CornerTopRight = legendBox.CornerTopRight; DefaultCorner = legendBox.DefaultCorner; DefaultEntry = new LegendEntrySettingsWrapper(legendBox.DefaultEntry); // Скопируем ExtraEntries ExtraEntries = new LegendEntrySettingsWrapper[legendBox.ExtraEntries.Count]; for (int i = 0; i < legendBox.ExtraEntries.Count; i++) { ExtraEntries[i] = new LegendEntrySettingsWrapper(legendBox.ExtraEntries[i]); } HeaderBackground = new BackgroundSettingsWrapper(legendBox.HeaderBackground); HeaderEntry = new LegendEntrySettingsWrapper(legendBox.HeaderEntry); HeaderLabel = new LabelSettingsWrapper(legendBox.HeaderLabel); IconPath = legendBox.IconPath; InteriorLine = new LineSettingsWrapper(legendBox.InteriorLine); LabelStyle = new LabelSettingsWrapper(legendBox.LabelStyle); Line = new LineSettingsWrapper(legendBox.Line); ListTopToBottom = legendBox.ListTopToBottom; Orientation = legendBox.Orientation; Padding = legendBox.Padding; Position = (LegendBoxPosition) legendBox.Position; Shadow = new ShadowSettingsWrapper(legendBox.Shadow); Template = legendBox.Template; Visible = legendBox.Visible; }
/// <summary> /// Восстановить сохранненые значения. /// </summary> public void RestoreSettings(LegendBox legendBox) { Background.RestoreSettings(legendBox.Background); legendBox.CornerBottomLeft = CornerBottomLeft; legendBox.CornerBottomRight = CornerBottomRight; legendBox.CornerSize = CornerSize; legendBox.CornerTopLeft = CornerTopLeft; legendBox.CornerTopRight = CornerTopRight; legendBox.DefaultCorner = DefaultCorner; DefaultEntry.RestoreSettings(legendBox.DefaultEntry); legendBox.ExtraEntries.Clear(); for (int i = 0; i < ExtraEntries.Length; i++) { LegendEntry entry = new LegendEntry(); ExtraEntries[i].RestoreSettings(entry); legendBox.ExtraEntries.Add(entry); } HeaderBackground.RestoreSettings(legendBox.HeaderBackground); HeaderEntry.RestoreSettings(legendBox.HeaderEntry); HeaderLabel.RestoreSettings(legendBox.HeaderLabel); legendBox.IconPath = IconPath; InteriorLine.RestoreSettings(legendBox.InteriorLine); LabelStyle.RestoreSettings(legendBox.LabelStyle); Line.RestoreSettings(legendBox.Line); legendBox.ListTopToBottom = ListTopToBottom; legendBox.Orientation = Orientation; legendBox.Padding = Padding; legendBox.Position = Position; Shadow.RestoreSettings(legendBox.Shadow); legendBox.Template = Template; legendBox.Visible = Visible; }
//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, 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 15pts 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("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 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 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.makeImage(); //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='[{dataSetName}] ({radius}, {angle})'"); }
// // Draw the chart // private void drawChart(WinChartViewer 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. //================================================================================ XYChart c = new XYChart(Math.Max(300, viewer.Width), Math.Max(150, viewer.Height)); // 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; }
// // Draw the chart // private void drawChart(RazorChartViewer viewer) { // // Data to draw the chart. In this demo, the data buffer will be filled by a random data // generator. In real life, the data is probably stored in a buffer (eg. a database table, a // text file, or some global memory) and updated by other means. // // We use a data buffer to emulate the last 240 samples. int sampleSize = 240; double[] dataSeries1 = new double[sampleSize]; double[] dataSeries2 = new double[sampleSize]; double[] dataSeries3 = new double[sampleSize]; DateTime[] timeStamps = new DateTime[sampleSize]; // Our pseudo random number generator DateTime firstDate = DateTime.Now.AddSeconds(-timeStamps.Length); for (int i = 0; i < timeStamps.Length; ++i) { timeStamps[i] = firstDate.AddSeconds(i); double p = timeStamps[i].Ticks / 10000000; dataSeries1[i] = Math.Cos(p * 2.1) * 10 + 1 / (Math.Cos(p) * Math.Cos(p) + 0.01) + 20; dataSeries2[i] = 100 * Math.Sin(p / 27.7) * Math.Sin(p / 10.1) + 150; dataSeries3[i] = 100 * Math.Cos(p / 6.7) * Math.Cos(p / 11.9) + 150; } // Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4) background, // black (000000) border, 1 pixel raised effect, and with a rounded frame. XYChart c = new XYChart(600, 270, 0xf4f4f4, 0x000000, 0); c.setRoundedFrame(); // Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff) background. // Enable both horizontal and vertical grids by setting their colors to grey (cccccc). Set // clipping mode to clip the data lines to the plot area. c.setPlotArea(55, 62, 520, 175, 0xffffff, -1, -1, 0xcccccc, 0xcccccc); c.setClipping(); // Add a title to the chart using 15pt Times New Roman Bold Italic font, with a light grey // (dddddd) background, black (000000) border, and a glass like raised effect. c.addTitle("Field Intensity at Observation Satellite", "Times New Roman Bold Italic", 15 ).setBackground(0xdddddd, 0x000000, Chart.glassEffect()); // Add a legend box at the top of the plot area with 9pt Arial Bold font. We set the legend // box to the same width as the plot area and use grid layout (as opposed to flow or top/down // layout). This distributes the 3 legend icons evenly on top of the plot area. LegendBox b = c.addLegend2(55, 33, 3, "Arial Bold", 9); b.setBackground(Chart.Transparent, Chart.Transparent); b.setWidth(520); // Configure the y-axis with a 10pt Arial Bold axis title c.yAxis().setTitle("Intensity (V/m)", "Arial Bold", 10); // Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15 // pixels between minor ticks. This shows more minor grid lines on the chart. c.xAxis().setTickDensity(75, 15); // Set the axes width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // Set the x-axis label format c.xAxis().setLabelFormat("{value|hh:nn:ss}"); // Create a line layer to plot the lines LineLayer layer = c.addLineLayer2(); // The x-coordinates are the timeStamps. layer.setXData(timeStamps); // The 3 data series are used to draw 3 lines. Here we put the latest data values as part of // the data set name, so you can see them updated in the legend box. layer.addDataSet(dataSeries1, 0xff0000, c.formatValue(dataSeries1[dataSeries1.Length - 1], "Alpha: <*bgColor=FFCCCC*> {value|2} ")); layer.addDataSet(dataSeries2, 0x00cc00, c.formatValue(dataSeries2[dataSeries2.Length - 1], "Beta: <*bgColor=CCFFCC*> {value|2} ")); layer.addDataSet(dataSeries3, 0x0000ff, c.formatValue(dataSeries3[dataSeries3.Length - 1], "Gamma: <*bgColor=CCCCFF*> {value|2} ")); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); }
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.SideLayout, 5); // 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(); }
// // Create chart // private void createChart(RazorChartViewer viewer) { // 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 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 - 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 10pt 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.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "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 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'"); }
//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 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("Multi-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.Chart = c; //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 tasks for the gantt chart string[] labels = { "Market Research", "Define Specifications", "Overall Archiecture", "Project Planning", "Detail Design", "Software Development","Test Plan", "Testing and QA", "User Documentation" }; // The task index, start date, end date and color for each bar double[] taskNo = { 0, 0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 8 }; DateTime[] startDate = { new DateTime(2004, 8, 16), new DateTime(2004, 10, 4), 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, 4), new DateTime(2004, 10,25), new DateTime(2004, 11, 1), new DateTime(2004, 10, 18), new DateTime(2004, 11, 8) }; DateTime[] endDate = { new DateTime(2004, 8, 30), new DateTime(2004, 10, 18), 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,10, 18),new DateTime(2004, 11, 8 ), new DateTime(2004, 11, 22), new DateTime(2004, 11, 1), new DateTime(2004, 11, 22) }; int[] colors = { 0x00cc00, 0x00cc00, 0x00cc00, 0x0000cc, 0x0000cc, 0xcc0000, 0xcc0000, 0x0000cc, 0xcc0000, 0xcc0000, 0x00cc00, 0xcc0000 }; // Create a XYChart object of size 620 x 325 pixels. Set background color to light red // (0xffcccc), with 1 pixel 3D border effect. XYChart c = new XYChart(620, 325, 0xffcccc, 0x000000, 1); // Add a title to the chart using 15 points Times Bold Itatic font, with white (ffffff) text // on a dark red (800000) background c.addTitle("Mutli-Color Gantt Chart Demo", "Times New Roman Bold Italic", 15, 0xffffff ).setBackground(0x800000); // 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); // 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); // Add some symbols to the chart to represent milestones. The symbols are added using scatter // layers. We need to specify the task index, date, name, symbol shape, size and color. c.addScatterLayer(new double[] { 1 }, Chart.CTime(new DateTime[] { new DateTime(2004, 9, 13) }), "Milestone 1", Chart.Cross2Shape(), 13, 0xffff00).setHTMLImageMap("{disable}"); c.addScatterLayer(new double[] { 3 }, Chart.CTime(new DateTime[] { new DateTime(2004, 10, 4) }), "Milestone 2", Chart.StarShape(5), 15, 0xff00ff).setHTMLImageMap("{disable}"); c.addScatterLayer(new double[] { 5 }, Chart.CTime(new DateTime[] { new DateTime(2004, 11, 8) }), "Milestone 3", Chart.TriangleSymbol, 13, 0xff9933).setHTMLImageMap("{disable}"); // Add a multi-color box-whisker layer to represent the gantt bars BoxWhiskerLayer layer = c.addBoxWhiskerLayer2(Chart.CTime(startDate), Chart.CTime(endDate), null, null, null, colors); layer.setXData(taskNo); layer.setBorderColor(Chart.SameAsMainColor); // Divide the plot area height ( = 200 in this chart) by the number of tasks to get the // height of each slot. Use 80% of that as the bar height. layer.setDataWidth((int)(200 * 4 / 5 / labels.Length)); // Add a legend box at (140, 265) - bottom of the plot area. Use 8pt Arial Bold as the font // with auto-grid layout. Set the width to the same width as the plot area. Set the // backgorund to grey (dddddd). LegendBox legendBox = c.addLegend2(140, 265, Chart.AutoGrid, "Arial Bold", 8); legendBox.setWidth(461); legendBox.setBackground(0xdddddd); // The keys for the scatter layers (milestone symbols) will automatically be added to the // legend box. We just need to add keys to show the meanings of the bar colors. legendBox.addKey("Market Team", 0x00cc00); legendBox.addKey("Planning Team", 0x0000cc); legendBox.addKey("Development Team", 0xcc0000); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='{xLabel}: {top|mmm dd, yyyy} to {bottom|mmm dd, yyyy}'"); }
//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) { // 4 data points to represent the cash flow for the Q1 - Q4 double[] data = { 230, -140, 220, 330 }; // We want to plot a waterfall chart showing the 4 quarters as well as the total string[] labels = { "1st Quarter", "2nd Quarter", "3rd Quarter", "4th Quarter", "Total" }; // The top side of the bars in a waterfall chart is the accumulated data. We use the // ChartDirector ArrayMath utility to accumulate the data. The "total" is handled by // inserting a zero point at the end before accumulation (after accumulation it will // become the total). double[] boxTop = new ArrayMath(data).insert2(0, 1, data.Length).acc().result(); // The botom side of the bars is just the top side of the previous bar. So we shifted // the top side data to obtain the bottom side data. double[] boxBottom = new ArrayMath(boxTop).shift(1, 0).result(); // The last point (total) is different. Its bottom side is always 0. boxBottom[boxBottom.Length - 1] = 0; // In this example, we want to use different colors depending on the data is positive or // negative. int posColor = 0x00ff00; int negColor = 0xff0000; // Create a XYChart object of size 500 x 280 pixels. Set background color to light blue // (ccccff), with 1 pixel 3D border effect. XYChart c = new XYChart(500, 300, 0xccccff, 0x000000, 1); // Add a title to the chart using 13 points Arial Bold Itatic font, with white (ffffff) // text on a deep blue (0x80) background c.addTitle("Corporate Cash Flow - Year 2004", "Arial Bold Italic", 13, 0xffffff ).setBackground(0x000080); // Set the plotarea at (55, 50) and of size 430 x 215 pixels. Use alternative white/grey // background. c.setPlotArea(55, 50, 430, 215, 0xffffff, 0xeeeeee); // Add a legend box at (55, 25) using 8pt Arial Bold font with horizontal layout, with // transparent background and border color. LegendBox b = c.addLegend(55, 25, false, "Arial Bold", 8); b.setBackground(Chart.Transparent, Chart.Transparent); // Add keys to show the colors for positive and negative cash flows b.addKey("Positive Cash Flow", posColor); b.addKey("Negative Cash Flow", negColor); // Set the labels on the x axis using Arial Bold font c.xAxis().setLabels(labels).setFontStyle("Arial Bold"); // Set the x-axis ticks and grid lines to be between the bars c.xAxis().setTickOffset(0.5); // Use Arial Bold as the y axis label font c.yAxis().setLabelStyle("Arial Bold"); // Add a title to the y axis c.yAxis().setTitle("USD (in millions)"); // Add a box-whisker layer to represent the waterfall bars BoxWhiskerLayer layer = c.addBoxWhiskerLayer(boxTop, boxBottom); // Color the bars depending on whether it is positive or negative for (int i = 0; i < boxTop.Length; ++i) { if (boxTop[i] >= boxBottom[i]) { layer.setBoxColor(i, posColor); } else { layer.setBoxColor(i, negColor); } } // Put data labels on the bars to show the cash flow using Arial Bold font layer.setDataLabelFormat("{={top}-{bottom}}M"); layer.setDataLabelStyle("Arial Bold").setAlignment(Chart.Center); // Output the chart viewer.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{xLabel}: {={top}-{bottom}} 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 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})'"); }
//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 = { 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); // 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.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "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 chart double[] data = { 50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73, 77, 84, 82, 80, 84, 89 }; // The error data representing the error band around the data points double[] errData = { 5, 6, 5.1, 6.5, 6.6, 8, 5.4, 5.1, 4.6, 5.0, 5.2, 6.0, 4.9, 5.6, 4.8, 6.2, 7.4, 7.1, 6.5, 9.6, 12.1, 15.3, 18.5, 20.9, 24.1 }; // The timestamps for the data DateTime[] labels = { new DateTime(2001, 1, 1), new DateTime(2001, 2, 1), new DateTime( 2001, 3, 1), new DateTime(2001, 4, 1), new DateTime(2001, 5, 1), new DateTime(2001, 6, 1), new DateTime(2001, 7, 1), new DateTime(2001, 8, 1),new DateTime(2001,9, 1), new DateTime(2001, 10, 1), new DateTime(2001, 11, 1), new DateTime(2001, 12, 1), new DateTime(2002, 1, 1), new DateTime(2002, 2, 1), new DateTime(2002, 3, 1), new DateTime(2002, 4, 1), new DateTime(2002, 5, 1), new DateTime(2002, 6, 1), new DateTime(2002, 7, 1), new DateTime(2002, 8, 1), new DateTime(2002, 9, 1), new DateTime(2002, 10, 1), new DateTime(2002, 11, 1), new DateTime(2002, 12, 1), new DateTime(2003, 1, 1) }; // Create a XYChart object of size 550 x 220 pixels XYChart c = new XYChart(550, 220); // Set the plot area at (50, 10) and of size 480 x 180 pixels. Enabled both vertical and // horizontal grids by setting their colors to light grey (cccccc) c.setPlotArea(50, 10, 480, 180).setGridColor(0xcccccc, 0xcccccc); // Add a legend box (50, 10) (top of plot area) using horizontal layout. Use 8pt Arial // font. Disable bounding box (set border to transparent). LegendBox legendBox = c.addLegend(50, 10, false, "", 8); legendBox.setBackground(Chart.Transparent); // Add keys to the legend box to explain the color zones legendBox.addKey("Historical", 0x9999ff); legendBox.addKey("Forecast", 0xff9966); // Add a title to the y axis. c.yAxis().setTitle("Energy Consumption"); // Set the labels on the x axis c.xAxis().setLabels2(labels); // Set multi-style axis label formatting. Use Arial Bold font for yearly labels and // display them as "yyyy". Use default font for monthly labels and display them as // "mmm". Replace some labels with minor ticks to ensure the labels are at least 3 units // apart. c.xAxis().setMultiFormat(Chart.StartOfYearFilter(), "<*font=Arial Bold*>{value|yyyy}", Chart.StartOfMonthFilter(), "{value|mmm}", 3); // Add a line layer to the chart LineLayer layer = c.addLineLayer2(); // Create the color to draw the data line. The line is blue (0x333399) to the left of x // = 18, and become a red (0xd04040) dash line to the right of x = 18. int lineColor = layer.xZoneColor(18, 0x333399, c.dashLineColor(0xd04040, Chart.DashLine) ); // Add the data line layer.addDataSet(data, lineColor, "Average"); // We are not showing the data set name in the legend box. The name is for showing in // tool tips only. layer.setLegend(Chart.NoLegend); // Create the color to draw the err zone. The color is semi-transparent blue // (0x809999ff) to the left of x = 18, and become semi-transparent red (0x80ff9966) to // the right of x = 18. int errColor = layer.xZoneColor(18, unchecked ((int)0x809999ff), unchecked ((int)0x80ff9966)); // Add the upper border of the err zone layer.addDataSet(new ArrayMath(data).add(errData).result(), errColor, "Upper bound"); // Add the lower border of the err zone layer.addDataSet(new ArrayMath(data).sub(errData).result(), errColor, "Lower bound"); // Set the default line width to 2 pixels layer.setLineWidth(2); // In this example, we are not showing the data set name in the legend box layer.setLegend(Chart.NoLegend); // Color the region between the err zone lines c.addInterLineLayer(layer.getLine(1), layer.getLine(2), errColor); // Output the chart viewer.Chart = c; // Include tool tip for the chart. viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{dataSetName} on {xLabel|mmm yyyy}: {value} MJoule'"); }
private void drawChart(WinChartViewer viewer) { // Create an XYChart object 600 x 270 pixels in size, with light grey (f4f4f4) // background, black (000000) border, 1 pixel raised effect, and with a rounded frame. XYChart c = new XYChart(800, 650, 0xf4f4f4, 0x000000, 1); c.setRoundedFrame(Chart.CColor(BackColor)); // Set the plotarea at (55, 62) and of size 520 x 175 pixels. Use white (ffffff) // background. Enable both horizontal and vertical grids by setting their colors to // grey (cccccc). Set clipping mode to clip the data lines to the plot area. c.setPlotArea(55, 62, 640, 500, 0xffffff, -1, -1, 0xcccccc, 0xcccccc); c.setClipping(); // Add a title to the chart using 15 pts Times New Roman Bold Italic font, with a light // grey (dddddd) background, black (000000) border, and a glass like raised effect. c.addTitle("Piezo Sensors Interface Output", "Times New Roman Bold Italic", 15 ).setBackground(0xdddddd, 0x000000, Chart.glassEffect()); // Add a legend box at the top of the plot area with 9pts Arial Bold font. We set the // legend box to the same width as the plot area and use grid layout (as opposed to // flow or top/down layout). This distributes the 3 legend icons evenly on top of the // plot area. LegendBox b = c.addLegend2(55, 33, 3, "Arial Bold", 9); b.setBackground(Chart.Transparent, Chart.Transparent); b.setWidth(520); // Configure the y-axis with a 10pts Arial Bold axis title c.yAxis().setTitle("Intensity", "Arial Bold", 10); // Configure the x-axis to auto-scale with at least 75 pixels between major tick and 15 // pixels between minor ticks. This shows more minor grid lines on the chart. c.xAxis().setTickDensity(75, 15); // Set the axes width to 2 pixels c.xAxis().setWidth(2); c.yAxis().setWidth(2); // Now we add the data to the chart DateTime lastTime = timeStamps[timeStamps.Length - 1]; if (lastTime != DateTime.MinValue) { // Set up the x-axis scale. In this demo, we set the x-axis to show the last 240 // samples, with 250ms per sample. c.xAxis().setDateScale(lastTime.AddSeconds( -dataRateTimer.Interval * timeStamps.Length / 1000), lastTime); // Set the x-axis label format c.xAxis().setLabelFormat("{value|hh:nn:ss}"); // Create a line layer to plot the lines LineLayer layer = c.addLineLayer2(); //SplineLayer layer = c.addSplineLayer(); // The x-coordinates are the timeStamps. //layer.setXData(0, timeStamps.Length); layer.setXData(timeStamps); // The 3 data series are used to draw 3 lines. Here we put the latest data values // as part of the data set name, so you can see them updated in the legend box. layer.addDataSet(dataSeriesA, 0xff0000, "Alpha: <*bgColor=FFCCCC*>" + c.formatValue(dataSeriesA[dataSeriesA.Length - 1], " {value|2} ")); layer.addDataSet(dataSeriesB, 0x00cc00, "Beta: <*bgColor=CCFFCC*>" + c.formatValue(dataSeriesB[dataSeriesB.Length - 1], " {value|2} ")); //layer.addDataSet(dataSeriesC, 0x0000ff, "Gamma: <*bgColor=CCCCFF*>" + // c.formatValue(dataSeriesC[dataSeriesC.Length - 1], " {value|2} ")); } //Assign the chart to the WinChartViewer viewer.Chart = c; if (this.alarm_detected == 1) { this.AlarmDetected.Color = System.Drawing.Color.Red; } else { this.AlarmDetected.Color = System.Drawing.Color.Green; } }
// // Create chart // private void createChart(RazorChartViewer viewer) { // 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.Image = c.makeWebImage(Chart.PNG); }
//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) { // 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.Chart = c; //include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable", "", "title='{x|mmm dd, yyyy}: {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 XY data of the first data series double[] dataX = { 50, 55, 37, 24, 42, 49, 63, 72, 83, 59 }; double[] dataY = { 3.6, 2.8, 2.5, 2.3, 3.8, 3.0, 3.8, 5.0, 6.0, 3.3 }; // Create a XYChart object of size 450 x 420 pixels XYChart c = new XYChart(450, 420); // Set the plotarea at (55, 65) and of size 350 x 300 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(55, 65, 350, 300, 0xffffff, -1, 0xc0c0c0, 0xc0c0c0, -1); // Add a title to the chart using 18 point Times Bold Itatic font. c.addTitle("Server Performance", "Times New Roman Bold Italic", 18); // Add titles to the axes using 12 pts Arial Bold Italic font c.yAxis().setTitle("Response Time (sec)", "Arial Bold Italic", 12); c.xAxis().setTitle("Server Load (TPS)", "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 (dataX, dataY) ScatterLayer scatterLayer = c.addScatterLayer(dataX, dataY, "", Chart.DiamondSymbol, 11, 0x008000); // tool tip for scatter layer scatterLayer.setHTMLImageMap("", "", "title='Response time at {x} TPS: {value} sec'"); // Add a trend line layer for (dataX, dataY) TrendLayer trendLayer = c.addTrendLayer2(dataX, dataY, 0x008000); // Set the line width to 3 pixels trendLayer.setLineWidth(3); // Add a 95% confidence band for the line trendLayer.addConfidenceBand(0.95, unchecked ((int)0x806666ff)); // Add a 95% confidence band (prediction band) for the points trendLayer.addPredictionBand(0.95, unchecked ((int)0x8066ff66)); // tool tip for trend layer trendLayer.setHTMLImageMap("", "", "title='Slope = {slope|4} sec/TPS; Intercept = {intercept|4} sec'"); // Add a legend box at (50, 30) (top of the chart) with horizontal // layout. Use 10 pts Arial Bold Italic font. Set the background and // border color to Transparent. LegendBox legendBox = c.addLegend(50, 30, false, "Arial Bold Italic", 10) ; legendBox.setBackground(Chart.Transparent); // Add entries to the legend box legendBox.addKey("95% Line Confidence", unchecked ((int)0x806666ff)); legendBox.addKey("95% Point Confidence", unchecked ((int)0x8066ff66)); // Display the trend line parameters as a text table formatted using CDML ChartDirector.TextBox textbox = c.addText(56, 65, String.Format( "<*block*>Slope\nIntercept\nCorrelation\nStd Error<*/*> " + "<*block*>{0:0.0000} sec/tps\n{1:0.0000} sec\n{2:0.0000}\n" + "{3:0.0000} sec<*/*>", trendLayer.getSlope(), trendLayer.getIntercept(), trendLayer.getCorrelation(), trendLayer.getStdError()), "Arial Bold", 8); // Set the background of the text box to light grey, with a black border, // and 1 pixel 3D border textbox.setBackground(0xc0c0c0, 0, 1); // Output the chart viewer.Image = c.makeImage(); // include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("clickable"); }