首页 文章

Javafx:如何在css中更改.chart-legend-item-symbol的大小?

提问于
浏览
1

我对Javafx比较新,对CSS也是全新的 . 现在我想将我在Javafx中创建的图表导出到png文件中,因为我希望有一个高质量的图片,我改变了我的CSS表格的一些设置,以便像字体大小这样的东西现在更大 .

我设法改变了几乎所有的参数,但我还有一个问题:我发现无法改变图表图例符号的大小 . Oracle提供了一个JavaFX参考指南,我发现我应该能够更改样式类.chart-legend-item-symbol中的设置 . (https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html

我还找到了一个来自Oracle(http://docs.oracle.com/javafx/2/charts/css-styles.htm)的教程,他们说:"By default, legend symbols look like circles, because they are declared as rounded rectangles with a 5-pixel height, 5-pixel width, and 5-pixel radius."

所以我的问题是:是否有一个参数可以用来改变矩形的5px大小?或者我需要在这里完全重新定义另一个尺寸的矩形,如果是这样 - 我该怎么做?

我觉得有点愚蠢,因为直到现在我还没完全理解CSS的语法,但是我没有通过询问google找到解决该问题的方法 .

非常感谢您的帮助!

2 回答

  • 0

    请在这里看一下jewelsea的答案:Controlling symbols, etc. in lineCharts inline programmatically .

    您可以访问任何图例符号:

    .default-color0.chart-legend-item-symbol{}
    .default-color1.chart-legend-item-symbol{}
    .default-color2.chart-legend-item-symbol{}
    

    也许有更好的方法来实现这一点,但您可以将自定义背景图像设置为legend-item-symbol并更改其大小:

    .default-color0.chart-legend-item-symbol {
        -fx-background-color: transparent;
        -fx-background-size: 5px;
        -fx-background-image: url('../Icons/rectangle.png');
        -fx-background-repeat: no-repeat;
        -fx-background-position: center; 
    }
    

    或者在这里使用此方法(饼图的自定义图例符号):https://gist.github.com/jewelsea/1422628

  • -1
    // For Line chart you can use
    
    .default-color0.chart-line-symbol {
        -fx-background-radius: 0;
    }
    

    或者您只需将 -line- 替换为 -area- 即可更改为面积图

相关问题