在我的项目中,我在同一帧中使用 abarchart和 a来显示相同的数据。但是,由于某种原因,我得到的输出中或linechart中都没有颜色。barchartlinechart
例如:
在此图像中, 是linechart有颜色的,但 是barchart没有颜色的。
我使用的代码:
FXML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.chart.BarChart?>
<?import javafx.scene.chart.CategoryAxis?>
<?import javafx.scene.chart.LineChart?>
<?import javafx.scene.chart.NumberAxis?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane" prefHeight="401.0" prefWidth="802.0" style="-fx-background-color: white;" stylesheets="@stylesheet.css" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication26.FXMLDocumentController">
<children>
<AnchorPane layoutX="1.0" layoutY="14.0" prefHeight="303.0" prefWidth="801.0" AnchorPane.bottomAnchor="46.0" AnchorPane.leftAnchor="1.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="14.0">
<children>
<AnchorPane layoutX="342.0" layoutY="-2.0" prefHeight="244.0" prefWidth="419.0" style="-fx-border-color: #4E6172; -fx-background-color: white;" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="-2.0">
<children>
<LineChart fx:id="linechart" layoutX="69.0" layoutY="11.0" prefHeight="353.0" prefWidth="380.0">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis …Run Code Online (Sandbox Code Playgroud) 在我的程序中,我有这样的要求,我必须将浮点值传递回主函数。
第一种方法的代码是:
#include <stdio.h>
void main()
{
int a,b;
a=1;
b=2;
division(a,b);
}
int division(int a, int b)
{
float res;
res=((float) a)/b;
printf("%f",res);
}
Run Code Online (Sandbox Code Playgroud)
第二种方法的代码(我将浮点值传递回主函数)是这样的:
#include <stdio.h>
void main()
{
int a,b;
a=1;
b=2;
float res;
res=division(a,b);
printf("%f",res);
}
int division(int a, int b)
{
float res;
res=((float) a)/b;
return res;
}
Run Code Online (Sandbox Code Playgroud)
对于第一种方法,输出为0.5,正如预期的那样。但是,当我传递结果时float(如下一个程序所示),我得到的输出为0. 为什么会出现这种情况?有什么解决方法吗?我对 C 比较陌生(尝试了 Java 之外的东西),所以我不太熟悉它的规则。当我修改int division为包含printf变量的语句时res,例如
int division(int a, int b)
{
float res; …Run Code Online (Sandbox Code Playgroud)