当前位置: 首页 > news >正文

电子商务网站开发费用调研报告公司免费网站搭建

电子商务网站开发费用调研报告,公司免费网站搭建,简单的购物网站设计,网站建设 中企动力南昌在现代应用程序开发中,数据可视化是一个关键部分。本文将介绍如何使用 Java Swing 和 XChart 库创建各种类型的图表。XChart 是一个轻量级的图表库,支持多种类型的图表,非常适合在 Java 应用中进行快速的图表绘制。 1、环境配置 在开始之前&…

在现代应用程序开发中,数据可视化是一个关键部分。本文将介绍如何使用 Java Swing 和 XChart 库创建各种类型的图表。XChart 是一个轻量级的图表库,支持多种类型的图表,非常适合在 Java 应用中进行快速的图表绘制。

1、环境配置

在开始之前,我们需要确保项目中包含了 XChart 的依赖。以下是在 Maven 项目中的 pom.xml 文件中添加 XChart 依赖的方法:

<dependency><groupId>org.knowm.xchart</groupId><artifactId>xchart</artifactId><version>3.8.0</version>
</dependency>

2、创建不同类型的图表

以下是如何使用 XChart 创建不同类型的图表的示例代码。

面积图


public class AreaChartExample extends JFrame {public AreaChartExample() {// 创建图表XYChart chart = new XYChartBuilder().width(800).height(600).title("Area Chart Example").xAxisTitle("X").yAxisTitle("Y").build();// 添加数据double[] xData = new double[] {0.0, 1.0, 2.0, 3.0, 4.0};double[] yData = new double[] {2.0, 1.0, 0.0, 1.0, 2.0};chart.addSeries("y(x)", xData, yData).setMarker(SeriesMarkers.NONE).setFillColor(new Color(0, 0, 255, 50));// 将图表面板添加到 JFrameJPanel chartPanel = new XChartPanel<>(chart);getContentPane().add(chartPanel, BorderLayout.CENTER);}public static void main(String[] args) {SwingUtilities.invokeLater(() -> {AreaChartExample example = new AreaChartExample();example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);example.pack();example.setVisible(true);});}
}

柱状图

public class BarChartExample extends JFrame {public BarChartExample() {// 创建图表CategoryChart chart = new CategoryChartBuilder().width(800).height(600).title("Bar Chart Example").xAxisTitle("Category").yAxisTitle("Value").build();// 添加数据List<String> categories = Arrays.asList("A", "B", "C");List<Number> series1Values = Arrays.asList(4, 5, 9);List<Number> series2Values = Arrays.asList(3, 8, 5);chart.addSeries("Series 1", categories, series1Values);chart.addSeries("Series 2", categories, series2Values);// 将图表面板添加到 JFrameJPanel chartPanel = new XChartPanel<>(chart);getContentPane().add(chartPanel, BorderLayout.CENTER);}public static void main(String[] args) {SwingUtilities.invokeLater(() -> {BarChartExample example = new BarChartExample();example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);example.pack();example.setVisible(true);});}
}

气泡图

public BubbleChartExample() {// 创建图表XYChart chart = new XYChartBuilder().width(800).height(600).title("Bubble Chart Example").xAxisTitle("X").yAxisTitle("Y").build();// 添加数据double[] xData = new double[] {0.1, 0.4, 1.0, 1.5, 2.2, 3.0};double[] yData = new double[] {2.0, 1.5, 0.9, 1.4, 1.9, 2.2};double[] bubbleSize = new double[] {0.1, 0.2, 0.3, 0.4, 0.5, 0.6};chart.addSeries("y(x)", xData, yData, bubbleSize).setMarker(SeriesMarkers.CIRCLE);// 将图表面板添加到 JFrameJPanel chartPanel = new XChartPanel<>(chart);getContentPane().add(chartPanel, BorderLayout.CENTER);}public static void main(String[] args) {SwingUtilities.invokeLater(() -> {BubbleChartExample example = new BubbleChartExample();example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);example.pack();example.setVisible(true);});}

折线图

public class LineChartExample extends JFrame {public LineChartExample() {// 创建图表XYChart chart = new XYChartBuilder().width(800).height(600).title("Line Chart Example").xAxisTitle("X").yAxisTitle("Y").build();// 自定义图表样式chart.getStyler().setLegendPosition(Styler.LegendPosition.InsideNE);chart.getStyler().setMarkerSize(16);// 添加数据double[] xData = new double[] {0.0, 1.0, 2.0, 3.0, 4.0};double[] yData = new double[] {2.0, 1.0, 0.0, 1.0, 2.0};chart.addSeries("y(x)", xData, yData);// 将图表面板添加到 JFrameJPanel chartPanel = new XChartPanel<>(chart);getContentPane().add(chartPanel, BorderLayout.CENTER);}public static void main(String[] args) {SwingUtilities.invokeLater(() -> {LineChartExample example = new LineChartExample();example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);example.pack();example.setVisible(true);});}
}

饼图

public class PieChartExample extends JFrame {public PieChartExample() {// 创建图表PieChart chart = new PieChartBuilder().width(800).height(600).title("Pie Chart Example").build();// 添加数据chart.addSeries("Category A", 40);chart.addSeries("Category B", 30);chart.addSeries("Category C", 20);chart.addSeries("Category D", 10);// 将图表面板添加到 JFrameJPanel chartPanel = new XChartPanel<>(chart);getContentPane().add(chartPanel, BorderLayout.CENTER);}public static void main(String[] args) {SwingUtilities.invokeLater(() -> {PieChartExample example = new PieChartExample();example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);example.pack();example.setVisible(true);});}
}

阶梯图

public class StepChartExample extends JFrame {public StepChartExample() {// 创建图表XYChart chart = new XYChartBuilder().width(800).height(600).title("Step Chart Example").xAxisTitle("X").yAxisTitle("Y").build();// 添加数据double[] xData = new double[] {0.0, 1.0, 2.0, 3.0, 4.0};double[] yData = new double[] {2.0, 1.0, 0.0, 1.0, 2.0};chart.addSeries("y(x)", xData, yData).setXYSeriesRenderStyle(XYSeries.XYSeriesRenderStyle.Step);// 将图表面板添加到 JFrameJPanel chartPanel = new XChartPanel<>(chart);getContentPane().add(chartPanel, BorderLayout.CENTER);}public static void main(String[] args) {SwingUtilities.invokeLater(() -> {StepChartExample example = new StepChartExample();example.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);example.pack();example.setVisible(true);});}
}

3、总结

通过本文的示例代码,您可以在 Java 应用程序中轻松创建多种类型的图表。XChart 提供了简单且强大的 API,能够满足大多数数据可视化需求。希望这些示例能帮助您更好地理解如何使用 XChart 进行数据可视化。

http://www.yayakq.cn/news/497739/

相关文章:

  • 企业建立自己网站主要方式seo数据是什么
  • 网站的结构布局shopnc
  • 网站改版 升级的目的是什么新科网站建设
  • 高埗镇网站仿做北京网站设计推荐刻
  • 网站建设模板软件系统做网站的地方
  • 邻水建设局网站药店网站源码
  • 网站制作基本流程成都专业网站建设套餐
  • 网站开发视频下载青岛快速排名优化
  • 免费下载ps素材网站学生管理系统wordpress
  • 海南网站搭建外包锦州滨海新区城市建设规划网站
  • 做百度推广和企业网站那个有效果吗网站建设沧州
  • 世界摄影网站二级建造师执业资格考试
  • 视频网站建设技术方案书天津建设工程信息网怎么投标
  • 天津网站建设有哪些小语种网站开发
  • 苏州吴江网站建设济南网站制做
  • 国内wordpress著名网站莱芜网逃人员
  • 微信后台怎么做微网站衡水医院网站建设
  • 优秀网站设计的标准山西网站备案
  • 韶关市建设局官方网站重庆如何快速制作一个网站
  • 学校网站开发协议网站开发融资
  • 怎样用linux做网站网页链接调用服务是干嘛的
  • 试用网站开发网站建设开始学什么
  • 重庆忠县网站建设公司哪里有wordpress 到顶插件
  • 专业制作网站建设亿网互联
  • 知行网站建设wordpress文章转发
  • 网站建设与开发的论文营销型网站框架图
  • 网站开发pc和手机端湖南做网站问磐石网络专业
  • 做网站的开发环境无锡产品排名优化
  • 网站设计项目明细机械网站案例
  • 招商网站建设地点西杰网站建设