با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این بخش SimpleExampleServlet را معرفی میکند که سادهترین نمونه اجرای یک منبع داده است که همراه با کتابخانه ارائه میشود. این بخش همچنین دستورالعمل های گام به گام در مورد نحوه اجرا و آزمایش SimpleExampleServlet را ارائه می دهد.
کلاس SimpleExampleServlet در بسته examples قرار دارد. این کلاس نمونه ای از ساده ترین پیاده سازی یک منبع داده را ارائه می دهد. SimpleExampleServlet از DataSourceServlet به ارث می برد، generateDataTable() پیاده سازی می کند و باید در یک کانتینر servlet اجرا شود.
یک قطعه از SimpleExampleServlet در زیر ارائه شده است. تابع generateDataTable داده ها را در معرض کتابخانه قرار می دهد. این تابع یک توضیح جدول داده ایجاد می کند، ستون های جدول داده را تعریف می کند و جدول داده ها را با داده ها پر می کند. کتابخانه تمام اقدامات مورد نیاز برای بازگرداندن جدول داده ها به تصویرسازی پرس و جو را انجام می دهد.
// This example extends DataSourceServlet
public class SimpleExampleServlet extends DataSourceServlet {
@Override
public DataTable generateDataTable(Query query, HttpServletRequest request) {
// Create a data table,
DataTable data = new DataTable();
ArrayList cd = new ArrayList();
cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal name"));
cd.add(new ColumnDescription("link", ValueType.TEXT, "Link to wikipedia"));
cd.add(new ColumnDescription("population", ValueType.NUMBER, "Population size"));
cd.add(new ColumnDescription("vegeterian", ValueType.BOOLEAN, "Vegetarian?"));
data.addColumns(cd);
// Fill the data table.
try {
data.addRowFromValues("Aye-aye", "http://en.wikipedia.org/wiki/Aye-aye", 100, true);
data.addRowFromValues("Sloth", "http://en.wikipedia.org/wiki/Sloth", 300, true);
data.addRowFromValues("Leopard", "http://en.wikipedia.org/wiki/Leopard", 50, false);
data.addRowFromValues("Tiger", "http://en.wikipedia.org/wiki/Tiger", 80, false);
} catch (TypeMismatchException e) {
System.out.println("Invalid type!");
}
return data;
}
}
اجرای و آزمایش SimpleExampleServlet
این بخش دستورالعمل هایی در مورد نحوه اجرا و آزمایش SimpleExampleServlet ارائه می دهد.
اگر قبلاً این کار را نکردهاید، برای اطلاعات در مورد پیش نیازها و دستورالعملهای نحوه دانلود و ساخت کتابخانه به بخش نصب مراجعه کنید. اگر قبلاً روی سیستم خود ندارید، مطمئن شوید که یک وب سرور را نصب کرده اید که به عنوان یک کانتینر سرولت نیز عمل می کند، مانند Apache Tomcat. دستورالعمل های این بخش مختص آپاچی تامکت در سیستم ویندوز است.
برای اجرا و آزمایش SimpleExampleServlet ، یک برنامه وب ایجاد کنید که منبع داده SimpleExampleServlet را اجرا کند، سپس یک صفحه وب نمونه را با تصویرسازی که داده های درخواست شده از منبع داده را نشان می دهد اجرا کنید. این در بخش های زیر توضیح داده شده است:
دستورالعمل های زیر را برای ایجاد یک برنامه وب در Apache Tomcat دنبال کنید یا آن را تطبیق دهید. این دستورالعمل ها مختص آپاچی تامکت در سیستم ویندوز است:
به دایرکتوری که Tomcat را در آن نصب کرده اید بروید. این در این سند به عنوان <tomcat_home> نوشته شده است.
به زیر شاخه webapps بروید.
یک زیر شاخه به نام myWebApp ایجاد کنید.
به زیر شاخه ای که ایجاد کرده اید تغییر دهید و زیر شاخه دیگری به نام WEB-INF ایجاد کنید.
به زیر شاخه WEB-INF تغییر دهید و زیر شاخه دیگری به نام lib ایجاد کنید. مسیر کامل باید <tomcat_home>/webapps/myWebApp/WEB-INF/lib باشد.
web.xml از <data_source_library_install>/examples/src/html در پوشه WEB-INF کپی کنید. جایی که <data_source_library_install> دایرکتوری است که کتابخانه منبع داده را در آن نصب کرده اید. خطوط زیر در web.xmlSimpleExampleServlet را تعریف و ترسیم می کند:
به دایرکتوری که کتابخانه منبع داده را در آن نصب کرده اید بروید. این در این سند به عنوان <data_source_library_install> نوشته شده است.
همه بستههای وابستگی را در <tomcat_home>/webapps/myWebApp/WEB-INF/lib کپی کنید. بسته ها در <data_source_library_install>/lib نصب می شوند، مگر اینکه آنها را در دایرکتوری دیگری قرار دهید.
اگر خودتان کتابخانه را ساخته اید، visualization-datasource-1.0.2.jar و visualization-datasource-examples.jar را کپی کنید. از <data_source_library_install>/build به <tomcat_home>/webapps/myWebApp/WEB-INF/lib .
اگر فایل فشرده را از حالت فشرده خارج کرده اید، visualization-datasource-1.0.2.jar و visualization-datasource-examples.jar را کپی کنید. از <data_source_library_install> به <tomcat_home>/webapps/myWebApp/WEB-INF/lib . توجه داشته باشید که شماره نسخه در نام فایل jar ممکن است بسته به آخرین شماره نسخه متفاوت باشد.
تامکت را راه اندازی کنید، یا اگر تامکت در حال اجرا است، مجددا راه اندازی کنید.
بسته به عرض صفحه نمایش، 6 تا 7 خط متن نمایش داده می شود. متن با google.visualization.Query.setResponse شروع می شود و به /Tiger'},{v:80.0},{v:false}]}]}});
این داده هایی است که توسط منبع داده شما به تصویرسازی پرس و جو بازگردانده می شود.
استفاده از تجسم برای مشاهده داده ها
فایل getting_started.html در دایرکتوری <data_source_library_install>/examples/src/html می تواند برای مشاهده تجسم داده ها استفاده شود. خط زیر که از getting_started.html گرفته شده است، سرور مورد استفاده را مشخص می کند. نقشه برداری سرورلت در مرحله 8 ایجاد یک برنامه وب در آپاچی تامکت تنظیم شد.
var query = new google.visualization.Query('simpleexample');
اگر نمی خواهید از DataSourceServlet ارث ببرید، می توانید یک منبع داده را همانطور که در Using Your Own Servlet توضیح داده شده است پیاده سازی کنید. به عنوان مثال، اگر یک servlet را از کلاس دیگری به ارث برده اید، ممکن است نخواهید از DataSourceServlet ارث بری کنید.
تاریخ آخرین بهروزرسانی 2024-07-10 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2024-07-10 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003e\u003ccode\u003eSimpleExampleServlet\u003c/code\u003e provides a basic example of a data source implementation within the library, inheriting from \u003ccode\u003eDataSourceServlet\u003c/code\u003e and requiring a servlet container to run.\u003c/p\u003e\n"],["\u003cp\u003eRunning and testing \u003ccode\u003eSimpleExampleServlet\u003c/code\u003e involves setting up a web application, like on Apache Tomcat, to host the servlet and using a visualization (like the provided \u003ccode\u003egetting_started.html\u003c/code\u003e) to display the queried data.\u003c/p\u003e\n"],["\u003cp\u003eThe setup process includes creating a web application directory structure, configuring \u003ccode\u003eweb.xml\u003c/code\u003e to define the servlet, deploying necessary library files, and accessing the servlet and visualization through specific URLs.\u003c/p\u003e\n"]]],[],null,["# Getting Started with Data Sources\n\nThis section introduces `SimpleExampleServlet`, which is\nthe simplest example implementation of a data source that is provided\nwith the library. This section also provides step-by-step instructions\non how to run and test `SimpleExampleServlet`.\n\n- [Introducing `SimpleExampleServlet`](#introducing)\n- [Running and testing `SimpleExampleServlet`](#running)\n\nIntroducing `SimpleExampleServlet`\n----------------------------------\n\nThe `SimpleExampleServlet` class is located in the `examples`\npackage. This class provides an example of the simplest implementation\nof a data source. `SimpleExampleServlet` inherits from `DataSourceServlet`,\nimplements `generateDataTable()`, and must be run\nwithin a servlet container.\n\nA snippet of `SimpleExampleServlet` is provided below. The `generateDataTable` function\nexposes data to the library. This function creates a data table description,\ndefines the data table columns, and populates the data table with data.\nThe library handles all other actions required to return the data table\nto the querying visualization. \n\n```gdscript\n// This example extends DataSourceServlet\npublic class SimpleExampleServlet extends DataSourceServlet {\n\n @Override\n public DataTable generateDataTable(Query query, HttpServletRequest request) {\n // Create a data table,\n DataTable data = new DataTable();\n ArrayList cd = new ArrayList();\n cd.add(new ColumnDescription(\"name\", ValueType.TEXT, \"Animal name\"));\n cd.add(new ColumnDescription(\"link\", ValueType.TEXT, \"Link to wikipedia\"));\n cd.add(new ColumnDescription(\"population\", ValueType.NUMBER, \"Population size\"));\n cd.add(new ColumnDescription(\"vegeterian\", ValueType.BOOLEAN, \"Vegetarian?\"));\n\n data.addColumns(cd);\n\n // Fill the data table.\n try {\n data.addRowFromValues(\"Aye-aye\", \"http://en.wikipedia.org/wiki/Aye-aye\", 100, true);\n data.addRowFromValues(\"Sloth\", \"http://en.wikipedia.org/wiki/Sloth\", 300, true);\n data.addRowFromValues(\"Leopard\", \"http://en.wikipedia.org/wiki/Leopard\", 50, false);\n data.addRowFromValues(\"Tiger\", \"http://en.wikipedia.org/wiki/Tiger\", 80, false);\n } catch (TypeMismatchException e) {\n System.out.println(\"Invalid type!\");\n }\n return data;\n }\n}\n```\n\nRunning and testing `SimpleExampleServlet`\n------------------------------------------\n\nThis section provides instructions on how to run and test `SimpleExampleServlet`.\n\nIf you haven't already done so, see the [Installation](/chart/interactive/docs/dev/dsl_install) section\nfor information about prerequisites, and instructions on how to download\nand build the library. Make sure you install a web server that also functions\nas a servlet container, such as Apache Tomcat, if you do not already have\none on your system. The instructions in this section are specific to Apache\nTomcat on a Windows system.\n\nTo run and test `SimpleExampleServlet`, create a web application\nthat\nruns the `SimpleExampleServlet` data source,\nthen run an example web\npage with a visualization showing data queried from the data\nsource. This is described in the following sections:\n\n- [Creating a Web Application on Apache Tomcat](#webapp)\n- [Using a Visualization to View the Data](#visualization)\n\n### Creating a Web Application on Apache Tomcat\n\nFollow or adapt the instructions below to create a web application\non Apache Tomcat. These instructions are specific to Apache Tomcat on a\nWindows system:\n\n1. Navigate to the directory in which you installed Tomcat. This is written in this document as `\u003ctomcat_home\u003e`. \n2. Navigate to the `webapps` subdirectory. \n3. Create a subdirectory called `myWebApp`. \n4. Change to the subdirectory you have just created and create another subdirectory called `WEB-INF`. \n5. Change to the `WEB-INF` subdirectory and create another subdirectory called `lib`. \n The full path should be `\u003ctomcat_home\u003e/webapps/myWebApp/WEB-INF/lib`. \n6. Copy `web.xml` from `\u003cdata_source_library_install\u003e/examples/src/html` to the `WEB-INF` directory. Where `\u003cdata_source_library_install\u003e` is the directory in which you installed the data source library. The following lines in `web.xml` define and map `SimpleExampleServlet`: \n\n ```carbon\n \u003cservlet\u003e\n \u003cservlet-name\u003eMy Servlet\u003c/servlet-name\u003e\n \u003cdescription\u003eMy servlet description.\u003c/description\u003e\n \u003cservlet-class\u003eSimpleExampleServlet\u003c/servlet-class\u003e\n \u003c/servlet\u003e\n\n \u003cservlet-mapping\u003e\n \u003cservlet-name\u003eMy Servlet\u003c/servlet-name\u003e\n \u003curl-pattern\u003e/simpleexample\u003c/url-pattern\u003e\n \u003c/servlet-mapping\u003e\n ```\n7. Navigate to the directory in which you installed the data source library. This is written in this document as `\u003cdata_source_library_install\u003e`. \n8. Copy all the dependency packages to `\u003ctomcat_home\u003e/webapps/myWebApp/WEB-INF/lib`. The packages are installed in `\u003cdata_source_library_install\u003e/lib`, unless you put them in a different directory. \n9. If you have built the library yourself, copy `visualization-datasource-1.0.2.jar` and `visualization-datasource-examples.jar` \n from `\u003cdata_source_library_install\u003e/build` \n to `\u003ctomcat_home\u003e/webapps/myWebApp/WEB-INF/lib`. \n\n If you have unzipped the zip file, copy `visualization-datasource-1.0.2.jar` and `visualization-datasource-examples.jar` \n from `\u003cdata_source_library_install\u003e` \n to `\u003ctomcat_home\u003e/webapps/myWebApp/WEB-INF/lib`. \n Note that the version number in the jar file name may vary depending on the latest version number. \n10. Start Tomcat, or restart Tomcat if it is already running. \n11. Click the following link: \n\n \u003chttp://localhost:8080/myWebApp/simpleexample\u003e \n\n The screen displays 6-7 lines of text, depending on your screen width. \n The text begins with `google.visualization.Query.setResponse ` \n and ends with `/Tiger'},{v:80.0},{v:false}]}]}});` \n\n This is the data that is returned by your data source to a querying visualization.\n\n### Using a Visualization\nto View the Data\n\nThe `getting_started.html` file in the `\u003cdata_source_library_install\u003e/examples/src/html` directory\ncan be used to view a visualization of the data. The following line, taken\nfrom `getting_started.html`, specifies\nthe servlet to use. The servlet mapping was set up in step 8 of [Creating\na Web Application on Apache Tomcat](#webapp). \n\n```gdscript\nvar query = new google.visualization.Query('simpleexample');\n```\n\nFor more information on how to specify a visualization and use the\nquery language, see [Using\nCharts](/chart/interactive/docs) and the [Query Language\nReference](/chart/interactive/docs/querylanguage).\n\nFollow, or adapt, the instructions below to view a visualization\nof the data provided by the data source:\n\n1. Copy the `getting_started.html` file from the `\u003cdata_source_library_install\u003e/examples/src/html` directory \n to the `\u003ctomcat_home\u003e/webapps/myWebApp/` directory. \n2. Click the following link \u003chttp://localhost:8080/myWebApp/getting_started.html\u003e, you should see the following: \n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n That's it! You have set up your first data source.\n\nNext Steps\n----------\n\nThe next example is described in the [Using an\nExternal Data Store](/chart/interactive/docs/dev/dsl_csv) section. Alternatively\nyou can return to the [Introduction](/chart/interactive/docs/dev/dsl_intro), or\nexplore the following links:\n\n- For an introduction to the library's most commonly used classes, see [Key Classes](/chart/interactive/docs/dev/dsl_packages#keyclasses).\n- For an example of how to implement your own flow of events, and query capabilities, see [Defining Capabilities and the Flow of Events](/chart/interactive/docs/dev/dsl_httpservlet).\n- If you do not want to inherit from `DataSourceServlet`, you can implement a data source as described in [Using\n Your Own Servlet](/chart/interactive/docs/dev/dsl_key_concepts#servlet). For example you might not want to inherit from `DataSourceServlet` if you inherit a servlet from another class.\n- If you do not want to use a servlet, see [Implementing a Non-servlet Data Source](/chart/interactive/docs/dev/dsl_key_concepts#nonservlet).\n- To learn about how to pass parameters from an application to a data source, see [Passing Parameters to `DataTableGenerator.generateDataTable`](/chart/interactive/docs/dev/dsl_key_concepts#params)."]]