原創|其它|編輯:郝浩|2012-10-18 09:38:57.000|閱讀 2431 次
概述:最近在嘗試在ChartDirector里進行坐標的設置,想在這里寫寫最近最近的學習成果。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
最近在嘗試在ChartDirector里進行坐標的設置,想在這里寫寫最近最近的學習成果。
下面是我的代碼實例,里面就是實現如何在ChartDirector里進行坐標的設置,代碼如下:
public void createChart(ChartViewer viewer, int index) { // 這是兩組數據,X和Y會一一對應生成;多在多縱軸圖中使用,橫坐標點會自動調整。 double[] dataY0 = { 4.5, 5}; Date[] dataX0 = { new GregorianCalendar(1999, 1, 1).getTime(), new GregorianCalendar(2000, 8, 6).getTime() }; double[] dataY1 = {7, 6.5, 6, 5, 6.5, 7, 6, 5.5, 5,9,8,7,8}; Date[] dataX1 = {new GregorianCalendar(1999, 1, 1).getTime(), new GregorianCalendar(1999, 6, 1).getTime(), new GregorianCalendar(1999, 11, 1).getTime(), new GregorianCalendar(1999, 11, 15).getTime(), new GregorianCalendar(1999, 12, 9).getTime(), new GregorianCalendar(2000, 2, 3).getTime(), new GregorianCalendar(2000, 7, 13).getTime(), new GregorianCalendar(2001, 4, 5).getTime(), new GregorianCalendar(2001, 8, 16).getTime(), new GregorianCalendar(2001, 10, 16).getTime(),new GregorianCalendar(2001, 12, 16).getTime(),new GregorianCalendar(2002, 2, 16).getTime(),new GregorianCalendar(2002, 4, 16).getTime()}; //這是單獨的橫坐標數據,橫坐標會根據數據進行調整,Y軸會按照順利一一對應。 Date[] dataX2 = { new GregorianCalendar(1999, 1, 1).getTime(), new GregorianCalendar(1999, 4, 1).getTime(), new GregorianCalendar(1999, 8, 9).getTime(), new GregorianCalendar(2000,1, 1).getTime(), new GregorianCalendar(2000, 4, 1).getTime(),new GregorianCalendar(2001, 8, 1).getTime(), }; //創建圖形的大小為 500 x 270 pixels, with a pale blue // (e0e0ff) background, black border, 1 pixel 3D border effect and rounded XYChart c = new XYChart(700, 500, 0xe0e0ff, 0x000000, 1); c.setRoundedFrame(); // 起點坐標是 (55, 60) ,圖形大小是520 x 200 pixels, with white c.setPlotArea(55, 60, 500, 300, 0xffffff, -1, -1, 0xcccccc, 0xcccccc); // Add a legend box at (55, 32) (top of the chart) with horizontal layout. // Use 9 pts Arial Bold font. Set the background and border color to // Transparent. c.addLegend(55, 32, false, "Arial Bold", 9).setBackground(Chart.Transparent); // Add a title box to the chart using 15 pts Times Bold Italic font. The text // is white (ffffff) on a deep blue (000088) background, with soft lighting // effect from the right side. c.addTitle("Long Term Interest Rates", "Times New Roman Bold Italic", 15, 0xffffff).setBackground(0x000088, -1, Chart.softLighting(Chart.Right)); // 左邊的Y軸 c.yAxis().setTitle("value").setAlignment(Chart.TopLeft2); // 右邊的Y軸 c.yAxis2().setTitle("Load\n(Mbps)").setAlignment(Chart.TopRight2); c.yAxis2().setColors(0x008000, 0x008000, 0x008000); //左邊距圖形50的Y軸 Axis leftAxis = c.addAxis(Chart.Left, 50); leftAxis.setTitle("Temp\n(C)").setAlignment(Chart.TopLeft2); leftAxis.setColors(0x0000cc, 0x0000cc, 0x0000cc); // 右邊距圖形50的Y軸 Axis rightAxis = c.addAxis(Chart.Right, 50); rightAxis.setTitle("Error\n(%)").setAlignment(Chart.TopRight2); rightAxis.setColors(0xcccccc, 0xffffff, 0xffffff); //加載兩組數據(XY是一一對應的,同時添加的) LineLayer layer0 = c.addLineLayer(dataY0, 0xff0000, "Country AAA"); layer0.setXData(dataX0); layer0.setLineWidth(1); LineLayer layer1 = c.addLineLayer(dataY1, 0x0000ff, "Country BBB"); layer1.setXData(dataX1); layer1.setLineWidth(2); layer1.setUseYAxis(leftAxis); // 橫坐標步長 c.xAxis().setLabelStep(2); // // 統一給橫坐標設值 // c.xAxis().setLabels(dataX2); // 橫坐標的標題 c.xAxis().setTitle("Hour of Day"); // output the chart viewer.setImage(c.makeImage()); //{x|mmm dd, yyyy}橫坐標的時間格式化 viewer.setImageMap(c.getHTMLImageMap("clickable", "", "title='{dataSetName} change to {value}% on {x|mmm dd, yyyy}'")); } public static void main(String[] args) { //Instantiate an instance of this demo module DemoModule demo = new multiaxes(); //Create and set up the main window JFrame frame = new JFrame(demo.toString()); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); frame.getContentPane().setBackground(Color.white); // Create the chart and put them in the content pane ChartViewer viewer = new ChartViewer(); demo.createChart(viewer, 0); frame.getContentPane().add(viewer); // Display the window frame.pack(); frame.setVisible(true); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:新浪博客