JavaFX 2.0条形图和散点图(以及JavaFX 2.1 StackedBarCharts)

JavaFX 2.0提供了用于生成图表的内置功能,该功能可在javafx.scene.chart包中找到。 在本文中,我将介绍如何使用JavaFX 2.0创建条形图和散点图 。 在本文的学习过程中,我将一路使用Guava和一些Java 7功能。

在演示JavaFX 2.0图表API之前,第一个代码清单显示了示例中要使用的数据的配置。 在更现实的情况下,我将从数据存储中获取此数据,但是在这种情况下,我只是直接将其直接包含在源代码中,以方便示例访问。 尽管此代码本身与JavaFX 2.0图表并没有内在的联系,但还是有一些有趣的事情。 该代码在数字文字中使用了Java 7的下划线,从而使读取数据中使用的样本状态的地域大小和总体更加容易。 该代码清单还使用了Guava的ImmutableMap类(在上一篇文章中介绍了 )。

配置示例数据的代码

/** Simple U.S. state representation. */private enum State{ALASKA("Alaska"),CALIFORNIA("California"),COLORADO("Colorado"),NEW_YORK("New York"),RHODE_ISLAND("Rhode Island"),TEXAS("Texas"),WYOMING("Wyoming");private String stateName;State(final String newStateName){this.stateName = newStateName;}}/** Simple Movie representation. */private enum Movie{STAR_WARS("Star Wars"),EMPIRE_STRIKES_BACK("The Empire Strikes Back"),RAIDERS_OF_THE_LOST_ARK("Raiders of the Lost Ark"),INCEPTION("Inception"),CHRISTMAS_VACATION("Christmas Vacation"),CHRISTMAS_VACATION_2("Christmas Vacation 2"),FLETCH("Fletch");private String movieName;Movie(final String newMovieName){this.movieName = newMovieName;}}/** Mapping of state name to area of state measured in kilometers. */private final static Map<String, Long> statesLandSizeKm;/** Mapping of state name to estimated number of people living in that state. */private final static Map<String, Long> statesPopulation;/** Normal audience movie ratings on Rotten Tomatoes. */private final static Map<String, Double> movieRatingsNormal;/** Critics movie ratings on Rotten Tomatoes. */private final static Map<String, Double> movieRatingsCritics;/** Dustin's movie ratings. */private final static Map<String, Double> movieRatingsDustin;/** Maximum population to be shown on bar charts of states' populations.  */private final static long POPULATION_RANGE_MAXIMUM = 40_000_000L;/** Maximum land area (km) to be shown on bar charts of states' land areas. */private final static long LAND_AREA_KM_MAXIMUM = 1_800_000L;/** Maximum movie rating to be shown on bar charts. */private final static double MOVIE_RATING_MAXIMUM = 10.0;/** Width of chart. */private final static int CHART_WIDTH = 750;/** Height of chart. */private final static int CHART_HEIGHT = 600;/** Width of chart for Movie Ratings. */private final static int MOVIE_CHART_WIDTH = CHART_WIDTH + 350;/* Initialize final static variables. */static{statesLandSizeKm =ImmutableMap.<String, Long>builder().put(State.ALASKA.stateName, 1_717_854L).put(State.CALIFORNIA.stateName, 423_970L).put(State.COLORADO.stateName, 269_601L).put(State.NEW_YORK.stateName, 141_299L).put(State.RHODE_ISLAND.stateName, 4_002L).put(State.TEXAS.stateName, 695_621L).put(State.WYOMING.stateName, 253_336L).build();statesPopulation =ImmutableMap.<String, Long>builder().put(State.ALASKA.stateName, 722_718L).put(State.CALIFORNIA.stateName, 37_691_912L).put(State.COLORADO.stateName, 5_116_769L).put(State.NEW_YORK.stateName, 19_465_197L).put(State.RHODE_ISLAND.stateName, 1_051_302L).put(State.TEXAS.stateName, 25_674_681L).put(State.WYOMING.stateName, 568_158L).build();movieRatingsNormal =ImmutableMap.<String, Double>builder().put(Movie.CHRISTMAS_VACATION.movieName, 8.3).put(Movie.CHRISTMAS_VACATION_2.movieName, 1.3).put(Movie.STAR_WARS.movieName, 9.3).put(Movie.EMPIRE_STRIKES_BACK.movieName, 9.4).put(Movie.RAIDERS_OF_THE_LOST_ARK.movieName, 9.3).put(Movie.INCEPTION.movieName, 9.3).put(Movie.FLETCH.movieName, 7.8).build();movieRatingsCritics =ImmutableMap.<String, Double>builder().put(Movie.CHRISTMAS_VACATION.movieName, 6.3).put(Movie.CHRISTMAS_VACATION_2.movieName, 0.0).put(Movie.STAR_WARS.movieName, 9.4).put(Movie.EMPIRE_STRIKES_BACK.movieName, 9.7).put(Movie.RAIDERS_OF_THE_LOST_ARK.movieName, 9.4).put(Movie.INCEPTION.movieName, 8.6).put(Movie.FLETCH.movieName, 7.5).build();movieRatingsDustin =ImmutableMap.<String, Double>builder().put(Movie.CHRISTMAS_VACATION.movieName, 7.0).put(Movie.CHRISTMAS_VACATION_2.movieName, 0.0).put(Movie.STAR_WARS.movieName, 9.5).put(Movie.EMPIRE_STRIKES_BACK.movieName, 10.0).put(Movie.RAIDERS_OF_THE_LOST_ARK.movieName, 10.0).put(Movie.INCEPTION.movieName, 9.0).put(Movie.FLETCH.movieName, 9.0).build();                     }

下一个代码清单演示了示例应用程序的引导。 这包括通常启动Java应用程序的单行主函数,以及从扩展Application类中重写的更有趣的start(String [])方法。 此代码清单还利用Java 7的Strings-on-Strings功能对命令行参数解析进行了快速而又肮脏的实现,以运行特定的图表生成演示。 该示例演示了传递给Application.launch(String ...)的命令行参数可通过Application.getParameters()方法返回给嵌套的Application.Parameters实例的JavaFX应用程序使用。

启动JavaFX 2.0图表演示示例的代码

/*** Start JavaFX application.* * @param stage First stage of JavaFX application.* @throws Exception */@Overridepublic void start(final Stage stage) throws Exception{final Parameters parameters = getParameters();  // command-line argsfinal List<String> args = parameters.getUnnamed();final String firstArgument = !args.isEmpty() ? args.get(0) : "1";final int chartWidth = !firstArgument.equals("4") ? CHART_WIDTH : MOVIE_CHART_WIDTH;stage.setTitle("Building Bar Charts");final Group rootGroup = new Group();final Scene scene = new Scene(rootGroup, chartWidth, CHART_HEIGHT, Color.WHITE);stage.setScene(scene);switch (firstArgument){case "1" :rootGroup.getChildren().add(buildVerticalLandAreaBarChart());break;case "2" :rootGroup.getChildren().add(buildVerticalPopulationBarChart());break;case "3" :rootGroup.getChildren().add(buildHorizontalPopulationBarChart());break;case "4" :rootGroup.getChildren().add(buildVerticalMovieRatingsBarChart());break;case "5" :rootGroup.getChildren().add(buildStatesLandSizePopulationScatterChart());break;default :rootGroup.getChildren().add(buildVerticalLandAreaBarChart());}stage.show();}/*** Main function for demonstrating JavaFX 2.0 bar chart and scatter chart.* * @param arguments Command-line arguments: none expected.*/public static void main(final String[] arguments){Application.launch(arguments);}

通过配置了用于填充图表的数据并演示了基本的JavaFX应用程序引导,现在该开始研究实际JavaFX 2.0图表API的使用了。 如上面的代码所示,第一个选项(“ 1”)导致生成垂直条形图,该条形图以公里为单位描述了样本州的相对土地面积。 接下来显示该示例执行的方法。

生成州土地面积的垂直条形图

/*** Build ObservableList of XYChart.Series instances mapping state names to* land areas.* * @return ObservableList of XYChart.Series instances mapping state names to*    land areas.*/public ObservableList<XYChart.Series<String,Long>> buildStatesToLandArea(){final ObservableList<XYChart.Data<String,Long>> statesToLandArea =FXCollections.observableArrayList();for (final State state : State.values()){final XYChart.Data<String,Long> stateAreaData =new XYChart.Data<String,Long>(state.stateName, statesLandSizeKm.get(state.stateName));statesToLandArea.add(stateAreaData);}final XYChart.Series<String, Long> landSeries =new XYChart.Series<String, Long>(statesToLandArea);final ObservableList<XYChart.Series<String, Long>> series =FXCollections.observableArrayList();landSeries.setName("State Land Size (km)");series.add(landSeries);return series;}/*** Provides a CategoryAxis instantiated with sample states' names.** @return CategoryAxis with sample states' names.*/public CategoryAxis buildStatesNamesCategoriesAxis(){final ObservableList<String> stateNames = FXCollections.observableArrayList();stateNames.addAll(State.ALASKA.stateName,State.CALIFORNIA.stateName,State.COLORADO.stateName,State.NEW_YORK.stateName,State.RHODE_ISLAND.stateName,State.TEXAS.stateName,State.WYOMING.stateName);final CategoryAxis categoryAxis = new CategoryAxis(stateNames);categoryAxis.setLabel("State");categoryAxis.setMinWidth(CHART_WIDTH);return categoryAxis;}/*** Build vertical bar chart comparing land areas of sample states.* * @return Vertical bar chart comparing land areas of sample states.*/public XYChart buildVerticalLandAreaBarChart(){final ValueAxis landAreaAxis = new NumberAxis(0, LAND_AREA_KM_MAXIMUM, 50_000);final BarChart landAreaBarChart =new BarChart(buildStatesNamesCategoriesAxis(), landAreaAxis, buildStatesToLandArea());landAreaBarChart.setMinWidth(CHART_WIDTH);landAreaBarChart.setMinHeight(CHART_HEIGHT);landAreaBarChart.setTitle("Land Area (in km) of Select U.S. States");return landAreaBarChart;}

上面的代码片段显示了我用于生成条形图的三种方法。 在底部的方法,buildVerticalLandAreaBarChart(),实例化NumberAxis图表的y轴,并使用该实施ValueAxis在实例化一个条形图BarChart实例化调用代码片段中的其他两个方法来创建带有状态名称的x轴,并准备ObservableList <XYChart.Series <String,Long >>格式的数据以用于图表生成。 生成的图表如下所示。

相似的代码可以生成用于描述样本状态总体的相似图表。 接下来显示执行此操作的代码,然后是生成的图表的屏幕快照。

使用州人口生成垂直条形图

// method buildStatesNamesCategoriesAxis() was shown in previous code listing/*** Build one or more series of XYChart Data representing state names as 'x'* portion and state populations as 'y' portion. This method is likely to be* used in vertical presentations where state names are desired on the x-axis* and population numbers are desired on the y-axis.* * @return Series of XYChar Data representing state names as 'x' portion and*    state populations as 'y' portion.*/public ObservableList<XYChart.Series<String,Long>> buildStatesToPopulation(){final ObservableList<XYChart.Data<String,Long>> statesToPopulation =FXCollections.observableArrayList();for (final State state : State.values()){final XYChart.Data<String,Long> statePopulationData =new XYChart.Data<String,Long>(state.stateName, statesPopulation.get(state.stateName));statesToPopulation.add(statePopulationData);}final XYChart.Series<String, Long> populationSeries =new XYChart.Series<String, Long>(statesToPopulation);final ObservableList<XYChart.Series<String, Long>> series =FXCollections.observableArrayList();populationSeries.setName("State Population");series.add(populationSeries);return series;}/*** Build vertical bar chart comparing populations of sample states.** @return Vertical bar chart comparing populations of sample states.*/public XYChart buildVerticalPopulationBarChart(){final ValueAxis populationAxis = new NumberAxis(0, POPULATION_RANGE_MAXIMUM, 2_000_000);final BarChart populationBarChart =new BarChart(buildStatesNamesCategoriesAxis(), populationAxis, buildStatesToPopulation());populationBarChart.setMinWidth(CHART_WIDTH);populationBarChart.setMinHeight(CHART_HEIGHT);populationBarChart.setTitle("Population of Select U.S. States");return populationBarChart;}

前两个图是垂直图。 下一个示例对其样本数据使用与上一个示例相同的状态填充,但是使用水平条形图而不是垂直图进行描述。 请注意,使用与前两个示例相同的方法来生成带有状态名称的轴,但是其结果作为第二个参数传递给BarChart构造函数,而不是第一个参数。 BarChart构造函数的顺序更改将图表从垂直更改为水平。 换句话说,在BarChart构造函数中,将CategoryAxis作为第一个参数,将ValueAxis作为第二个参数将导致一个垂直图表。 切换这两种类型的Axis的顺序会产生一个水平图。 我还必须切换要绘制的数据的映射顺序,以便关键部分是填充,而值部分是状态名称。 该代码后跟输出。

用州人口生成水平条形图

// method buildStatesNamesCategoriesAxis() was shown in previous code listings/*** Build one or more series of XYChart Data representing population as 'x'* portion and state names as 'y' portion. This method is likely to be used* in horizontal presentations where state names are desired on the y-axis* and population numbers are desired on the x-axis.* * @return Series of XYChar Data representing population as 'x' portion and*    state names as 'y' portion.*/public ObservableList<XYChart.Series<Long,String>> buildPopulationToStates(){final ObservableList<XYChart.Data<Long,String>> statesToPopulation =FXCollections.observableArrayList();for (final State state : State.values()){final XYChart.Data<Long,String> statePopulationData =new XYChart.Data<Long,String>(statesPopulation.get(state.stateName), state.stateName);statesToPopulation.add(statePopulationData);}final XYChart.Series<Long, String> populationSeries =new XYChart.Series<Long, String>(statesToPopulation);final ObservableList<XYChart.Series<Long, String>> series =FXCollections.observableArrayList();populationSeries.setName("State Population");series.add(populationSeries);return series;}/*** Build horizontal bar chart comparing populations of sample states.* * @return Horizontal bar chart comparing populations of sample states.*/public XYChart buildHorizontalPopulationBarChart(){final ValueAxis populationAxis = new NumberAxis(0, POPULATION_RANGE_MAXIMUM, 2_000_000);final BarChart populationBarChart =new BarChart(populationAxis, buildStatesNamesCategoriesAxis(), buildPopulationToStates());populationBarChart.setMinWidth(CHART_WIDTH);populationBarChart.setTitle("Population of Select U.S. States");return populationBarChart;}

对于生成条形图的所有这些示例,我都使用了JavaFX的XYChart 。 事实证明ScatterChart也扩展了XYChart ,因此其用法与BarChart相似。 这种情况( ScatterChart )的最大区别是将存在两个面向值的轴。 换句话说,每个轴将基于值(x轴的土地面积和y轴的人口数)而不是使用x轴(垂直)或y轴(水平)的州名。 这些类型的图表通常用于直观地确定数据之间的相关程度。 接下来显示生成此代码的代码及其生成的输出。

生成州人口到州土地面积散布图

/*** Build mapping of land area to population for each state.* * @return Mapping of land area to population for each sample state.*/public ObservableList<XYChart.Series<Long,Long>> buildAreaToPopulation(){final ObservableList<XYChart.Data<Long,Long>> areaToPopulation =FXCollections.observableArrayList();for (final State state : State.values()){final XYChart.Data<Long,Long> areaPopulationData =new XYChart.Data<Long,Long>(statesLandSizeKm.get(state.stateName),statesPopulation.get(state.stateName));areaToPopulation.add(areaPopulationData);}final XYChart.Series<Long, Long> areaPopulationSeries =new XYChart.Series<Long, Long>(areaToPopulation);final ObservableList<XYChart.Series<Long, Long>> series =FXCollections.observableArrayList();areaPopulationSeries.setName("State Land Area and Population");series.add(areaPopulationSeries);return series;}/*** Build a Scatter Chart depicting correlation between land area and population* for each state.* * @return Scatter Chart depicting correlation between land area and population*    for each state.*/public XYChart buildStatesLandSizePopulationScatterChart(){final ValueAxis xAxis = new NumberAxis(0, LAND_AREA_KM_MAXIMUM, 50_000);xAxis.setLabel("Land Area (km)");final ValueAxis yAxis = new NumberAxis(0, POPULATION_RANGE_MAXIMUM, 2_000_000);yAxis.setLabel("Population");final ScatterChart xyChart = new ScatterChart(xAxis, yAxis, buildAreaToPopulation());xyChart.setMinHeight(CHART_HEIGHT);return xyChart;}

散点图有助于直观地确定一个州的土地面积与其人口之间是否存在任何关联。 部分是因为阿拉斯加和怀俄明州被包括在样本状态集中,所以没有太多的相关性。 设置JavaFX散点图样式还有很多工作要做。

有时在同一条形图上看到多个序列是很有用的。 为了说明同一条形图中的多个系列,我将更改所使用的相同数据。 我将不使用状态及其大小和总体的数据,而是使用原始代码清单中与电影等级相关的数据。 特别是这里有三个系列:评论家的评分,“正常”听众的评分和我自己的评分。 与前面的示例一样,我首先显示代码(最有趣的部分是buildRatingsToMovieTitle()方法 ,然后是输出。

生成具有多个系列的电影分级条形图(多个分级组)

/*** Build one or more series of XYChart Data representing movie names as 'x'* portion and movie ratings as 'y' portion. This method is likely to be* used in vertical presentations where movie names are desired on the x-axis* and movie ratings are desired on the y-axis. This method illustrates* multiple series as ratings for both normal audience members and critics* are shown.* * @return Series of XYChar Data representing state movie names as 'x' portion*    and movie ratings as 'y' portion.*/public ObservableList<XYChart.Series<String,Double>> buildRatingsToMovieTitle(){final ObservableList<XYChart.Data<String,Double>> normalRatings =FXCollections.observableArrayList();final ObservableList<XYChart.Data<String,Double>> criticRatings =FXCollections.observableArrayList();final ObservableList<XYChart.Data<String,Double>> dustinRatings =FXCollections.observableArrayList();for (final Movie movie : Movie.values()){final XYChart.Data<String,Double> normalRatingsData =new XYChart.Data<String,Double>(movie.movieName, movieRatingsNormal.get(movie.movieName));normalRatings.add(normalRatingsData);final XYChart.Data<String,Double> criticRatingsData =new XYChart.Data<String,Double>(movie.movieName, movieRatingsCritics.get(movie.movieName));criticRatings.add(criticRatingsData);final XYChart.Data<String,Double> dustinRatingsData =new XYChart.Data<String,Double>(movie.movieName, movieRatingsDustin.get(movie.movieName));dustinRatings.add(dustinRatingsData);}final XYChart.Series<String, Double> normalSeries =new XYChart.Series<String, Double>(normalRatings);normalSeries.setName("Normal Audience");final XYChart.Series<String, Double> criticSeries =new XYChart.Series<String, Double>(criticRatings);criticSeries.setName("Critics");final XYChart.Series<String, Double> dustinSeries =new XYChart.Series<String, Double>(dustinRatings);dustinSeries.setName("Dustin");final ObservableList<XYChart.Series<String, Double>> series =FXCollections.observableArrayList();series.add(normalSeries);series.add(criticSeries);series.add(dustinSeries);return series;} /*** Build vertical bar chart comparing movie ratings to demonstrate multiple* series used in a single chart.* * @return Vertical bar chart comparing movie ratings.*/public XYChart buildVerticalMovieRatingsBarChart(){final ValueAxis ratingAxis = new NumberAxis(0, MOVIE_RATING_MAXIMUM, 1.0);final BarChart ratingBarChart =new BarChart(buildMovieRatingsAxis(), ratingAxis, buildRatingsToMovieTitle());ratingBarChart.setMinWidth(MOVIE_CHART_WIDTH);ratingBarChart.setMinHeight(CHART_HEIGHT);ratingBarChart.setTitle("Movie Ratings");return ratingBarChart;}

JavaFX 2.1 beta版包含几个新图表,包括StackedBarChart 。 堆叠的条形图表示多个序列,因此我将调整最后一个示例以使用其中的一个。 堆叠的条形图将显示三个评级源中的每一个,每个电影贡献一个条形,而不像上一个示例那样,每个电影三个条形。

生成电影分级的StackedBarChart

/*** Build one or more series of XYChart Data representing movie names as 'x'* portion and movie ratings as 'y' portion. This method is likely to be* used in vertical presentations where movie names are desired on the x-axis* and movie ratings are desired on the y-axis. This method illustrates* multiple series as ratings for both normal audience members and critics* are shown.* * @return Series of XYChar Data representing state movie names as 'x' portion*    and movie ratings as 'y' portion.*/public ObservableList<XYChart.Series<String,Double>> buildRatingsToMovieTitle(){final ObservableList<XYChart.Data<String,Double>> normalRatings =FXCollections.observableArrayList();final ObservableList<XYChart.Data<String,Double>> criticRatings =FXCollections.observableArrayList();final ObservableList<XYChart.Data<String,Double>> dustinRatings =FXCollections.observableArrayList();for (final Movie movie : Movie.values()){final XYChart.Data<String,Double> normalRatingsData =new XYChart.Data<String,Double>(movie.movieName, movieRatingsNormal.get(movie.movieName));normalRatings.add(normalRatingsData);final XYChart.Data<String,Double> criticRatingsData =new XYChart.Data<String,Double>(movie.movieName, movieRatingsCritics.get(movie.movieName));criticRatings.add(criticRatingsData);final XYChart.Data<String,Double> dustinRatingsData =new XYChart.Data<String,Double>(movie.movieName, movieRatingsDustin.get(movie.movieName));dustinRatings.add(dustinRatingsData);}final XYChart.Series<String, Double> normalSeries =new XYChart.Series<String, Double>(normalRatings);normalSeries.setName("Normal Audience");final XYChart.Series<String, Double> criticSeries =new XYChart.Series<String, Double>(criticRatings);criticSeries.setName("Critics");final XYChart.Series<String, Double> dustinSeries =new XYChart.Series<String, Double>(dustinRatings);dustinSeries.setName("Dustin");final ObservableList<XYChart.Series<String, Double>> series =FXCollections.observableArrayList();series.add(normalSeries);series.add(criticSeries);series.add(dustinSeries);return series;} /*** Build a Stacked Bar Chart depicting total ratings of each movie based on* contributions of three ratings groups.* * @return Stacked Bar Chart depicting three rating groups' contributions*    to overall movie rating.*/public XYChart buildStackedMovieRatingsBarChart(){final ValueAxis ratingAxis = new NumberAxis(0, MOVIE_RATING_MAXIMUM*3, 2.5);final StackedBarChart ratingBarChart =new StackedBarChart(buildMovieRatingsAxis(), ratingAxis, buildRatingsToMovieTitle());ratingBarChart.setMinWidth(MOVIE_CHART_WIDTH);ratingBarChart.setMinHeight(CHART_HEIGHT);ratingBarChart.setTitle("Movie Ratings");return ratingBarChart;}

堆叠的条形图很有用,因为它可以快速查看每部电影的总体综合评分以及每个评论者组对该总评分的贡献。

JavaFX 2.0图表文档
“ 使用JavaFX图表”教程涵盖各种JavaFX 2.0图表类型(例如饼图 , 折线图 , 面积图 , 气泡图 , 散点图和条形图)的代码示例和相应的生成的图表图像。 本教程还提供了有关使用CSS设置图表样式的部分,以及有关准备图表数据和生成自定义图表的信息。

结论
这篇文章演示了如何使用JavaFX图表包生成条形图,散点图和堆积条形图。 当JavaFX被接受为Java SE SDK的标准部分时,它将为SDK带来用于生成Java图表的标准机制。

参考:来自JCG合作伙伴的 JavaFX 2.0条形图和散点图(以及JavaFX 2.1 StackedBarCharts)   实际事件启发博客中的达斯汀·马克思。


翻译自: https://www.javacodegeeks.com/2012/02/javafx-20-bar-and-scatter-charts-and.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/373593.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python中下划线开头的命名_Python 中各种下划线的骚操作:_、_xx、xx_、__xx、__xx__、_classname_...

我们在定义一些变量或者方法的时候&#xff0c;常常会用到下划线&#xff0c;在 Python 中&#xff0c;下划线可是很有用处的哟&#xff0c;比如变量&#xff0c;有些是一个下划线开头的(_xx)&#xff0c;有些是两个下划线开头的(__xx)&#xff0c;有些是在名称的结尾添加下划线…

MongoDB学习2——Windows 使用mongo连接数据库

一、查看mongo帮助文档mongo.exe --help二、使用mongo 连接服务器mongo.exe 数据库地址&#xff1a;数据库端口号/数据库关闭服务器db.shutdownServer()注&#xff1a;关闭数据必须使用admin数据库权限

【UVA 10816】 Travel in Desert (最小瓶颈树+最短路)

【题意】 有n个绿洲&#xff0c; m条道路&#xff0c;每条路上有一个温度&#xff0c;和一个路程长度&#xff0c;从绿洲s到绿洲t&#xff0c;求一条道路的最高温度尽量小&#xff0c; 如果有多条&#xff0c; 选一条总路程最短的。 InputInput consists of several test cases…

[OJ] Data Stream Median (Hard)

LintCode 81. Data Stream Median (Hard) 思路: 用一个大根堆保存较小的一半数, 一个小根堆保存较大的一半数.每次根据num和两个堆顶的数据决定往哪个堆里面放.放完后进行平衡确保两个堆的size差不超过1.利用两个堆的size和堆顶值计算median.大根堆可以表示为priority_queue<…

书评:JBoss AS 7:配置,部署和管理

我热切地接受Packt Publishing邀请复审JBoss AS 7&#xff1a;配置&#xff0c;部署和管理&#xff0c;因为自从我上次使用JBoss已有数年了&#xff0c;我很想了解有关JBoss AS 7的更多信息。 我已经写过关于《 JBoss AS 7配置&#xff0c;部署和管理》一书的第一印象&#xff…

联想小新air14笔记本黑屏_联想小新air14锐龙版测评,谈谈它的好和坏

联想小新air14锐龙版本测评了解数码就找小侠客&#xff0c;我是机圈小侠客 今天呢&#xff0c;主要和大家测评一下联想小新air14这款笔记本&#xff0c;总体而言的话&#xff0c;这款笔记本它是一个。对于办公人士或者轻度游戏爱好者来说的话&#xff0c;是一个不错的选择&…

MongoDB学习3——mongoDB的一些基本使用

#查看所有数据库show dbs;#创建&#xff08;切换&#xff09;数据库use DATABASE_NAME注&#xff1a;如果数据库不存在&#xff0c;则创建数据库&#xff0c;否则切换到指定数据库。#插入文档&#xff08;关系型数据说法叫插入数据&#xff09;方式一&#xff1a;db.COLLECTION…

Java入门:Java下载与安装方法

本文适合刚入门的Java编程的初学者阅读。 JDK有两种下载方法&#xff0c;一个是官网下载&#xff0c;另一个是第三方网站下载。官网速度也许有点慢&#xff0c;慢的话可以考虑去第三方网站下载。 一、官网下载 1. 访问地址&#xff1a;http://www.oracle.com/cn/downloads/inde…

jquery获得下拉框的值

获取Select &#xff1a; 获取select 选中的 text : $("#ddlRegType").find("option:selected").text(); 获取select选中的 value: $("#ddlRegType ").val(); 获取select选中的索引: $("#ddlRegType ").get(0).selectedIndex; 设置sel…

Java 7:如何编写非常快速的Java代码

当我第一次写此博客时&#xff0c;我的目的是向您介绍ThreadLocalRandom类&#xff0c;它是Java 7中新增的用于生成随机数的类。 我已在一系列微基准测试中分析了ThreadLocalRandom的性能&#xff0c;以了解其在单线程环境中的性能。 结果相对令人惊讶&#xff1a;尽管代码非常…

python 微信支付接口 详解_Python支付接口汇总大全(包含微信、支付宝等,长期更新、欢迎补充)...

wzhifuSDK- 由微信支付SDK 官方PHP Demo移植而来&#xff0c;v3.37下载地址学习Python中有不明白推荐加入交流群号&#xff1a;864573496群里有志同道合的小伙伴&#xff0c;互帮互助&#xff0c;群里有不错的视频学习教程和PDF&#xff01;weixin_pay- 是一个简单的微信支付的…

[地图开发][算法及数据结构]四叉树原理

参考&#xff1a;http://blog.csdn.net/zhouxuguang236/article/details/12312099 原博客地址还有c&#xff0b;&#xff0b;源码。。。 四叉树索引的基本思想是将地理空间递归划分为不同层次的树结构。它将已知范围的空间等分成四个相等的子空间&#xff0c;如此递归下去&…

mongoDB中的数据类型

Date mongo shell中提供各式各样的返回日期类型的方法&#xff0c;例如字符串类型或者Date对象类型&#xff1a; Date()返回当前的日期字符串&#xff1b;new Date()返回使用ISODate()包装的Date对象类型&#xff1b;ISODate()返回使用ISODate()包装的Date对象类型&#xff1b;…

C++ namespace

是否应该使用using(using namespace std) 注&#xff1a;我将namespace翻译成姓或士族。选择某个namespace中的变量、函数、组合类型&#xff0c;就像是在介绍某个人 姓 namespace, 名 variable。 参考&#xff1a; 1、Why is “using namespace std” considered bad practice…

按键 粘贴上一个命令_合并单元格、选择性粘贴的快捷键都是啥?今天一次告诉你……...

经常有人在群里问&#xff0c;合并单元格的快捷键是什么&#xff1f;选择性粘贴数值的快捷键是什么&#xff1f;今天就来聊聊快捷键的一些冷门知识……Alt键的作用快捷键其实就是一些组合键&#xff0c;主要用到Ctrl、shift、Alt这三个键其中之一或者是几个&#xff0c;再加上其…

Spring MVC和JQuery用于Ajax表单验证

在本教程中&#xff0c;我们将看到如何使用Ajax和Spring MVC和JQuery在服务器端验证表单。 Spring MVC为通过注释驱动的配置采用Ajax提供了非常方便的过程。 我们将使用此注释驱动的配置以JSON数据的形式发送Ajax响应。 响应将包含表单验证的状态&#xff0c;并且表单数据中存在…

myeclipse10.7破解成功 但 无法打war包 提示:securecrt alert:integrity ch

myeclipse10.7破解成功 但 无法打war包 提示&#xff1a;securecrt alert:integritycheck error找了好久才找到解决办法http://download.csdn.net/detail/yi303526230/6889101#comment本次对于myeclipse10破解后&#xff0c;导出war包时报“SECURITY ALERT: INTEGERITY CHECK E…

Mongodb的update操作

在前面的文章“mongodb 查询的语法”里&#xff0c;我介绍了Mongodb的常用查询语法&#xff0c;Mongodb的update操作也有点复杂&#xff0c;我结合自己的使用经验&#xff0c;在这里介绍一下&#xff0c;给用mongodb的朋友看看&#xff0c;也方便以后自己用到的时候查阅&#x…

封装方法

<?php class DBDA {public $host"localhost";public $uid"root";public $pwd"123";public $dbname"mydb";/***给一个sql语句&#xff0c;返回执行的结果*param string $sql 用户指定的sql语句*param int $type 用户给的语句类型&a…

AFNetwork 作用和使用方法具体解释

转自&#xff1a;http://www.maxiaoguo.com/clothes/269.html AFNetworking是一个轻量级的iOS网络通信类库。它建立在NSURLConnection和NSOperation等类库的基础上&#xff0c;让非常多网络通信功能的实现变得十分简单。它支持HTTP请求和基于REST的网络服务&#xff08;包含GET…